1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#![forbid(unsafe_code)]
#![deny(
bare_trait_objects,
unused_doc_comments,
unused_import_braces,
missing_docs
)]
#![warn(clippy::all, clippy::nursery, clippy::pedantic)]
#![allow(clippy::non_ascii_literal)]
pub mod backend;
pub mod download;
pub mod downloader;
pub mod progress;
pub mod verify;
pub use crate::download::Download;
pub use crate::downloader::Downloader;
pub use crate::progress::Progress;
pub use crate::verify::{SimpleProgress, Verification, Verify};
#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error("Setup error: {0}")]
Setup(String),
#[error("Download definition: {0}")]
DownloadDefinition(String),
#[error("File creation failed: {0}")]
File(DownloadSummary),
#[error("Download failed for {0}")]
Download(DownloadSummary),
#[error("Verification failed for {0}")]
Verification(DownloadSummary),
}
pub type Result<T> = std::result::Result<T, Error>;
pub struct DownloadSummary {
pub status: Vec<(String, u16)>,
pub file_name: std::path::PathBuf,
pub verified: Verification,
}
fn to_fmt(f: &mut std::fmt::Formatter<'_>, summary: &DownloadSummary) -> std::fmt::Result {
writeln!(
f,
"{}: (verification: {}):",
summary.file_name.to_string_lossy(),
match summary.verified {
Verification::NotVerified => "unverified",
Verification::Failed => "FAILED",
Verification::Ok => "Ok",
},
)?;
for i in 0..summary.status.len() {
writeln!(
f,
" {}: {} with status {}",
i + 1,
summary.status[i].0,
summary.status[i].1
)?;
}
Ok(())
}
impl std::fmt::Display for DownloadSummary {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
to_fmt(f, self)
}
}
impl std::fmt::Debug for DownloadSummary {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
to_fmt(f, self)
}
}