-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmod.rs
43 lines (39 loc) · 895 Bytes
/
mod.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
//! crates mod contains index, crates and rustup
//!
//!
//!
//!
//!
pub mod channel;
pub mod crates_file;
pub mod index;
pub mod rustup;
#[derive(Clone, Default, Debug)]
pub enum DownloadMode {
Init,
// indicates this operation is fix error downloads
Fix,
#[default]
Increment,
}
impl DownloadMode {
pub fn new(init: bool, fix: bool) -> Self {
if init {
DownloadMode::Init
} else if fix {
DownloadMode::Fix
} else {
DownloadMode::Increment
}
}
}
pub mod utils {
// the path rules of crates index file
pub fn index_suffix(name: &str) -> String {
match name.len() {
1..=2 => format!("{}/{}", name.len(), name),
3 => format!("{}/{}/{}", name.len(), &name[0..1], name),
_ => format!("{}/{}/{}", &name[0..2], &name[2..4], name),
}
}
}