From 44868183fbf3dc3d72fcc2e1f128fd61a81666ba Mon Sep 17 00:00:00 2001 From: ALEZ Date: Wed, 15 Nov 2023 21:03:03 +0100 Subject: [PATCH 1/3] readme code example can now compile --- crates/librqbit/README.md | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/crates/librqbit/README.md b/crates/librqbit/README.md index 5eac475b..4c6be0fb 120000 --- a/crates/librqbit/README.md +++ b/crates/librqbit/README.md @@ -15,13 +15,22 @@ const MAGNET_LINK: &str = "magnet:?..."; // Put your magnet link here #[tokio::main] async fn main() -> Result<(), Box>{ - 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(()) From b0125f7c27dfe6713a6c182a56c908fbb5f53a42 Mon Sep 17 00:00:00 2001 From: ALEZ Date: Wed, 15 Nov 2023 21:12:31 +0100 Subject: [PATCH 2/3] add PathBuf to readme lib --- crates/librqbit/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/librqbit/README.md b/crates/librqbit/README.md index 4c6be0fb..c8a2037e 120000 --- a/crates/librqbit/README.md +++ b/crates/librqbit/README.md @@ -8,6 +8,7 @@ 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}; const MAGNET_LINK: &str = "magnet:?..."; // Put your magnet link here From e6ac4c71b6d68e27d0505da1dc3e2fe41d968bb3 Mon Sep 17 00:00:00 2001 From: ALEZ Date: Wed, 15 Nov 2023 21:14:03 +0100 Subject: [PATCH 3/3] edit BlockingSpawner to readme lib --- crates/librqbit/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/librqbit/README.md b/crates/librqbit/README.md index c8a2037e..7703388d 120000 --- a/crates/librqbit/README.md +++ b/crates/librqbit/README.md @@ -10,6 +10,7 @@ This program will just download a simple torrent file with a Magnet link 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