Struct tor_units::BoundedInt32
source · [−]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
sourceimpl<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
sourceimpl<const LOWER: i32, const UPPER: i32> Clone for BoundedInt32<LOWER, UPPER>
impl<const LOWER: i32, const UPPER: i32> Clone for BoundedInt32<LOWER, UPPER>
sourcefn clone(&self) -> BoundedInt32<LOWER, UPPER>
fn clone(&self) -> BoundedInt32<LOWER, UPPER>
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl<const LOWER: i32, const UPPER: i32> Debug for BoundedInt32<LOWER, UPPER>
impl<const LOWER: i32, const UPPER: i32> Debug for BoundedInt32<LOWER, UPPER>
sourceimpl<const L: i32, const U: i32> Display for BoundedInt32<L, U>
impl<const L: i32, const U: i32> Display for BoundedInt32<L, U>
sourceimpl From<BoundedInt32<0_i32, 1_i32>> for bool
impl From<BoundedInt32<0_i32, 1_i32>> for bool
sourcefn from(val: BoundedInt32<0, 1>) -> bool
fn from(val: BoundedInt32<0, 1>) -> bool
Converts to this type from the input type.
sourceimpl From<BoundedInt32<0_i32, 255_i32>> for u8
impl From<BoundedInt32<0_i32, 255_i32>> for u8
sourcefn from(val: BoundedInt32<0, 255>) -> u8
fn from(val: BoundedInt32<0, 255>) -> u8
Converts to this type from the input type.
sourceimpl<const H: i32> From<BoundedInt32<0_i32, H>> for u32
impl<const H: i32> From<BoundedInt32<0_i32, H>> for u32
sourcefn from(val: BoundedInt32<0, H>) -> u32
fn from(val: BoundedInt32<0, H>) -> u32
Converts to this type from the input type.
sourceimpl<const H: i32> From<BoundedInt32<1_i32, H>> for u32
impl<const H: i32> From<BoundedInt32<1_i32, H>> for u32
sourcefn from(val: BoundedInt32<1, H>) -> u32
fn from(val: BoundedInt32<1, H>) -> u32
Converts to this type from the input type.
sourceimpl<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
sourcefn from(val: BoundedInt32<L, U>) -> i32
fn from(val: BoundedInt32<L, U>) -> i32
Converts to this type from the input type.
sourceimpl<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
sourcefn from(val: BoundedInt32<L, U>) -> f64
fn from(val: BoundedInt32<L, U>) -> f64
Converts to this type from the input type.
sourceimpl<const L: i32, const H: i32> FromStr for BoundedInt32<L, H>
impl<const L: i32, const H: i32> FromStr for BoundedInt32<L, H>
sourceimpl<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>
sourcefn eq(&self, other: &BoundedInt32<LOWER, UPPER>) -> bool
fn eq(&self, other: &BoundedInt32<LOWER, UPPER>) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourcefn ne(&self, other: &BoundedInt32<LOWER, UPPER>) -> bool
fn ne(&self, other: &BoundedInt32<LOWER, UPPER>) -> bool
This method tests for !=
.
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> StructuralEq 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> 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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more