Struct tor_units::BoundedInt32
source · pub struct BoundedInt32<const LOWER: i32, const UPPER: i32> { /* private fields */ }Expand description
A 32-bit signed integer with a restricted range.
This type holds an i32 value such that LOWER <= value <= UPPER
Limitations
If you try to instantiate this type with LOWER > UPPER, you will get an uninhabitable type. It would be better if we could check that at compile time, and prevent such types from being named.
Implementations§
source§impl<const LOWER: i32, const UPPER: i32> BoundedInt32<LOWER, UPPER>
impl<const LOWER: i32, const UPPER: i32> BoundedInt32<LOWER, UPPER>
sourcepub fn get(&self) -> i32
pub fn get(&self) -> i32
Return the underlying i32 value.
This value will always be between Self::LOWER and Self::UPPER,
inclusive.
sourcepub fn saturating_new(val: i32) -> Self
pub fn saturating_new(val: i32) -> Self
If val is within range, return a new BoundedInt32 wrapping
it; otherwise, clamp it to the upper or lower bound as
appropriate.
sourcepub fn checked_new(val: i32) -> Result<Self, Error>
pub fn checked_new(val: i32) -> Result<Self, Error>
If val is an acceptable value inside the range for this type,
return a new BoundedInt32. Otherwise return an error.
sourcepub fn saturating_from(val: i32) -> Self
pub fn saturating_from(val: i32) -> Self
Convert from the underlying type, clamping to the upper or lower bound if needed.
Panics
This function will panic if UPPER < LOWER.
sourcepub fn saturating_from_str(s: &str) -> Result<Self, Error>
pub fn saturating_from_str(s: &str) -> Result<Self, Error>
Convert from a string, clamping to the upper or lower bound if needed.
Limitations
If the input is a number that cannot be represented as an i32, then we return an error instead of clamping it.
Trait Implementations§
source§impl<const LOWER: i32, const UPPER: i32> Clone for BoundedInt32<LOWER, UPPER>
impl<const LOWER: i32, const UPPER: i32> Clone for BoundedInt32<LOWER, UPPER>
source§fn clone(&self) -> BoundedInt32<LOWER, UPPER>
fn clone(&self) -> BoundedInt32<LOWER, UPPER>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresource§impl From<BoundedInt32<0, 1>> for bool
impl From<BoundedInt32<0, 1>> for bool
source§fn from(val: BoundedInt32<0, 1>) -> bool
fn from(val: BoundedInt32<0, 1>) -> bool
source§impl From<BoundedInt32<0, 255>> for u8
impl From<BoundedInt32<0, 255>> for u8
source§fn from(val: BoundedInt32<0, 255>) -> u8
fn from(val: BoundedInt32<0, 255>) -> u8
source§impl<const H: i32> From<BoundedInt32<0, H>> for u32
impl<const H: i32> From<BoundedInt32<0, H>> for u32
source§fn from(val: BoundedInt32<0, H>) -> u32
fn from(val: BoundedInt32<0, H>) -> u32
source§impl<const H: i32> From<BoundedInt32<1, H>> for u32
impl<const H: i32> From<BoundedInt32<1, H>> for u32
source§fn from(val: BoundedInt32<1, H>) -> u32
fn from(val: BoundedInt32<1, H>) -> u32
source§impl<const L: i32, const U: i32> From<BoundedInt32<L, U>> for f64
impl<const L: i32, const U: i32> From<BoundedInt32<L, U>> for f64
source§fn from(val: BoundedInt32<L, U>) -> f64
fn from(val: BoundedInt32<L, U>) -> f64
source§impl<const L: i32, const U: i32> From<BoundedInt32<L, U>> for i32
impl<const L: i32, const U: i32> From<BoundedInt32<L, U>> for i32
source§fn from(val: BoundedInt32<L, U>) -> i32
fn from(val: BoundedInt32<L, U>) -> i32
source§impl<const LOWER: i32, const UPPER: i32> PartialEq<BoundedInt32<LOWER, UPPER>> for BoundedInt32<LOWER, UPPER>
impl<const LOWER: i32, const UPPER: i32> PartialEq<BoundedInt32<LOWER, UPPER>> for BoundedInt32<LOWER, UPPER>
source§fn eq(&self, other: &BoundedInt32<LOWER, UPPER>) -> bool
fn eq(&self, other: &BoundedInt32<LOWER, UPPER>) -> bool
self and other values to be equal, and is used
by ==.