downloader_rs/
download_status.rs1use std::fmt::{Display, Formatter};
2
3#[derive(PartialEq, Clone, Copy)]
4pub enum DownloadStatus {
5 None,
6 Pending,
7 Head,
8 Download,
9 DownloadPost,
10 FileVerify,
11 Complete,
12 Failed,
13 Stop,
14}
15
16impl Display for DownloadStatus {
17 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
18 match self {
19 DownloadStatus::None => write!(f, "None"),
20 DownloadStatus::Pending => write!(f, "Pending"),
21 DownloadStatus::Head => write!(f, "Head"),
22 DownloadStatus::Download => write!(f, "Download"),
23 DownloadStatus::FileVerify => write!(f, "FileVerify"),
24 DownloadStatus::DownloadPost => write!(f, "DownloadPost"),
25 DownloadStatus::Complete => write!(f, "Complete"),
26 DownloadStatus::Failed => write!(f, "Failed"),
27 DownloadStatus::Stop => write!(f, "Stop"),
28 }
29 }
30}
31
32impl Into<u8> for DownloadStatus {
33 fn into(self) -> u8 {
34 match self {
35 DownloadStatus::None => 0,
36 DownloadStatus::Pending => 1,
37 DownloadStatus::Head => 2,
38 DownloadStatus::Download => 3,
39 DownloadStatus::DownloadPost => 4,
40 DownloadStatus::FileVerify => 5,
41 DownloadStatus::Complete => 6,
42 DownloadStatus::Failed => 7,
43 DownloadStatus::Stop => 8
44 }
45 }
46}
47
48impl From<u8> for DownloadStatus {
49 fn from(value: u8) -> Self {
50 match value {
51 0 => DownloadStatus::None,
52 1 => DownloadStatus::Pending,
53 2 => DownloadStatus::Head,
54 3 => DownloadStatus::Download,
55 4 => DownloadStatus::DownloadPost,
56 5 => DownloadStatus::FileVerify,
57 6 => DownloadStatus::Complete,
58 7 => DownloadStatus::Failed,
59 8 => DownloadStatus::Stop,
60 _ => DownloadStatus::None,
61 }
62 }
63}