Struct constmuck::IsContiguous [−][src]
pub struct IsContiguous<T, IntRepr> { /* fields omitted */ }
Expand description
Encodes a T:
Contiguous
<Int = IntRepr>
bound as a value.
This also stores the minimum and maximum values of the integer represetantion.
Related: the contiguous
module.
Implementations
Constructs an IsContiguous
You can also use the IsContiguous
or infer
macros
to construct IsContiguous
arguments.
Constructs an IsContiguous
without checking that T
implements
Contiguous<Int = IntRepr>
Safety
You must ensure that T
follows the
safety requirements of Contiguous
,
<T as Contiguous>::Int
is IntRepr
,
min_value
equals <T as Contiguous>::MIN_VALUE
,
and max_value
equals <T as Contiguous>::MAX_VALUE
.
Example
use constmuck::{IsContiguous, contiguous};
use std::num::Wrapping;
let ic = unsafe { IsContiguous::<Wrapping<u8>, u8>::new_unchecked(10, 20) };
assert_eq!(contiguous::from_u8(9, ic), None);
assert_eq!(contiguous::from_u8(10, ic), Some(Wrapping(10)));
assert_eq!(contiguous::from_u8(20, ic), Some(Wrapping(20)));
assert_eq!(contiguous::from_u8(21, ic), None);
assert_eq!(contiguous::into_integer(Wrapping(11), &ic), 11);
assert_eq!(contiguous::into_integer(Wrapping(15), &ic), 15);
Gets the minimum value of T
’s integer representation
Example
use constmuck::IsContiguous;
use std::num::NonZeroU8;
{
let ic = IsContiguous!(NonZeroU8);
assert_eq!(ic.min_value(), &1);
}
{
let ic = IsContiguous!(u16);
assert_eq!(ic.min_value(), &0);
}
Gets the maximum value of T
’s integer representation
Example
use constmuck::IsContiguous;
use std::num::NonZeroU16;
{
let ic = IsContiguous!(NonZeroU16);
assert_eq!(ic.max_value(), &u16::MAX);
}
{
let ic = IsContiguous!(u8);
assert_eq!(ic.max_value(), &u8::MAX);
}