use std::fmt;
use std::borrow::Cow;
use response::NamedResponse;
use response;
#[derive(Deserialize, Debug)]
pub struct Backup {
pub id: f64,
pub name: String,
#[serde(rename = "type")]
pub b_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 Backup {}
impl fmt::Display for Backup {
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.b_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 Backups = Vec<Backup>;
impl NamedResponse for Backup {
fn name<'a>() -> Cow<'a, str> {
"backup".into()
}
}