Struct constmuck::ImplsContiguous [−][src]
pub struct ImplsContiguous<T, IntRepr> { /* fields omitted */ }
Expand description
Encodes a T:
Contiguous
bound as a value,
avoids requiring (unstable as of 2021) trait bounds in const fn
s.
Related: the contiguous
module.
Implementations
Constructs an ImplsContiguous
without checking that T
implements
Contiguous<Int = IntRepr>
Safety
You must ensure that T
follows the
safety requirements of Contiguous
Example
use constmuck::{ImplsContiguous, contiguous};
use std::num::Wrapping;
let ic = unsafe { ImplsContiguous::<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::ImplsContiguous;
use std::num::NonZeroU8;
{
let ic = ImplsContiguous::<NonZeroU8, _>::NEW;
assert_eq!(ic.min_value(), &1);
}
{
let ic = ImplsContiguous::<u16, _>::NEW;
assert_eq!(ic.min_value(), &0);
}
Gets the maximum value of T
’s integer representation
Example
use constmuck::ImplsContiguous;
use std::num::NonZeroU16;
{
let ic = ImplsContiguous::<NonZeroU16, _>::NEW;
assert_eq!(ic.max_value(), &u16::MAX);
}
{
let ic = ImplsContiguous::<u8, _>::NEW;
assert_eq!(ic.max_value(), &u8::MAX);
}