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.
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
impl<const LOWER: i32, const UPPER: i32> Copy for BoundedInt32<LOWER, UPPER>
impl<const LOWER: i32, const UPPER: i32> Eq for BoundedInt32<LOWER, UPPER>
impl<const LOWER: i32, const UPPER: i32> StructuralPartialEq for BoundedInt32<LOWER, UPPER>
Auto Trait Implementations§
impl<const LOWER: i32, const UPPER: i32> Freeze for BoundedInt32<LOWER, UPPER>
impl<const LOWER: i32, const UPPER: i32> RefUnwindSafe for BoundedInt32<LOWER, UPPER>
impl<const LOWER: i32, const UPPER: i32> Send for BoundedInt32<LOWER, UPPER>
impl<const LOWER: i32, const UPPER: i32> Sync for BoundedInt32<LOWER, UPPER>
impl<const LOWER: i32, const UPPER: i32> Unpin for BoundedInt32<LOWER, UPPER>
impl<const LOWER: i32, const UPPER: i32> UnwindSafe for BoundedInt32<LOWER, UPPER>
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
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)
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)
clone_to_uninit)