#[repr(u64)]
#[derive(Clone, Copy, PartialEq, Eq, Default, PartialOrd, Ord, Hash, Debug)]
pub enum ByteScale {
B = 1,
#[default]
KB = 1024,
MB = Self::KB as u64 * 1024,
GB = Self::MB as u64 * 1024,
TB = Self::GB as u64 * 1024,
PB = Self::TB as u64 * 1024,
EB = Self::PB as u64 * 1024,
}
impl Into<u64> for ByteScale {
fn into(self) -> u64 {
self as _
}
}
impl Into<usize> for ByteScale {
fn into(self) -> usize {
#[cfg(not(any(target_pointer_width = "32", target_pointer_width = "64")))]
assert!(self < Self::MB, "pointer width not 32 or 64");
#[cfg(not(target_pointer_width = "64"))]
assert!(self < Self::TB, "pointer width not 64");
self as _
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn sizes() {
println!("{}", ByteScale::MB as u64);
println!("{}", ByteScale::GB as u64);
println!("{}", ByteScale::TB as u64);
println!("{}", ByteScale::PB as u64);
println!("{}", ByteScale::EB as u64);
}
}