初始例程
安装
在你的Cargo.toml
中添加:
[dependencies]
vielpork = "0.1.0"
快速开始
use vielpork::downloader::Downloader;
use vielpork::reporters::tui::TuiReporter;
use vielpork::resolvers::url::UrlResolver;
use vielpork::base::structs::DownloadOptions;
use vielpork::base::enums::DownloadResource;
use vielpork::error::Result;
use std::sync::Arc;
use tokio::sync::Mutex;
#[tokio::main]
async fn main() -> Result<()> {
let options: DownloadOptions = DownloadOptions::default()
.with_save_path("fetch".to_string())
.with_concurrency(3);
let downloader = Downloader::new(options, Box::new(UrlResolver::new()), Box::new(TuiReporter::new()));
let resources = vec![
DownloadResource::Url("https://example.com".to_string()),
DownloadResource::Url("https://example.com".to_string()),
DownloadResource::Url("https://example.com".to_string()),
DownloadResource::Url("https://example.com".to_string()),
DownloadResource::Url("https://example.com".to_string()),
DownloadResource::Url("https://example.com".to_string()),
DownloadResource::Url("https://example.com".to_string()),
DownloadResource::Url("https://example.com".to_string()),
DownloadResource::Url("https://example.com".to_string()),
];
downloader.start(resources).await?;
loop {
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
// Because of the async nature of the downloader, we need to keep the main thread alive
}
Ok(())
}