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 const fn lower(&self) -> i32
pub const fn lower(&self) -> i32
Return the lower bound value of this bounded i32.
This always return Self::LOWER
.
Sourcepub const fn upper(&self) -> i32
pub const fn upper(&self) -> i32
Return the lower bound value of this bounded i32.
This always return Self::LOWER
.
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 L: i32, const H: i32> From<BoundedInt32<L, H>> for u32
impl<const L: i32, const H: i32> From<BoundedInt32<L, H>> for u32
Source§fn from(val: BoundedInt32<L, H>) -> u32
fn from(val: BoundedInt32<L, 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> HasMemoryCostStructural for BoundedInt32<LOWER, UPPER>
impl<const LOWER: i32, const UPPER: i32> HasMemoryCostStructural for BoundedInt32<LOWER, UPPER>
Source§fn indirect_memory_cost(&self, et: EnabledToken) -> usize
fn indirect_memory_cost(&self, et: EnabledToken) -> usize
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§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.Source§impl<T> HasMemoryCost for Twhere
T: HasMemoryCostStructural,
impl<T> HasMemoryCost for Twhere
T: HasMemoryCostStructural,
Source§fn memory_cost(&self, et: EnabledToken) -> usize
fn memory_cost(&self, et: EnabledToken) -> usize
self
, in bytes Read moreSource§impl<T> HasTypedMemoryCost<T> for Twhere
T: HasMemoryCost,
impl<T> HasTypedMemoryCost<T> for Twhere
T: HasMemoryCost,
Source§fn typed_memory_cost(&self, enabled: EnabledToken) -> TypedMemoryCost<T>
fn typed_memory_cost(&self, enabled: EnabledToken) -> TypedMemoryCost<T>
TypedMemoryCost<T>
rather than a raw usize
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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>
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>
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
Source§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
Source§fn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
impl<T> ErasedDestructor for Twhere
T: 'static,
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...)
attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 4 bytes