pub struct Bytesize(pub usize);
Expand description
Human-readable byte size representation with parsing/serialization support
§Example:
use rmqtt_utils::Bytesize;
// Create from string
let size = Bytesize::try_from("2G512M").unwrap();
assert_eq!(size.as_usize(), 2_684_354_560);
// Create from integer
let size = Bytesize::from(1024);
assert_eq!(size.string(), "1K");
Tuple Fields§
§0: usize
Implementations§
Source§impl Bytesize
impl Bytesize
Sourcepub fn as_u32(&self) -> u32
pub fn as_u32(&self) -> u32
Convert to u32 (may truncate on 32-bit platforms)
§Example:
let size = rmqtt_utils::Bytesize(5000);
assert_eq!(size.as_u32(), 5000);
Sourcepub fn as_u64(&self) -> u64
pub fn as_u64(&self) -> u64
Convert to u64
§Example:
let size = rmqtt_utils::Bytesize(usize::MAX);
assert_eq!(size.as_u64(), usize::MAX as u64);
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Bytesize
impl<'de> Deserialize<'de> for Bytesize
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl Copy for Bytesize
Auto Trait Implementations§
impl Freeze for Bytesize
impl RefUnwindSafe for Bytesize
impl Send for Bytesize
impl Sync for Bytesize
impl Unpin for Bytesize
impl UnwindSafe for Bytesize
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more