pub struct NonZeroPow2<N: NonZeroable>(/* private fields */);Expand description
A number that is non-zero and is a power of two.
Implementations§
Source§impl<N: NonZeroable> NonZeroPow2<N>
impl<N: NonZeroable> NonZeroPow2<N>
Source§impl<N> NonZeroPow2<N>
impl<N> NonZeroPow2<N>
Source§impl<N: NonZeroable> NonZeroPow2<N>
impl<N: NonZeroable> NonZeroPow2<N>
Sourcepub unsafe fn new_unchecked(value: N) -> Self
pub unsafe fn new_unchecked(value: N) -> Self
Sourcepub const unsafe fn from_nonzero_unchecked(value: N::NonZeroType) -> Self
pub const unsafe fn from_nonzero_unchecked(value: N::NonZeroType) -> Self
Sourcepub fn new(value: N) -> Option<Self>
pub fn new(value: N) -> Option<Self>
Creates a new NonZeroPow2.
Returns None if the given value is zero or not a power of two.
§Examples
assert!(NonZeroPow2::new(0usize).is_none());
assert!(NonZeroPow2::new(2usize).is_some());
assert!(NonZeroPow2::new(4usize).is_some());
assert!(NonZeroPow2::new(6usize).is_none());Sourcepub fn get(self) -> N
pub fn get(self) -> N
Gets the value of the number in its primitive representation.
§Examples
assert_eq!(
NonZeroPow2::new(32usize).unwrap().get(),
32usize,
);Sourcepub fn get_nonzero(self) -> N::NonZeroType
pub fn get_nonzero(self) -> N::NonZeroType
Gets the value of the number in its nonzero representation.
§Examples
assert_eq!(
NonZeroPow2::new(32usize).unwrap().get_nonzero(),
NonZeroUsize::new(32usize).unwrap(),
);Trait Implementations§
Source§impl<N: Clone + NonZeroable> Clone for NonZeroPow2<N>where
N::NonZeroType: Clone,
impl<N: Clone + NonZeroable> Clone for NonZeroPow2<N>where
N::NonZeroType: Clone,
Source§fn clone(&self) -> NonZeroPow2<N>
fn clone(&self) -> NonZeroPow2<N>
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<N: Debug + NonZeroable> Debug for NonZeroPow2<N>where
N::NonZeroType: Debug,
impl<N: Debug + NonZeroable> Debug for NonZeroPow2<N>where
N::NonZeroType: Debug,
Source§impl<N: Hash + NonZeroable> Hash for NonZeroPow2<N>where
N::NonZeroType: Hash,
impl<N: Hash + NonZeroable> Hash for NonZeroPow2<N>where
N::NonZeroType: Hash,
Source§impl<N: NonZeroable> Multiplier for NonZeroPow2<N>
impl<N: NonZeroable> Multiplier for NonZeroPow2<N>
Source§impl<N: Ord + NonZeroable> Ord for NonZeroPow2<N>where
N::NonZeroType: Ord,
impl<N: Ord + NonZeroable> Ord for NonZeroPow2<N>where
N::NonZeroType: Ord,
Source§fn cmp(&self, other: &NonZeroPow2<N>) -> Ordering
fn cmp(&self, other: &NonZeroPow2<N>) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl<N: PartialEq + NonZeroable> PartialEq for NonZeroPow2<N>where
N::NonZeroType: PartialEq,
impl<N: PartialEq + NonZeroable> PartialEq for NonZeroPow2<N>where
N::NonZeroType: PartialEq,
Source§impl<N: PartialOrd + NonZeroable> PartialOrd for NonZeroPow2<N>where
N::NonZeroType: PartialOrd,
impl<N: PartialOrd + NonZeroable> PartialOrd for NonZeroPow2<N>where
N::NonZeroType: PartialOrd,
impl<N: Copy + NonZeroable> Copy for NonZeroPow2<N>where
N::NonZeroType: Copy,
impl<N: Eq + NonZeroable> Eq for NonZeroPow2<N>where
N::NonZeroType: Eq,
impl<N: NonZeroable + Number> Multiplier for NonZeroPow2<N>where
Self: Copy,
impl<N: NonZeroable> StructuralPartialEq for NonZeroPow2<N>
Auto Trait Implementations§
impl<N> Freeze for NonZeroPow2<N>
impl<N> RefUnwindSafe for NonZeroPow2<N>
impl<N> Send for NonZeroPow2<N>
impl<N> Sync for NonZeroPow2<N>
impl<N> Unpin for NonZeroPow2<N>
impl<N> UnwindSafe for NonZeroPow2<N>
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
Mutably borrows from an owned value. Read more