librqbit
A torrent library 100% written in rust
Basic example
This is a simple program on how to use this library
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:?...";
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>>{
let session = Session::new("C:\\Anime".parse().unwrap(), BlockingSpawner::new(false)).await?;
let handle = match session.add_torrent(MAGNET_LINK, None).await {
Ok(AddTorrentResponse::Added(handle)) => {
Ok(handle)
},
Err(e) => {
eprintln!("Something goes wrong when downloading torrent : {:?}", e);
Err(())
}
_ => Err(())
}.expect("Failed to add torrent to the session");
handle.wait_until_completed().await?;
Ok(())
}