Struct Download

Source
pub struct Download<'a> { /* private fields */ }
Expand description

Download url : 下载链接 out: 输出目录或输出文件路径 proxy: 使用代理,发现 reqwest 自动使用系统代理不好用 , 目前只支持 http 代理 如:http://127.0.0.1:7890 ,不支持 https,socks5代理(懒)

Implementations§

Source§

impl<'a> Download<'a>

Source

pub fn new( url: &'a str, out: Option<&'a str>, proxy: Option<&'a str>, ) -> Download<'a>

创建 Download对象 url: 需要下载的url out: 保存地址(具体文件夹或具体文件名) proxy: 使用代理,发现 reqwest 自动使用系统代理不好用 , 目前只支持 http 代理 如:http://127.0.0.1:7890 ,不支持 https,socks5代理(懒)

Examples found in repository?
examples/sync_download_example.rs (line 15)
7fn main() {
8    let url = "https://www.baidu.com/img/bd_logo1.png";
9    // 当前目录
10     let filename = "bd_log1.png";
11    // 指定 下载目录
12    // let filename = "/download/";
13    // 指定下载目录下载文件名,需要手动创建下载文件夹
14    // let filename = "download/bd_log1.png";
15    let download = Download::new(url,Some(filename),None);
16
17    match download.download() {
18        Ok(_) => println!("下载完成"),
19        Err(e) => println!("下载出错 : {}",e.to_string()),
20    }
21
22    // 删除图片
23    fs::remove_file(filename).unwrap();
24}
Source

pub fn download(&self) -> Result<(), Box<dyn Error>>

同步方法下载 没有下载进度条

§Examples
use download_rs::sync_download::Download;
use std::error::Error;

fn main() {
   let url = "https://www.baidu.com/img/bd_logo1.png";
   // 当前目录
    let filename = "bd_log1.png";
   // 指定 下载目录
   // let filename = "/download/";
   // 指定下载目录下载文件名,需要手动创建下载文件夹
   // let filename = "download/bd_log1.png";
   //let proxy = Some("http://127.0.0.1:7089");
   //let download = Download::new(url,Some(filename),proxy);
   let download = Download::new(url,Some(filename),None);
   match download.download() {
       Ok(_) => println!("下载完成"),
       Err(e) => println!("下载出错 : {}",e.to_string()),
   }
}
Examples found in repository?
examples/sync_download_example.rs (line 17)
7fn main() {
8    let url = "https://www.baidu.com/img/bd_logo1.png";
9    // 当前目录
10     let filename = "bd_log1.png";
11    // 指定 下载目录
12    // let filename = "/download/";
13    // 指定下载目录下载文件名,需要手动创建下载文件夹
14    // let filename = "download/bd_log1.png";
15    let download = Download::new(url,Some(filename),None);
16
17    match download.download() {
18        Ok(_) => println!("下载完成"),
19        Err(e) => println!("下载出错 : {}",e.to_string()),
20    }
21
22    // 删除图片
23    fs::remove_file(filename).unwrap();
24}

Auto Trait Implementations§

§

impl<'a> Freeze for Download<'a>

§

impl<'a> RefUnwindSafe for Download<'a>

§

impl<'a> Send for Download<'a>

§

impl<'a> Sync for Download<'a>

§

impl<'a> Unpin for Download<'a>

§

impl<'a> UnwindSafe for Download<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T