pub struct ByteSize(/* private fields */);
Expand description
Represents a size in bytes.
ByteSize
can be parsed from strings or with Serde, and remembers the original unit that was
used to describe it for stable serialization. Use ByteSize::infer
to infer the most
appropriate unit for a number of bytes.
Units based on 1000 and 1024 are both supported:
- To refer to the 1000-based versions, use “kB” and “MB”.
- To refer to the 1024-based versions, use “KiB” and “MiB”.
§Examples
Infer the best unit:
use relay_config::ByteSize;
let size = ByteSize::infer(42 * 1000 * 1000);
assert_eq!("42MB", size.to_string());
Format a 1024-based size to string:
use relay_config::ByteSize;
let size = ByteSize::kibibytes(42);
assert_eq!("42KiB", size.to_string());
Implementations§
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
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more