Merge pull request #34 from ALEZ-DEV/main

Code example now compile
This commit is contained in:
Igor Katson 2023-11-15 20:32:05 +00:00 committed by GitHub
commit 0cd9981f62
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -8,20 +8,31 @@ This program will just download a simple torrent file with a Magnet link
```rust
use std::error::Error;
use std::path::PathBuf;
use librqbit::session::{AddTorrentResponse, Session};
use librqbit::spawn_utils::BlockingSpawner;
const MAGNET_LINK: &str = "magnet:?..."; // Put your magnet link here
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>>{
let session = Session::new("C:\\Anime", Default::default());
// Create the session
let session = Session::new("C:\\Anime".parse().unwrap(), BlockingSpawner::new(false)).await?;
// Add the torrent to the session
let handle = match session.add_torrent(MAGNET_LINK, None).await {
AddTorrentResponse::Added(handle) => {
handle
Ok(AddTorrentResponse::Added(handle)) => {
Ok(handle)
},
resp => unimplemented!("{:?}", resp)
};
Err(e) => {
eprintln!("Something goes wrong when downloading torrent : {:?}", e);
Err(())
}
_ => Err(())
}.expect("Failed to add torrent to the session");
// Wait until the download is completed
handle.wait_until_completed().await?;
Ok(())