use std::fmt;
use std::borrow::Cow;
use response::NamedResponse;
use response;
#[derive(Deserialize, Debug)]
pub struct Size {
slug: String,
memory: f64,
vcpus: f64,
disk: f64,
transfer: f64,
price_monthly: f64,
price_hourly: f64,
regions: Vec<String>,
available: bool,
}
impl response::NotArray for Size {}
impl fmt::Display for Size {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f,
"Slug: {}\n\
Available: {}\n\
Transfer Bandwidth: {} TB\n\
Monthly Price: ${}\n\
Hourly Price: ${}\n\
Memory: {} MB\n\
Virtual CPUs: {:.0}\n\
Disk Space: {} GB\n\
Sizes: {}",
self.slug,
self.available,
self.transfer,
self.price_monthly,
self.price_hourly,
self.memory,
self.vcpus,
self.disk,
self.regions.iter().fold(String::new(), |acc, s| acc + &format!(" {},", s)[..]))
}
}
impl NamedResponse for Size {
fn name<'a>() -> Cow<'a, str> {
"size".into()
}
}
pub type Sizes = Vec<Size>;