#[repr(C)]pub struct RangeI32<const RMIN: i32, const RMAX: i32>(/* private fields */);
num
only.Expand description
A signed integer that is known to be included in some inclusive range.
It has an optimized memory layout, so that
Option<RangeI32>
is the same size as RangeI32
.
Examples
use devela::num::RangeI32;
assert![RangeI32::<5, 25>::new(4).is_none()];
assert![RangeI32::<5, 25>::new(26).is_none()];
assert![RangeI32::<5, 25>::new(5).unwrap().get() == 5];
assert![RangeI32::<5, 25>::new(25).unwrap().get() == 25];
assert![RangeI32::<5, 25>::VALID_VALUES == 21];
// Self::INVALID_VALUES + Self::VALID_VALUES == u32::MAX + 1.
assert![RangeI32::<5, 25>::INVALID_VALUES == u32::MAX - 21 + 1];
Implementations§
source§impl<const RMIN: i32, const RMAX: i32> RangeI32<RMIN, RMAX>
impl<const RMIN: i32, const RMAX: i32> RangeI32<RMIN, RMAX>
sourcepub const fn new(value: i32) -> Option<Self>
pub const fn new(value: i32) -> Option<Self>
Returns a RangeI32
with the given value
, only if it’s between RMIN
and RMAX
.
Returns None
if value
is not between RMIN
and RMAX
, inclusive,
or if RMIN > RMAX
.
sourcepub const unsafe fn new_unchecked(value: i32) -> Self
Available on crate feature unsafe_num
only.
pub const unsafe fn new_unchecked(value: i32) -> Self
unsafe_num
only.sourcepub const VALID_VALUES: u32 = _
pub const VALID_VALUES: u32 = _
Returns the number of valid values within the range from RMIN
to RMAX
,
inclusive, as an unsigned integer with equal bit size.
Notice
A range where RMAX == RMIN
will result in VALID_VALUES == 1
, as expected.
But a range from i32::MIN
to i32::MAX
will result in VALID_VALUES == 0
, instead of u32::MAX
+ 1
,
This is because the maximum number of representable values for a given
bit-size can’t be represented using the same number of bits.
In this case INVALID_VALUES
will also be == 0
.
This doesn’t matter as much because a RangeI32
with the largest range of values is really just a i32
.
Remember that INVALID_VALUES + VALID_VALUES == u32::MAX + 1
,
which would wrap to 0
.
sourcepub const INVALID_VALUES: u32 = _
pub const INVALID_VALUES: u32 = _
Returns the number of invalid values outside the range from RMIN
to RMAX
,
inclusive, as an unsigned integer with equal bit size.
Notice
A range where RMAX == RMIN
will result in INVALID_VALUES ==
u32::MAX
, as expected.
A range from i32::MIN
to i32::MAX
will result
in INVALID_VALUES == 0
, also as expected.
Just be aware that in this case VALID_VALUES
will also be == 0
instead of
u32::MAX
+ 1
.
Trait Implementations§
source§impl<const RMIN: i32, const RMAX: i32> BitSize<32> for RangeI32<RMIN, RMAX>
Available on crate feature mem
only.
impl<const RMIN: i32, const RMAX: i32> BitSize<32> for RangeI32<RMIN, RMAX>
mem
only.source§const BIT_SIZE: usize = _
const BIT_SIZE: usize = _
source§const MIN_BYTE_SIZE: usize = _
const MIN_BYTE_SIZE: usize = _
source§fn bit_size(&self) -> usize
fn bit_size(&self) -> usize
source§fn min_byte_size(&self) -> usize
fn min_byte_size(&self) -> usize
source§impl<const RMIN: i32, const RMAX: i32> Num for RangeI32<RMIN, RMAX>
impl<const RMIN: i32, const RMAX: i32> Num for RangeI32<RMIN, RMAX>
source§fn num_from_ref(from: &Self::Inner) -> Result<Self>
fn num_from_ref(from: &Self::Inner) -> Result<Self>
Self
if given a valid &value
.source§fn num_set_ref(&mut self, value: &Self::Inner) -> Result<()>
fn num_set_ref(&mut self, value: &Self::Inner) -> Result<()>
self
to the given valid &value
.source§fn num_is_zero(&self) -> Result<bool>
fn num_is_zero(&self) -> Result<bool>
true
if self
is zero.source§fn num_is_one(&self) -> Result<bool>
fn num_is_one(&self) -> Result<bool>
true
if self
is one.source§fn num_get_zero() -> Result<Self>
fn num_get_zero() -> Result<Self>
source§fn num_get_one() -> Result<Self>
fn num_get_one() -> Result<Self>
source§fn num_set_zero(&mut self) -> Result<()>
fn num_set_zero(&mut self) -> Result<()>
self
to 0
.source§fn num_set_one(&mut self) -> Result<()>
fn num_set_one(&mut self) -> Result<()>
source§fn num_ref_add(&self, other: Self) -> Result<Self::OpOut>
fn num_ref_add(&self, other: Self) -> Result<Self::OpOut>
&self
+ other
.source§fn num_ref_mul(&self, other: Self) -> Result<Self::OpOut>
fn num_ref_mul(&self, other: Self) -> Result<Self::OpOut>
&self
* other
.source§fn num_ref_sub(&self, other: Self) -> Result<Self::OpOut>
fn num_ref_sub(&self, other: Self) -> Result<Self::OpOut>
&self
- other
.source§fn num_ref_div(&self, other: Self) -> Result<Self::OpOut>
fn num_ref_div(&self, other: Self) -> Result<Self::OpOut>
&self
/ other
.source§fn num_ref_rem(&self, other: Self) -> Result<Self::OpOut>
fn num_ref_rem(&self, other: Self) -> Result<Self::OpOut>
&self
% other
.source§fn num_ref_neg(&self) -> Result<Self::OpOut>
fn num_ref_neg(&self) -> Result<Self::OpOut>
- &self
.source§fn num_ref_abs(&self) -> Result<Self::OpOut>
fn num_ref_abs(&self) -> Result<Self::OpOut>
&self
.source§impl<const RMIN: i32, const RMAX: i32> Ord for RangeI32<RMIN, RMAX>
impl<const RMIN: i32, const RMAX: i32> Ord for RangeI32<RMIN, RMAX>
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere Self: Sized,
source§impl<const RMIN: i32, const RMAX: i32> PartialEq for RangeI32<RMIN, RMAX>
impl<const RMIN: i32, const RMAX: i32> PartialEq for RangeI32<RMIN, RMAX>
source§impl<const RMIN: i32, const RMAX: i32> PartialOrd for RangeI32<RMIN, RMAX>
impl<const RMIN: i32, const RMAX: i32> PartialOrd for RangeI32<RMIN, RMAX>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moreimpl<const RMIN: i32, const RMAX: i32> Copy for RangeI32<RMIN, RMAX>
impl<const RMIN: i32, const RMAX: i32> Eq for RangeI32<RMIN, RMAX>
impl<const RMIN: i32, const RMAX: i32> IntBufAble for RangeI32<RMIN, RMAX>
unsafe_text
and text
only.impl<const RMIN: i32, const RMAX: i32> StructuralEq for RangeI32<RMIN, RMAX>
impl<const RMIN: i32, const RMAX: i32> StructuralPartialEq for RangeI32<RMIN, RMAX>
Auto Trait Implementations§
impl<const RMIN: i32, const RMAX: i32> RefUnwindSafe for RangeI32<RMIN, RMAX>
impl<const RMIN: i32, const RMAX: i32> Send for RangeI32<RMIN, RMAX>
impl<const RMIN: i32, const RMAX: i32> Sync for RangeI32<RMIN, RMAX>
impl<const RMIN: i32, const RMAX: i32> Unpin for RangeI32<RMIN, RMAX>
impl<const RMIN: i32, const RMAX: i32> UnwindSafe for RangeI32<RMIN, RMAX>
Blanket Implementations§
source§impl<T> Also for T
impl<T> Also for T
source§impl<T> AnyExt for Twhere
T: Any,
impl<T> AnyExt for Twhere T: Any,
source§fn type_name(&self) -> &'static str
fn type_name(&self) -> &'static str
any
only.self
. Read moresource§fn as_any_ref(&self) -> &dyn Anywhere
Self: Sized,
fn as_any_ref(&self) -> &dyn Anywhere Self: Sized,
any
only.source§fn as_any_mut(&mut self) -> &mut dyn Anywhere
Self: Sized,
fn as_any_mut(&mut self) -> &mut dyn Anywhere Self: Sized,
any
only.source§impl<T, Res> Apply<Res> for Twhere
T: ?Sized,
impl<T, Res> Apply<Res> for Twhere T: ?Sized,
source§fn apply<F: FnOnce(Self) -> Res>(self, f: F) -> Reswhere
Self: Sized,
fn apply<F: FnOnce(Self) -> Res>(self, f: F) -> Reswhere Self: Sized,
result
only.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> CheckedAs for T
impl<T> CheckedAs for T
source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where T: CheckedCast<Dst>,
source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere Src: CheckedCast<Dst>,
source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
source§impl<T> Mem for Twhere
T: ?Sized,
impl<T> Mem for Twhere T: ?Sized,
source§const NEEDS_DROP: bool = _
const NEEDS_DROP: bool = _
mem
only.source§fn mem_needs_drop(&self) -> bool
fn mem_needs_drop(&self) -> bool
mem
only.true
if dropping values of this type matters.source§fn mem_drop(self)where
Self: Sized,
fn mem_drop(self)where Self: Sized,
mem
only.self
by running its destructor.source§fn mem_forget(self)where
Self: Sized,
fn mem_forget(self)where Self: Sized,
mem
only.self
without running its destructor.source§fn mem_replace(&mut self, other: Self) -> Selfwhere
Self: Sized,
fn mem_replace(&mut self, other: Self) -> Selfwhere Self: Sized,
mem
only.self
with other, returning the previous value of self
.source§fn mem_take(&mut self) -> Selfwhere
Self: Default,
fn mem_take(&mut self) -> Selfwhere Self: Default,
mem
only.self
with its default value, returning the previous value of self
.source§fn mem_swap(&mut self, other: &mut Self)where
Self: Sized,
fn mem_swap(&mut self, other: &mut Self)where Self: Sized,
mem
only.self
and other
without deinitializing either one.source§impl<T> OverflowingAs for T
impl<T> OverflowingAs for T
source§fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
fn overflowing_as<Dst>(self) -> (Dst, bool)where T: OverflowingCast<Dst>,
source§impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere Src: OverflowingCast<Dst>,
source§fn overflowing_cast_from(src: Src) -> (Dst, bool)
fn overflowing_cast_from(src: Src) -> (Dst, bool)
source§impl<T> SaturatingAs for T
impl<T> SaturatingAs for T
source§fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
fn saturating_as<Dst>(self) -> Dstwhere T: SaturatingCast<Dst>,
source§impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere Src: SaturatingCast<Dst>,
source§fn saturating_cast_from(src: Src) -> Dst
fn saturating_cast_from(src: Src) -> Dst
source§impl<T> Size for T
impl<T> Size for T
source§const BYTE_ALIGN: usize = _
const BYTE_ALIGN: usize = _
mem
only.source§const BYTE_SIZE: usize = _
const BYTE_SIZE: usize = _
mem
only.source§const PTR_SIZE: usize = 4usize
const PTR_SIZE: usize = 4usize
mem
only.source§fn byte_align(&self) -> usize
fn byte_align(&self) -> usize
mem
only.