11//! Easy file downloading
22
3- #[ macro_use]
4- extern crate error_chain;
5- extern crate url;
6-
7- #[ cfg( feature = "reqwest-backend" ) ]
8- #[ macro_use]
9- extern crate lazy_static;
10- #[ cfg( feature = "reqwest-backend" ) ]
11- extern crate reqwest;
12-
133use std:: path:: Path ;
144use url:: Url ;
155
@@ -35,7 +25,7 @@ fn download_with_backend(
3525 backend : Backend ,
3626 url : & Url ,
3727 resume_from : u64 ,
38- callback : & Fn ( Event ) -> Result < ( ) > ,
28+ callback : & dyn Fn ( Event < ' _ > ) -> Result < ( ) > ,
3929) -> Result < ( ) > {
4030 match backend {
4131 Backend :: Curl => curl:: download ( url, resume_from, callback) ,
@@ -48,7 +38,7 @@ pub fn download_to_path_with_backend(
4838 url : & Url ,
4939 path : & Path ,
5040 resume_from_partial : bool ,
51- callback : Option < & Fn ( Event ) -> Result < ( ) > > ,
41+ callback : Option < & dyn Fn ( Event < ' _ > ) -> Result < ( ) > > ,
5242) -> Result < ( ) > {
5343 use std:: cell:: RefCell ;
5444 use std:: fs:: OpenOptions ;
@@ -133,7 +123,7 @@ pub fn download_to_path_with_backend(
133123#[ cfg( feature = "curl-backend" ) ]
134124pub mod curl {
135125
136- extern crate curl;
126+ use curl;
137127
138128 use self :: curl:: easy:: Easy ;
139129 use super :: Event ;
@@ -143,7 +133,11 @@ pub mod curl {
143133 use std:: time:: Duration ;
144134 use url:: Url ;
145135
146- pub fn download ( url : & Url , resume_from : u64 , callback : & Fn ( Event ) -> Result < ( ) > ) -> Result < ( ) > {
136+ pub fn download (
137+ url : & Url ,
138+ resume_from : u64 ,
139+ callback : & dyn Fn ( Event < ' _ > ) -> Result < ( ) > ,
140+ ) -> Result < ( ) > {
147141 // Fetch either a cached libcurl handle (which will preserve open
148142 // connections) or create a new one if it isn't listed.
149143 //
@@ -239,7 +233,7 @@ pub mod curl {
239233 . response_code ( )
240234 . chain_err ( || "failed to get response code" ) ?;
241235 match code {
242- 0 | 200 ... 299 => { }
236+ 0 | 200 ..= 299 => { }
243237 _ => {
244238 return Err ( ErrorKind :: HttpStatus ( code) . into ( ) ) ;
245239 }
@@ -252,16 +246,19 @@ pub mod curl {
252246
253247#[ cfg( feature = "reqwest-backend" ) ]
254248pub mod reqwest_be {
255- extern crate env_proxy;
256-
257249 use super :: Event ;
258250 use crate :: errors:: * ;
251+ use lazy_static:: lazy_static;
259252 use reqwest:: { header, Client , Proxy , Response } ;
260253 use std:: io;
261254 use std:: time:: Duration ;
262255 use url:: Url ;
263256
264- pub fn download ( url : & Url , resume_from : u64 , callback : & Fn ( Event ) -> Result < ( ) > ) -> Result < ( ) > {
257+ pub fn download (
258+ url : & Url ,
259+ resume_from : u64 ,
260+ callback : & dyn Fn ( Event < ' _ > ) -> Result < ( ) > ,
261+ ) -> Result < ( ) > {
265262 // Short-circuit reqwest for the "file:" URL scheme
266263 if download_from_file_url ( url, resume_from, callback) ? {
267264 return Ok ( ( ) ) ;
@@ -316,7 +313,7 @@ pub mod reqwest_be {
316313 }
317314
318315 fn env_proxy ( url : & Url ) -> Option < Url > {
319- env_proxy:: for_url ( url) . to_url ( )
316+ :: env_proxy:: for_url ( url) . to_url ( )
320317 }
321318
322319 fn request ( url : & Url , resume_from : u64 ) -> :: reqwest:: Result < Response > {
@@ -332,7 +329,7 @@ pub mod reqwest_be {
332329 fn download_from_file_url (
333330 url : & Url ,
334331 resume_from : u64 ,
335- callback : & Fn ( Event ) -> Result < ( ) > ,
332+ callback : & dyn Fn ( Event < ' _ > ) -> Result < ( ) > ,
336333 ) -> Result < bool > {
337334 use std:: fs;
338335 use std:: io;
0 commit comments