1
1
//! Easy file downloading
2
2
#![ deny( rust_2018_idioms) ]
3
3
4
+ use std:: fs:: remove_file;
4
5
use std:: path:: Path ;
5
6
6
7
use anyhow:: Context ;
7
8
pub use anyhow:: Result ;
8
- use std :: fs :: remove_file ;
9
+ use thiserror :: Error ;
9
10
use url:: Url ;
10
11
11
- mod errors;
12
- pub use crate :: errors:: * ;
13
-
14
12
/// User agent header value for HTTP request.
15
13
/// See: https://github.com/rust-lang/rustup/issues/2860.
16
14
#[ cfg( feature = "curl-backend" ) ]
@@ -185,8 +183,7 @@ pub mod curl {
185
183
use curl:: easy:: Easy ;
186
184
use url:: Url ;
187
185
188
- use super :: Event ;
189
- use crate :: errors:: * ;
186
+ use super :: { DownloadError , Event } ;
190
187
191
188
pub fn download (
192
189
url : & Url ,
@@ -306,9 +303,7 @@ pub mod reqwest_be {
306
303
use tokio_stream:: StreamExt ;
307
304
use url:: Url ;
308
305
309
- use super :: Event ;
310
- use super :: TlsBackend ;
311
- use crate :: errors:: * ;
306
+ use super :: { DownloadError , Event , TlsBackend } ;
312
307
313
308
pub async fn download (
314
309
url : & Url ,
@@ -460,15 +455,33 @@ pub mod reqwest_be {
460
455
}
461
456
}
462
457
458
+ #[ derive( Debug , Error ) ]
459
+ pub enum DownloadError {
460
+ #[ error( "http request returned an unsuccessful status code: {0}" ) ]
461
+ HttpStatus ( u32 ) ,
462
+ #[ error( "file not found" ) ]
463
+ FileNotFound ,
464
+ #[ error( "download backend '{0}' unavailable" ) ]
465
+ BackendUnavailable ( & ' static str ) ,
466
+ #[ error( "{0}" ) ]
467
+ Message ( String ) ,
468
+ #[ error( transparent) ]
469
+ IoError ( #[ from] std:: io:: Error ) ,
470
+ #[ cfg( feature = "reqwest-backend" ) ]
471
+ #[ error( transparent) ]
472
+ Reqwest ( #[ from] :: reqwest:: Error ) ,
473
+ #[ cfg( feature = "curl-backend" ) ]
474
+ #[ error( transparent) ]
475
+ CurlError ( #[ from] :: curl:: Error ) ,
476
+ }
477
+
463
478
#[ cfg( not( feature = "curl-backend" ) ) ]
464
479
pub mod curl {
465
-
466
480
use anyhow:: { anyhow, Result } ;
467
-
468
- use super :: Event ;
469
- use crate :: errors:: * ;
470
481
use url:: Url ;
471
482
483
+ use super :: { DownloadError , Event } ;
484
+
472
485
pub fn download (
473
486
_url : & Url ,
474
487
_resume_from : u64 ,
@@ -480,14 +493,11 @@ pub mod curl {
480
493
481
494
#[ cfg( not( feature = "reqwest-backend" ) ) ]
482
495
pub mod reqwest_be {
483
-
484
496
use anyhow:: { anyhow, Result } ;
485
-
486
- use super :: Event ;
487
- use super :: TlsBackend ;
488
- use crate :: errors:: * ;
489
497
use url:: Url ;
490
498
499
+ use super :: { DownloadError , Event , TlsBackend } ;
500
+
491
501
pub fn download (
492
502
_url : & Url ,
493
503
_resume_from : u64 ,
0 commit comments