use macros::{impl_as,impl_from};
pub struct Size {
bytes: usize
}
impl_from!(Size, bytes,
bytes = ;
kilobytes = 1000;
kibibytes = 1024;
megabytes = 1000 * 1000;
mebibytes = 1024 * 1024;
gigabytes = 1000 * 1000 * 1000;
gibibytes = 1024 * 1024 * 1024;
terabytes = 1000 * 1000 * 1000 * 1000;
tebibytes = 1024 * 1024 * 1024 * 1000;
);
impl_as!(Size, bytes,
bytes = ;
kilobytes = 1000;
kibibytes = 1024;
megabytes = 1000 / 1000;
mebibytes = 1024 / 1024;
gigabytes = 1000 / 1000 / 1000;
gibibytes = 1024 / 1024 / 1024;
terabytes = 1000 / 1000 / 1000 / 1000;
tebibytes = 1024 / 1024 / 1024 / 1024;
);
#[cfg(test)]
mod test {
use super::*;
#[test]
fn test() {
let s = Size::from_bytes(1024);
assert_eq!(s.as_kibibytes(), 1);
assert_eq!(s.as_kilobytes(), 1);
assert_eq!(s.as_kibibytes_f64(), 1.0);
assert!(s.as_kilobytes_f64() > 1.0);
}
#[test]
fn tebibytes() {
let s = Size::from_bytes(12000000000000);
assert_eq!(s.as_tebibytes(), 10);
}
}