fast_down/base/
event.rs

1use crate::ProgressEntry;
2
3pub type WorkerId = usize;
4
5#[derive(Debug)]
6pub enum ConnectErrorKind {
7    Reqwest(reqwest::Error),
8    /// The server returned a non-206 status code when use Range header.
9    StatusCode(reqwest::StatusCode),
10}
11
12impl std::fmt::Display for ConnectErrorKind {
13    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
14        match self {
15            ConnectErrorKind::Reqwest(err) => write!(f, "Reqwest error: {}", err),
16            ConnectErrorKind::StatusCode(code) => write!(
17                f,
18                "Server returned non-206 status code: {} {}",
19                code.as_u16(),
20                code.canonical_reason().unwrap_or("unknown status")
21            ),
22        }
23    }
24}
25
26impl std::error::Error for ConnectErrorKind {
27    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
28        match self {
29            ConnectErrorKind::Reqwest(err) => Some(err),
30            ConnectErrorKind::StatusCode(_) => None,
31        }
32    }
33}
34
35#[derive(Debug)]
36pub enum Event {
37    Connecting(WorkerId),
38    ConnectError(WorkerId, ConnectErrorKind),
39    Downloading(WorkerId),
40    DownloadError(WorkerId, reqwest::Error),
41    DownloadProgress(ProgressEntry),
42    WriteError(std::io::Error),
43    WriteProgress(ProgressEntry),
44    Finished(WorkerId),
45    Abort(WorkerId),
46}