Macro constmuck::IsContiguous [−][src]
macro_rules! IsContiguous {
() => { ... };
($T : ty $(,) *) => { ... };
($T : ty, $IntRepr : ty $(,) *) => { ... };
}
Expand description
Constructs an IsContiguous<$T, $IntRepr>
,
requires $T:
Contiguous
<Int = $IntRepr>
.
This has two optional type arguments ($T
and $IntRepr
) that default to
infering the type if not passed.
Example
use constmuck::{IsContiguous, contiguous};
use std::num::NonZeroU8;
// The three lines below are equivalent.
const FOO: IsContiguous<NonZeroU8, u8> = IsContiguous!();
const BAR: IsContiguous<NonZeroU8, u8> = IsContiguous!(NonZeroU8);
const BAZ: IsContiguous<NonZeroU8, u8> = IsContiguous!(NonZeroU8, u8);
assert_eq!(contiguous::from_u8(0, FOO), None);
assert_eq!(contiguous::from_u8(0, BAR), None);
assert_eq!(contiguous::from_u8(0, BAZ), None);
assert_eq!(contiguous::from_u8(1, BAZ), Some(NonZeroU8::new(1).unwrap()));
assert_eq!(contiguous::into_integer(NonZeroU8::new(1).unwrap(), &FOO), 1u8);