Struct smart_config::ByteSize
source · pub struct ByteSize(pub u64);
Expand description
A wrapper providing a clear reminder that the wrapped value represents the number of bytes.
§Examples
In non-const context, the most idiomatic way to produce a size is to multiply SizeUnit
by u64
:
let size = 128 * SizeUnit::MiB;
assert_eq!(size, ByteSize(128 << 20));
In const context, Self::new()
may be used instead:
const SIZE: ByteSize = ByteSize::new(128, SizeUnit::MiB);
assert_eq!(SIZE, ByteSize(128 << 20));
Tuple Fields§
§0: u64
Implementations§
source§impl ByteSize
impl ByteSize
sourcepub const fn checked(val: u64, unit: SizeUnit) -> Option<Self>
pub const fn checked(val: u64, unit: SizeUnit) -> Option<Self>
Creates a value with the specified unit of measurement checking for overflow.
sourcepub const fn checked_add(self, rhs: Self) -> Option<Self>
pub const fn checked_add(self, rhs: Self) -> Option<Self>
Adds two byte sizes.
sourcepub const fn checked_mul(self, factor: u64) -> Option<Self>
pub const fn checked_mul(self, factor: u64) -> Option<Self>
Multiplies this size by the given factor.
Trait Implementations§
source§impl CustomKnownOption for ByteSize
impl CustomKnownOption for ByteSize
§type OptDeserializer = Optional<WithUnit, true>
type OptDeserializer = Optional<WithUnit, true>
Type of the deserializer used for
Option<Self>
.source§const OPT_DE: Self::OptDeserializer = _
const OPT_DE: Self::OptDeserializer = _
Deserializer instance.
source§impl DeserializeParam<ByteSize> for SizeUnit
impl DeserializeParam<ByteSize> for SizeUnit
Supports deserializing a ByteSize
from a number, with self
being the unit of measurement.
§Examples
use smart_config::testing;
#[derive(DescribeConfig, DeserializeConfig)]
struct TestConfig {
#[config(with = SizeUnit::MiB)]
size_mb: ByteSize,
}
let source = smart_config::config!("size_mb": 4);
let config = testing::test::<TestConfig>(source)?;
assert_eq!(config.size_mb, ByteSize(4 << 20));
source§const EXPECTING: BasicTypes = BasicTypes::INTEGER
const EXPECTING: BasicTypes = BasicTypes::INTEGER
Describes which parameter this deserializer is expecting.
source§fn describe(&self, description: &mut TypeDescription)
fn describe(&self, description: &mut TypeDescription)
Additional info about the deserialized type, e.g., extended description.
source§fn deserialize_param(
&self,
ctx: DeserializeContext<'_>,
param: &'static ParamMetadata,
) -> Result<ByteSize, ErrorWithOrigin>
fn deserialize_param( &self, ctx: DeserializeContext<'_>, param: &'static ParamMetadata, ) -> Result<ByteSize, ErrorWithOrigin>
Performs deserialization given the context and param metadata. Read more
source§impl DeserializeParam<ByteSize> for WithUnit
impl DeserializeParam<ByteSize> for WithUnit
source§const EXPECTING: BasicTypes = Self::EXPECTED_TYPES
const EXPECTING: BasicTypes = Self::EXPECTED_TYPES
Describes which parameter this deserializer is expecting.
source§fn describe(&self, description: &mut TypeDescription)
fn describe(&self, description: &mut TypeDescription)
Additional info about the deserialized type, e.g., extended description.
source§fn deserialize_param(
&self,
ctx: DeserializeContext<'_>,
param: &'static ParamMetadata,
) -> Result<ByteSize, ErrorWithOrigin>
fn deserialize_param( &self, ctx: DeserializeContext<'_>, param: &'static ParamMetadata, ) -> Result<ByteSize, ErrorWithOrigin>
Performs deserialization given the context and param metadata. Read more
source§impl Ord for ByteSize
impl Ord for ByteSize
source§impl PartialOrd for ByteSize
impl PartialOrd for ByteSize
source§impl WellKnown for ByteSize
impl WellKnown for ByteSize
§type Deserializer = WithUnit
type Deserializer = WithUnit
Type of the deserializer used for this type.
source§const DE: Self::Deserializer = WithUnit
const DE: Self::Deserializer = WithUnit
Deserializer instance.
impl Copy for ByteSize
impl Eq for ByteSize
impl StructuralPartialEq 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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)source§impl<T> CloneToUninit for Twhere
T: Copy,
impl<T> CloneToUninit for Twhere
T: Copy,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Checks if this value is equivalent to the given key. Read more
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.