downloader_rs/
download_status.rs

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
use std::fmt::{Display, Formatter};

#[derive(PartialEq, Clone, Copy)]
pub enum DownloadStatus {
    None,
    Pending,
    Head,
    Download,
    DownloadPost,
    FileVerify,
    Complete,
    Failed,
    Stop,
}

impl Display for DownloadStatus {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        match self {
            DownloadStatus::None => write!(f, "None"),
            DownloadStatus::Pending => write!(f, "Pending"),
            DownloadStatus::Head => write!(f, "Head"),
            DownloadStatus::Download => write!(f, "Download"),
            DownloadStatus::FileVerify => write!(f, "FileVerify"),
            DownloadStatus::DownloadPost => write!(f, "DownloadPost"),
            DownloadStatus::Complete => write!(f, "Complete"),
            DownloadStatus::Failed => write!(f, "Failed"),
            DownloadStatus::Stop => write!(f, "Stop"),
        }
    }
}

impl Into<u8> for DownloadStatus {
    fn into(self) -> u8 {
        match self {
            DownloadStatus::None => 0,
            DownloadStatus::Pending => 1,
            DownloadStatus::Head => 2,
            DownloadStatus::Download => 3,
            DownloadStatus::DownloadPost => 4,
            DownloadStatus::FileVerify => 5,
            DownloadStatus::Complete => 6,
            DownloadStatus::Failed => 7,
            DownloadStatus::Stop => 8
        }
    }
}

impl From<u8> for DownloadStatus {
    fn from(value: u8) -> Self {
        match value {
            0 => DownloadStatus::None,
            1 => DownloadStatus::Pending,
            2 => DownloadStatus::Head,
            3 => DownloadStatus::Download,
            4 => DownloadStatus::DownloadPost,
            5 => DownloadStatus::FileVerify,
            6 => DownloadStatus::Complete,
            7 => DownloadStatus::Failed,
            8 => DownloadStatus::Stop,
            _ => DownloadStatus::None,
        }
    }
}