use std::fmt;
use std::borrow::Cow;
use response::NamedResponse;
use response;
#[derive(Deserialize, Debug)]
pub struct Image {
id: f64,
name: String,
distribution: String,
slug: Option<String>,
public: bool,
regions: Vec<String>,
created_at: String,
min_disk_size: f64,
#[serde(rename = "type")]
image_type: String,
}
impl response::NotArray for Image {}
impl fmt::Display for Image {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f,
"ID: {:.0}\n\
Name: {}\n\
Type: {}\n\
Distribution: {}\n\
Slug: {}\n\
Public: {} MB\n\
Regions: {}\n\
Minimum Disk Size: {} GB",
self.id,
self.name,
self.image_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)
}
}
impl NamedResponse for Image {
fn name<'a>() -> Cow<'a, str> {
"image".into()
}
}
pub type Images = Vec<Image>;