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
use std::fmt;
use std::borrow::Cow;
use response::NamedResponse;
use response;
#[derive(Deserialize, Debug)]
pub struct Snapshot {
pub id: f64,
pub name: String,
#[serde(rename = "type")]
pub s_type: String,
pub distribution: String,
pub slug: Option<String>,
pub public: bool,
pub regions: Vec<String>,
pub min_disk_size: f64
}
impl response::NotArray for Snapshot {}
impl fmt::Display for Snapshot {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "ID: {:.0}\n\
Name: {}\n\
Type:{}\n\
Distribution:{}\n\
Slug:{}\n\
Public:{}\n\
Regions:{}\n\
Minimum Disk Size: {:.0} MB\n",
self.id,
self.name,
self.s_type,
self.distribution,
if let Some(ref s) = self.slug { s.clone() } else { "None".to_owned() },
self.public,
self.regions.iter().fold(String::new(), |acc, s| acc + &format!(" {},", s)[..]),
self.min_disk_size)
}
}
pub type Snapshots = Vec<Snapshot>;
impl NamedResponse for Snapshot {
fn name<'a>() -> Cow<'a, str> {
"snapshot".into()
}
}