#[derive(Default, Debug, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
#[derive(Serialize, Deserialize)]
pub struct MegaBytes(u64);
impl Display for MegaBytes
{
#[inline(always)]
fn fmt(&self, f: &mut Formatter) -> fmt::Result
{
write!(f, "{} mb", self.0)
}
}
impl From<u8> for MegaBytes
{
#[inline(always)]
fn from(value: u8) -> Self
{
MegaBytes(value as u64)
}
}
impl From<u16> for MegaBytes
{
#[inline(always)]
fn from(value: u16) -> Self
{
MegaBytes(value as u64)
}
}
impl From<u32> for MegaBytes
{
#[inline(always)]
fn from(value: u32) -> Self
{
MegaBytes(value as u64)
}
}
impl From<u64> for MegaBytes
{
#[inline(always)]
fn from(value: u64) -> Self
{
MegaBytes(value)
}
}
impl From<KiloBytes> for MegaBytes
{
#[inline(always)]
fn from(value: KiloBytes) -> Self
{
MegaBytes(value.0 / 1024)
}
}
impl Into<u64> for MegaBytes
{
#[inline(always)]
fn into(self) -> u64
{
self.0
}
}
impl MegaBytes
{
#[inline(always)]
pub fn scale_by(self, scalar: u64) -> Self
{
MegaBytes(self.0 * scalar)
}
#[inline(always)]
pub fn to_string_capped_at_dpdk_maximum(self) -> String
{
const MaximumMegaBytes: u64 = 512;
format!("{}", min(self.0, MaximumMegaBytes))
}
}