use core::ops::Mul;
use super::private;
pub const trait BaseByteSize: private::Sealed + Clone + Copy + Sized {
fn to_f64(&self) -> f64;
}
pub const trait KiloByteSize: [const] BaseByteSize + [const] Mul<Output = Self> {
const KB: Self;
const KIB: Self;
}
pub const trait MegaByteSize: [const] KiloByteSize {
const MB: Self;
const MIB: Self;
}
pub const trait GigaByteSize: [const] MegaByteSize {
const GB: Self;
const GIB: Self;
}
pub const trait TeraByteSize: [const] GigaByteSize {
const TB: Self;
const TIB: Self;
}
pub const trait PetaByteSize: [const] TeraByteSize {
const PB: Self;
const PIB: Self;
}
pub const trait ExaByteSize: [const] PetaByteSize {
const EB: Self;
const EIB: Self;
}
macroweave::repeat!(Ty in [u8, u16, u32, u64, usize] {
const impl BaseByteSize for Ty {
fn to_f64(&self) -> f64 {
*self as f64
}
}
});
macroweave::repeat!((Trait, Ty, DecimalName, BinaryName, Scale) in [
(KiloByteSize, u16, KB, KIB, 1),
(KiloByteSize, u32, KB, KIB, 1),
(MegaByteSize, u32, MB, MIB, 2),
(GigaByteSize, u32, GB, GIB, 3),
(KiloByteSize, u64, KB, KIB, 1),
(MegaByteSize, u64, MB, MIB, 2),
(GigaByteSize, u64, GB, GIB, 3),
(TeraByteSize, u64, TB, TIB, 4),
(PetaByteSize, u64, PB, PIB, 5),
(ExaByteSize, u64, EB, EIB, 6),
] {
const impl Trait for Ty {
const DecimalName: Self = Ty::pow(1000, Scale);
const BinaryName: Self = Ty::pow(1024, Scale);
}
});
macroweave::repeat!((PointerWidth, Trait, DecimalName, BinaryName, Scale) in [
("16", KiloByteSize, KB, KIB, 1),
("32", KiloByteSize, KB, KIB, 1),
("32", MegaByteSize, MB, MIB, 2),
("32", GigaByteSize, GB, GIB, 3),
("64", KiloByteSize, KB, KIB, 1),
("64", MegaByteSize, MB, MIB, 2),
("64", GigaByteSize, GB, GIB, 3),
("64", TeraByteSize, TB, TIB, 4),
("64", PetaByteSize, PB, PIB, 5),
("64", ExaByteSize, EB, EIB, 6),
] {
#[cfg(target_pointer_width = PointerWidth)]
const impl Trait for usize {
const DecimalName: Self = usize::pow(1000, Scale);
const BinaryName: Self = usize::pow(1024, Scale);
}
});