Skip to main content

core/num/
nonzero.rs

1//! Definitions of integer that is known not to equal zero.
2
3use super::{IntErrorKind, ParseIntError, TryFromIntError};
4use crate::clone::{TrivialClone, UseCloned};
5use crate::cmp::Ordering;
6use crate::hash::{Hash, Hasher};
7use crate::marker::{Destruct, Freeze, StructuralPartialEq};
8use crate::num::imp;
9use crate::ops::{BitOr, BitOrAssign, Div, DivAssign, Neg, Rem, RemAssign};
10use crate::panic::{RefUnwindSafe, UnwindSafe};
11use crate::str::FromStr;
12use crate::{fmt, intrinsics, ptr, slice, ub_checks};
13
14/// A marker trait for primitive types which can be zero.
15///
16/// This is an implementation detail for <code>[NonZero]\<T></code> which may disappear or be replaced at any time.
17///
18/// # Safety
19///
20/// Types implementing this trait must be primitives that are valid when zeroed.
21///
22/// The associated `Self::NonZeroInner` type must have the same size+align as `Self`,
23/// but with a niche and bit validity making it so the following `transmutes` are sound:
24///
25/// - `Self::NonZeroInner` to `Option<Self::NonZeroInner>`
26/// - `Option<Self::NonZeroInner>` to `Self`
27///
28/// (And, consequently, `Self::NonZeroInner` to `Self`.)
29#[unstable(
30    feature = "nonzero_internals",
31    reason = "implementation detail which may disappear or be replaced at any time",
32    issue = "none"
33)]
34pub impl(self) unsafe trait ZeroablePrimitive: Sized + Copy {
35    /// A type like `Self` but with a niche that includes zero.
36    type NonZeroInner: Sized + Copy;
37}
38
39macro_rules! impl_zeroable_primitive {
40    ($($NonZeroInner:ident ( $primitive:ty )),+ $(,)?) => {
41        $(
42            #[unstable(
43                feature = "nonzero_internals",
44                reason = "implementation detail which may disappear or be replaced at any time",
45                issue = "none"
46            )]
47            unsafe impl ZeroablePrimitive for $primitive {
48                type NonZeroInner = super::niche_types::$NonZeroInner;
49            }
50        )+
51    };
52}
53
54#[unstable(feature = "nonzero_internals", reason =
"implementation detail which may disappear or be replaced at any time", issue
= "none")]
unsafe impl ZeroablePrimitive for u8 {
    type NonZeroInner = super::niche_types::NonZeroU8Inner;
}
#[unstable(feature = "nonzero_internals", reason =
"implementation detail which may disappear or be replaced at any time", issue
= "none")]
unsafe impl ZeroablePrimitive for u16 {
    type NonZeroInner = super::niche_types::NonZeroU16Inner;
}
#[unstable(feature = "nonzero_internals", reason =
"implementation detail which may disappear or be replaced at any time", issue
= "none")]
unsafe impl ZeroablePrimitive for u32 {
    type NonZeroInner = super::niche_types::NonZeroU32Inner;
}
#[unstable(feature = "nonzero_internals", reason =
"implementation detail which may disappear or be replaced at any time", issue
= "none")]
unsafe impl ZeroablePrimitive for u64 {
    type NonZeroInner = super::niche_types::NonZeroU64Inner;
}
#[unstable(feature = "nonzero_internals", reason =
"implementation detail which may disappear or be replaced at any time", issue
= "none")]
unsafe impl ZeroablePrimitive for u128 {
    type NonZeroInner = super::niche_types::NonZeroU128Inner;
}
#[unstable(feature = "nonzero_internals", reason =
"implementation detail which may disappear or be replaced at any time", issue
= "none")]
unsafe impl ZeroablePrimitive for usize {
    type NonZeroInner = super::niche_types::NonZeroUsizeInner;
}
#[unstable(feature = "nonzero_internals", reason =
"implementation detail which may disappear or be replaced at any time", issue
= "none")]
unsafe impl ZeroablePrimitive for i8 {
    type NonZeroInner = super::niche_types::NonZeroI8Inner;
}
#[unstable(feature = "nonzero_internals", reason =
"implementation detail which may disappear or be replaced at any time", issue
= "none")]
unsafe impl ZeroablePrimitive for i16 {
    type NonZeroInner = super::niche_types::NonZeroI16Inner;
}
#[unstable(feature = "nonzero_internals", reason =
"implementation detail which may disappear or be replaced at any time", issue
= "none")]
unsafe impl ZeroablePrimitive for i32 {
    type NonZeroInner = super::niche_types::NonZeroI32Inner;
}
#[unstable(feature = "nonzero_internals", reason =
"implementation detail which may disappear or be replaced at any time", issue
= "none")]
unsafe impl ZeroablePrimitive for i64 {
    type NonZeroInner = super::niche_types::NonZeroI64Inner;
}
#[unstable(feature = "nonzero_internals", reason =
"implementation detail which may disappear or be replaced at any time", issue
= "none")]
unsafe impl ZeroablePrimitive for i128 {
    type NonZeroInner = super::niche_types::NonZeroI128Inner;
}
#[unstable(feature = "nonzero_internals", reason =
"implementation detail which may disappear or be replaced at any time", issue
= "none")]
unsafe impl ZeroablePrimitive for isize {
    type NonZeroInner = super::niche_types::NonZeroIsizeInner;
}
#[unstable(feature = "nonzero_internals", reason =
"implementation detail which may disappear or be replaced at any time", issue
= "none")]
unsafe impl ZeroablePrimitive for char {
    type NonZeroInner = super::niche_types::NonZeroCharInner;
}impl_zeroable_primitive!(
55    NonZeroU8Inner(u8),
56    NonZeroU16Inner(u16),
57    NonZeroU32Inner(u32),
58    NonZeroU64Inner(u64),
59    NonZeroU128Inner(u128),
60    NonZeroUsizeInner(usize),
61    NonZeroI8Inner(i8),
62    NonZeroI16Inner(i16),
63    NonZeroI32Inner(i32),
64    NonZeroI64Inner(i64),
65    NonZeroI128Inner(i128),
66    NonZeroIsizeInner(isize),
67    NonZeroCharInner(char),
68);
69
70/// A value that is known not to equal zero.
71///
72/// This enables some memory layout optimization.
73/// For example, `Option<NonZero<u32>>` is the same size as `u32`:
74///
75/// ```
76/// use core::num::NonZero;
77///
78/// assert_eq!(size_of::<Option<NonZero<u32>>>(), size_of::<u32>());
79/// ```
80///
81/// # Layout
82///
83/// `NonZero<T>` is guaranteed to have the same layout and bit validity as `T`
84/// with the exception that the all-zero bit pattern is invalid.
85/// `Option<NonZero<T>>` is guaranteed to be ABI-compatible with `T`, including in
86/// FFI.
87///
88/// Thanks to the [null pointer optimization], `NonZero<T>` and
89/// `Option<NonZero<T>>` are guaranteed to have the same size and alignment:
90///
91/// ```
92/// use std::num::NonZero;
93///
94/// assert_eq!(size_of::<NonZero<u32>>(), size_of::<Option<NonZero<u32>>>());
95/// assert_eq!(align_of::<NonZero<u32>>(), align_of::<Option<NonZero<u32>>>());
96/// ```
97///
98/// [null pointer optimization]: crate::option#representation
99///
100/// # Note on generic usage
101///
102/// `NonZero<T>` can only be used with some standard library primitive types
103/// (such as `u8`, `i32`, and etc.). The type parameter `T` must implement the
104/// internal trait [`ZeroablePrimitive`], which is currently permanently unstable
105/// and cannot be implemented by users. Therefore, you cannot use `NonZero<T>`
106/// with your own types, nor can you implement traits for all `NonZero<T>`,
107/// only for concrete types.
108#[stable(feature = "generic_nonzero", since = "1.79.0")]
109#[repr(transparent)]
110#[rustc_nonnull_optimization_guaranteed]
111#[rustc_diagnostic_item = "NonZero"]
112pub struct NonZero<T: ZeroablePrimitive>(T::NonZeroInner);
113
114macro_rules! impl_nonzero_fmt {
115    ($(#[$Attribute:meta] $Trait:ident)*) => {
116        $(
117            #[$Attribute]
118            impl<T> fmt::$Trait for NonZero<T>
119            where
120                T: ZeroablePrimitive + fmt::$Trait,
121            {
122                #[inline]
123                fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
124                    self.get().fmt(f)
125                }
126            }
127        )*
128    };
129}
130
131#[stable(feature = "nonzero", since = "1.28.0")]
impl<T> fmt::Debug for NonZero<T> where T: ZeroablePrimitive + fmt::Debug {
    #[inline]
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        self.get().fmt(f)
    }
}
#[stable(feature = "nonzero", since = "1.28.0")]
impl<T> fmt::Display for NonZero<T> where T: ZeroablePrimitive + fmt::Display
    {
    #[inline]
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        self.get().fmt(f)
    }
}
#[stable(feature = "nonzero", since = "1.28.0")]
impl<T> fmt::Binary for NonZero<T> where T: ZeroablePrimitive + fmt::Binary {
    #[inline]
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        self.get().fmt(f)
    }
}
#[stable(feature = "nonzero", since = "1.28.0")]
impl<T> fmt::Octal for NonZero<T> where T: ZeroablePrimitive + fmt::Octal {
    #[inline]
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        self.get().fmt(f)
    }
}
#[stable(feature = "nonzero", since = "1.28.0")]
impl<T> fmt::LowerHex for NonZero<T> where T: ZeroablePrimitive +
    fmt::LowerHex {
    #[inline]
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        self.get().fmt(f)
    }
}
#[stable(feature = "nonzero", since = "1.28.0")]
impl<T> fmt::UpperHex for NonZero<T> where T: ZeroablePrimitive +
    fmt::UpperHex {
    #[inline]
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        self.get().fmt(f)
    }
}
#[stable(feature = "nonzero_fmt_exp", since = "1.84.0")]
impl<T> fmt::LowerExp for NonZero<T> where T: ZeroablePrimitive +
    fmt::LowerExp {
    #[inline]
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        self.get().fmt(f)
    }
}
#[stable(feature = "nonzero_fmt_exp", since = "1.84.0")]
impl<T> fmt::UpperExp for NonZero<T> where T: ZeroablePrimitive +
    fmt::UpperExp {
    #[inline]
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        self.get().fmt(f)
    }
}impl_nonzero_fmt! {
132    #[stable(feature = "nonzero", since = "1.28.0")]
133    Debug
134    #[stable(feature = "nonzero", since = "1.28.0")]
135    Display
136    #[stable(feature = "nonzero", since = "1.28.0")]
137    Binary
138    #[stable(feature = "nonzero", since = "1.28.0")]
139    Octal
140    #[stable(feature = "nonzero", since = "1.28.0")]
141    LowerHex
142    #[stable(feature = "nonzero", since = "1.28.0")]
143    UpperHex
144    #[stable(feature = "nonzero_fmt_exp", since = "1.84.0")]
145    LowerExp
146    #[stable(feature = "nonzero_fmt_exp", since = "1.84.0")]
147    UpperExp
148}
149
150macro_rules! impl_nonzero_auto_trait {
151    (unsafe $Trait:ident) => {
152        #[stable(feature = "nonzero", since = "1.28.0")]
153        unsafe impl<T> $Trait for NonZero<T> where T: ZeroablePrimitive + $Trait {}
154    };
155    ($Trait:ident) => {
156        #[stable(feature = "nonzero", since = "1.28.0")]
157        impl<T> $Trait for NonZero<T> where T: ZeroablePrimitive + $Trait {}
158    };
159}
160
161// Implement auto-traits manually based on `T` to avoid docs exposing
162// the `ZeroablePrimitive::NonZeroInner` implementation detail.
163#[stable(feature = "nonzero", since = "1.28.0")]
unsafe impl<T> Freeze for NonZero<T> where T: ZeroablePrimitive + Freeze { }impl_nonzero_auto_trait!(unsafe Freeze);
164#[stable(feature = "nonzero", since = "1.28.0")]
impl<T> RefUnwindSafe for NonZero<T> where T: ZeroablePrimitive +
    RefUnwindSafe {
}impl_nonzero_auto_trait!(RefUnwindSafe);
165#[stable(feature = "nonzero", since = "1.28.0")]
unsafe impl<T> Send for NonZero<T> where T: ZeroablePrimitive + Send { }impl_nonzero_auto_trait!(unsafe Send);
166#[stable(feature = "nonzero", since = "1.28.0")]
unsafe impl<T> Sync for NonZero<T> where T: ZeroablePrimitive + Sync { }impl_nonzero_auto_trait!(unsafe Sync);
167#[stable(feature = "nonzero", since = "1.28.0")]
impl<T> Unpin for NonZero<T> where T: ZeroablePrimitive + Unpin { }impl_nonzero_auto_trait!(Unpin);
168#[stable(feature = "nonzero", since = "1.28.0")]
impl<T> UnwindSafe for NonZero<T> where T: ZeroablePrimitive + UnwindSafe { }impl_nonzero_auto_trait!(UnwindSafe);
169
170#[stable(feature = "nonzero", since = "1.28.0")]
171#[rustc_const_unstable(feature = "const_clone", issue = "142757")]
172const impl<T> Clone for NonZero<T>
173where
174    T: ZeroablePrimitive,
175{
176    #[inline]
177    fn clone(&self) -> Self {
178        *self
179    }
180}
181
182#[unstable(feature = "ergonomic_clones", issue = "132290")]
183impl<T> UseCloned for NonZero<T> where T: ZeroablePrimitive {}
184
185#[stable(feature = "nonzero", since = "1.28.0")]
186impl<T> Copy for NonZero<T> where T: ZeroablePrimitive {}
187
188#[doc(hidden)]
189#[unstable(feature = "trivial_clone", issue = "none")]
190#[rustc_const_unstable(feature = "const_clone", issue = "142757")]
191const unsafe impl<T> TrivialClone for NonZero<T> where T: ZeroablePrimitive {}
192
193#[stable(feature = "nonzero", since = "1.28.0")]
194#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
195const impl<T> PartialEq for NonZero<T>
196where
197    T: ZeroablePrimitive + [const] PartialEq,
198{
199    #[inline]
200    fn eq(&self, other: &Self) -> bool {
201        self.get() == other.get()
202    }
203
204    #[inline]
205    fn ne(&self, other: &Self) -> bool {
206        self.get() != other.get()
207    }
208}
209
210#[unstable(feature = "structural_match", issue = "31434")]
211impl<T> StructuralPartialEq for NonZero<T> where T: ZeroablePrimitive + StructuralPartialEq {}
212
213#[stable(feature = "nonzero", since = "1.28.0")]
214#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
215const impl<T> Eq for NonZero<T> where T: ZeroablePrimitive + [const] Eq {}
216
217#[stable(feature = "nonzero", since = "1.28.0")]
218#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
219const impl<T> PartialOrd for NonZero<T>
220where
221    T: ZeroablePrimitive + [const] PartialOrd,
222{
223    #[inline]
224    fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
225        self.get().partial_cmp(&other.get())
226    }
227
228    #[inline]
229    fn lt(&self, other: &Self) -> bool {
230        self.get() < other.get()
231    }
232
233    #[inline]
234    fn le(&self, other: &Self) -> bool {
235        self.get() <= other.get()
236    }
237
238    #[inline]
239    fn gt(&self, other: &Self) -> bool {
240        self.get() > other.get()
241    }
242
243    #[inline]
244    fn ge(&self, other: &Self) -> bool {
245        self.get() >= other.get()
246    }
247}
248
249#[stable(feature = "nonzero", since = "1.28.0")]
250#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
251const impl<T> Ord for NonZero<T>
252where
253    // FIXME(const_hack): the T: ~const Destruct should be inferred from the Self: ~const Destruct.
254    // See https://github.com/rust-lang/rust/issues/144207
255    T: ZeroablePrimitive + [const] Ord + [const] Destruct,
256{
257    #[inline]
258    fn cmp(&self, other: &Self) -> Ordering {
259        self.get().cmp(&other.get())
260    }
261
262    #[inline]
263    fn max(self, other: Self) -> Self {
264        // SAFETY: The maximum of two non-zero values is still non-zero.
265        unsafe { Self::new_unchecked(self.get().max(other.get())) }
266    }
267
268    #[inline]
269    fn min(self, other: Self) -> Self {
270        // SAFETY: The minimum of two non-zero values is still non-zero.
271        unsafe { Self::new_unchecked(self.get().min(other.get())) }
272    }
273
274    #[inline]
275    fn clamp(self, min: Self, max: Self) -> Self {
276        // SAFETY: A non-zero value clamped between two non-zero values is still non-zero.
277        unsafe { Self::new_unchecked(self.get().clamp(min.get(), max.get())) }
278    }
279}
280
281#[stable(feature = "nonzero", since = "1.28.0")]
282impl<T> Hash for NonZero<T>
283where
284    T: ZeroablePrimitive + Hash,
285{
286    #[inline]
287    fn hash<H>(&self, state: &mut H)
288    where
289        H: Hasher,
290    {
291        self.get().hash(state)
292    }
293}
294
295#[stable(feature = "from_nonzero", since = "1.31.0")]
296#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
297const impl<T> From<NonZero<T>> for T
298where
299    T: ZeroablePrimitive,
300{
301    #[inline]
302    fn from(nonzero: NonZero<T>) -> Self {
303        // Call `get` method to keep range information.
304        nonzero.get()
305    }
306}
307
308#[stable(feature = "more_from_nonzero", since = "1.101.0")]
309impl<'a, T> From<&'a NonZero<T>> for &'a T
310where
311    T: ZeroablePrimitive,
312{
313    #[inline]
314    fn from(nonzero: &'a NonZero<T>) -> &'a T {
315        nonzero.as_ref()
316    }
317}
318
319// FIXME: see library/std/tests/slice-from-array-issue-113238.rs
320/*
321#[stable(feature = "more_from_nonzero", since = "1.101.0")]
322impl<'a, T> From<&'a [NonZero<T>]> for &'a [T]
323where
324    T: ZeroablePrimitive,
325{
326    #[inline]
327    fn from(nonzero: &'a [NonZero<T>]) -> &'a [T] {
328        nonzero.as_zeroable()
329    }
330}
331impl<T> [NonZero<T>]
332where
333    T: ZeroablePrimitive,
334{
335    /// Implementation of `From<&[NonZero<T>]> for &[T]`.
336    #[must_use]
337    #[inline]
338    fn as_zeroable(&self) -> &[T] {
339        // SAFETY: `repr(transparent)` ensures that `NonZero<T>` has same layout as `T`, and thus
340        //   `[NonZero<T>]` has same layout as `[T]`
341        unsafe { &*(slice::from_raw_parts(self.as_ptr().cast::<T>(), self.len())) }
342    }
343}
344*/
345
346#[stable(feature = "more_from_nonzero", since = "1.101.0")]
347impl<T, const N: usize> From<[NonZero<T>; N]> for [T; N]
348where
349    T: ZeroablePrimitive,
350{
351    #[inline]
352    fn from(nonzero: [NonZero<T>; N]) -> [T; N] {
353        nonzero.into_zeroable()
354    }
355}
356
357// FIXME: can't detect that ZeroablePrimitive is a sealed trait
358macro_rules! impl_ref_try_from {
359    ($($t:ty),* $(,)?) => {
360        $(
361            #[stable(feature = "more_from_nonzero", since = "1.101.0")]
362            impl<'a> TryFrom<&'a $t> for &'a NonZero<$t> {
363                type Error = TryFromIntError;
364
365                #[inline]
366                fn try_from(zeroable: &'a $t) -> Result<&'a NonZero<$t>, TryFromIntError> {
367                    NonZero::from_ref(zeroable).ok_or(TryFromIntError(IntErrorKind::Zero))
368                }
369            }
370        )*
371    }
372}
373
374#[stable(feature = "more_from_nonzero", since = "1.101.0")]
impl<'a> TryFrom<&'a u8> for &'a NonZero<u8> {
    type Error = TryFromIntError;
    #[inline]
    fn try_from(zeroable: &'a u8)
        -> Result<&'a NonZero<u8>, TryFromIntError> {
        NonZero::from_ref(zeroable).ok_or(TryFromIntError(IntErrorKind::Zero))
    }
}
#[stable(feature = "more_from_nonzero", since = "1.101.0")]
impl<'a> TryFrom<&'a u16> for &'a NonZero<u16> {
    type Error = TryFromIntError;
    #[inline]
    fn try_from(zeroable: &'a u16)
        -> Result<&'a NonZero<u16>, TryFromIntError> {
        NonZero::from_ref(zeroable).ok_or(TryFromIntError(IntErrorKind::Zero))
    }
}
#[stable(feature = "more_from_nonzero", since = "1.101.0")]
impl<'a> TryFrom<&'a u32> for &'a NonZero<u32> {
    type Error = TryFromIntError;
    #[inline]
    fn try_from(zeroable: &'a u32)
        -> Result<&'a NonZero<u32>, TryFromIntError> {
        NonZero::from_ref(zeroable).ok_or(TryFromIntError(IntErrorKind::Zero))
    }
}
#[stable(feature = "more_from_nonzero", since = "1.101.0")]
impl<'a> TryFrom<&'a u64> for &'a NonZero<u64> {
    type Error = TryFromIntError;
    #[inline]
    fn try_from(zeroable: &'a u64)
        -> Result<&'a NonZero<u64>, TryFromIntError> {
        NonZero::from_ref(zeroable).ok_or(TryFromIntError(IntErrorKind::Zero))
    }
}
#[stable(feature = "more_from_nonzero", since = "1.101.0")]
impl<'a> TryFrom<&'a u128> for &'a NonZero<u128> {
    type Error = TryFromIntError;
    #[inline]
    fn try_from(zeroable: &'a u128)
        -> Result<&'a NonZero<u128>, TryFromIntError> {
        NonZero::from_ref(zeroable).ok_or(TryFromIntError(IntErrorKind::Zero))
    }
}
#[stable(feature = "more_from_nonzero", since = "1.101.0")]
impl<'a> TryFrom<&'a usize> for &'a NonZero<usize> {
    type Error = TryFromIntError;
    #[inline]
    fn try_from(zeroable: &'a usize)
        -> Result<&'a NonZero<usize>, TryFromIntError> {
        NonZero::from_ref(zeroable).ok_or(TryFromIntError(IntErrorKind::Zero))
    }
}
#[stable(feature = "more_from_nonzero", since = "1.101.0")]
impl<'a> TryFrom<&'a i8> for &'a NonZero<i8> {
    type Error = TryFromIntError;
    #[inline]
    fn try_from(zeroable: &'a i8)
        -> Result<&'a NonZero<i8>, TryFromIntError> {
        NonZero::from_ref(zeroable).ok_or(TryFromIntError(IntErrorKind::Zero))
    }
}
#[stable(feature = "more_from_nonzero", since = "1.101.0")]
impl<'a> TryFrom<&'a i16> for &'a NonZero<i16> {
    type Error = TryFromIntError;
    #[inline]
    fn try_from(zeroable: &'a i16)
        -> Result<&'a NonZero<i16>, TryFromIntError> {
        NonZero::from_ref(zeroable).ok_or(TryFromIntError(IntErrorKind::Zero))
    }
}
#[stable(feature = "more_from_nonzero", since = "1.101.0")]
impl<'a> TryFrom<&'a i32> for &'a NonZero<i32> {
    type Error = TryFromIntError;
    #[inline]
    fn try_from(zeroable: &'a i32)
        -> Result<&'a NonZero<i32>, TryFromIntError> {
        NonZero::from_ref(zeroable).ok_or(TryFromIntError(IntErrorKind::Zero))
    }
}
#[stable(feature = "more_from_nonzero", since = "1.101.0")]
impl<'a> TryFrom<&'a i64> for &'a NonZero<i64> {
    type Error = TryFromIntError;
    #[inline]
    fn try_from(zeroable: &'a i64)
        -> Result<&'a NonZero<i64>, TryFromIntError> {
        NonZero::from_ref(zeroable).ok_or(TryFromIntError(IntErrorKind::Zero))
    }
}
#[stable(feature = "more_from_nonzero", since = "1.101.0")]
impl<'a> TryFrom<&'a i128> for &'a NonZero<i128> {
    type Error = TryFromIntError;
    #[inline]
    fn try_from(zeroable: &'a i128)
        -> Result<&'a NonZero<i128>, TryFromIntError> {
        NonZero::from_ref(zeroable).ok_or(TryFromIntError(IntErrorKind::Zero))
    }
}
#[stable(feature = "more_from_nonzero", since = "1.101.0")]
impl<'a> TryFrom<&'a isize> for &'a NonZero<isize> {
    type Error = TryFromIntError;
    #[inline]
    fn try_from(zeroable: &'a isize)
        -> Result<&'a NonZero<isize>, TryFromIntError> {
        NonZero::from_ref(zeroable).ok_or(TryFromIntError(IntErrorKind::Zero))
    }
}
#[stable(feature = "more_from_nonzero", since = "1.101.0")]
impl<'a> TryFrom<&'a char> for &'a NonZero<char> {
    type Error = TryFromIntError;
    #[inline]
    fn try_from(zeroable: &'a char)
        -> Result<&'a NonZero<char>, TryFromIntError> {
        NonZero::from_ref(zeroable).ok_or(TryFromIntError(IntErrorKind::Zero))
    }
}impl_ref_try_from! {
375    u8,
376    u16,
377    u32,
378    u64,
379    u128,
380    usize,
381    i8,
382    i16,
383    i32,
384    i64,
385    i128,
386    isize,
387    char,
388}
389
390#[stable(feature = "more_from_nonzero", since = "1.101.0")]
391impl<'a, T> TryFrom<&'a [T]> for &'a [NonZero<T>]
392where
393    T: ZeroablePrimitive,
394{
395    type Error = TryFromIntError;
396
397    #[inline]
398    fn try_from(zeroable: &'a [T]) -> Result<&'a [NonZero<T>], TryFromIntError> {
399        NonZero::from_slice(zeroable).ok_or(TryFromIntError(IntErrorKind::Zero))
400    }
401}
402
403#[stable(feature = "more_from_nonzero", since = "1.101.0")]
404impl<T, const N: usize> TryFrom<[T; N]> for [NonZero<T>; N]
405where
406    T: ZeroablePrimitive,
407{
408    type Error = TryFromIntError;
409
410    #[inline]
411    fn try_from(zeroable: [T; N]) -> Result<[NonZero<T>; N], TryFromIntError> {
412        NonZero::from_array(zeroable).ok_or(TryFromIntError(IntErrorKind::Zero))
413    }
414}
415
416#[stable(feature = "nonzero_bitor", since = "1.45.0")]
417#[rustc_const_unstable(feature = "const_ops", issue = "143802")]
418const impl<T> BitOr for NonZero<T>
419where
420    T: ZeroablePrimitive + [const] BitOr<Output = T>,
421{
422    type Output = Self;
423
424    #[inline]
425    fn bitor(self, rhs: Self) -> Self::Output {
426        // SAFETY: Bitwise OR of two non-zero values is still non-zero.
427        unsafe { Self::new_unchecked(self.get() | rhs.get()) }
428    }
429}
430
431#[stable(feature = "nonzero_bitor", since = "1.45.0")]
432#[rustc_const_unstable(feature = "const_ops", issue = "143802")]
433const impl<T> BitOr<T> for NonZero<T>
434where
435    T: ZeroablePrimitive + [const] BitOr<Output = T>,
436{
437    type Output = Self;
438
439    #[inline]
440    fn bitor(self, rhs: T) -> Self::Output {
441        // SAFETY: Bitwise OR of a non-zero value with anything is still non-zero.
442        unsafe { Self::new_unchecked(self.get() | rhs) }
443    }
444}
445
446#[stable(feature = "nonzero_bitor", since = "1.45.0")]
447#[rustc_const_unstable(feature = "const_ops", issue = "143802")]
448const impl<T> BitOr<NonZero<T>> for T
449where
450    T: ZeroablePrimitive + [const] BitOr<Output = T>,
451{
452    type Output = NonZero<T>;
453
454    #[inline]
455    fn bitor(self, rhs: NonZero<T>) -> Self::Output {
456        // SAFETY: Bitwise OR of anything with a non-zero value is still non-zero.
457        unsafe { NonZero::new_unchecked(self | rhs.get()) }
458    }
459}
460
461#[stable(feature = "nonzero_bitor", since = "1.45.0")]
462#[rustc_const_unstable(feature = "const_ops", issue = "143802")]
463const impl<T> BitOrAssign for NonZero<T>
464where
465    T: ZeroablePrimitive,
466    Self: [const] BitOr<Output = Self>,
467{
468    #[inline]
469    fn bitor_assign(&mut self, rhs: Self) {
470        *self = *self | rhs;
471    }
472}
473
474#[stable(feature = "nonzero_bitor", since = "1.45.0")]
475#[rustc_const_unstable(feature = "const_ops", issue = "143802")]
476const impl<T> BitOrAssign<T> for NonZero<T>
477where
478    T: ZeroablePrimitive,
479    Self: [const] BitOr<T, Output = Self>,
480{
481    #[inline]
482    fn bitor_assign(&mut self, rhs: T) {
483        *self = *self | rhs;
484    }
485}
486
487impl<T> NonZero<T>
488where
489    T: ZeroablePrimitive,
490{
491    /// Creates a non-zero if the given value is not zero.
492    #[stable(feature = "nonzero", since = "1.28.0")]
493    #[rustc_const_stable(feature = "const_nonzero_int_methods", since = "1.47.0")]
494    #[must_use]
495    #[inline]
496    pub const fn new(n: T) -> Option<Self> {
497        // SAFETY: Memory layout optimization guarantees that `Option<NonZero<T>>` has
498        //         the same layout and size as `T`, with `0` representing `None`.
499        unsafe { intrinsics::transmute_unchecked(n) }
500    }
501
502    /// Creates a non-zero without checking whether the value is non-zero.
503    /// This results in undefined behavior if the value is zero.
504    ///
505    /// # Safety
506    ///
507    /// The value must not be zero.
508    #[stable(feature = "nonzero", since = "1.28.0")]
509    #[rustc_const_stable(feature = "nonzero", since = "1.28.0")]
510    #[must_use]
511    #[inline]
512    #[track_caller]
513    pub const unsafe fn new_unchecked(n: T) -> Self {
514        match Self::new(n) {
515            Some(n) => n,
516            None => {
517                // SAFETY: The caller guarantees that `n` is non-zero, so this is unreachable.
518                unsafe {
519                    {
    #[rustc_no_mir_inline]
    #[inline]
    #[rustc_nounwind]
    #[track_caller]
    const fn precondition_check() {
        if !false {
            let msg =
                "unsafe precondition(s) violated: NonZero::new_unchecked requires the argument to be non-zero\n\nThis indicates a bug in the program. This Undefined Behavior check is optional, and cannot be relied on for safety.";
            ::core::panicking::panic_nounwind_fmt(::core::fmt::Arguments::from_str(msg),
                false);
        }
    }
    if ::core::ub_checks::check_language_ub() { precondition_check(); }
};ub_checks::assert_unsafe_precondition!(
520                        check_language_ub,
521                        "NonZero::new_unchecked requires the argument to be non-zero",
522                        () => false,
523                    );
524                    intrinsics::unreachable()
525                }
526            }
527        }
528    }
529
530    /// Converts a reference to a non-zero mutable reference
531    /// if the referenced value is not zero.
532    #[unstable(feature = "nonzero_from_mut", issue = "106290")]
533    #[must_use]
534    #[inline]
535    pub fn from_mut(n: &mut T) -> Option<&mut Self> {
536        // SAFETY: Memory layout optimization guarantees that `Option<NonZero<T>>` has
537        //         the same layout and size as `T`, with `0` representing `None`.
538        let opt_n = unsafe { &mut *(ptr::from_mut(n).cast::<Option<Self>>()) };
539
540        opt_n.as_mut()
541    }
542
543    /// Converts a mutable reference to a non-zero mutable reference
544    /// without checking whether the referenced value is non-zero.
545    /// This results in undefined behavior if the referenced value is zero.
546    ///
547    /// # Safety
548    ///
549    /// The referenced value must not be zero.
550    #[unstable(feature = "nonzero_from_mut", issue = "106290")]
551    #[must_use]
552    #[inline]
553    #[track_caller]
554    pub unsafe fn from_mut_unchecked(n: &mut T) -> &mut Self {
555        match Self::from_mut(n) {
556            Some(n) => n,
557            None => {
558                // SAFETY: The caller guarantees that `n` references a value that is non-zero, so this is unreachable.
559                unsafe {
560                    {
    #[rustc_no_mir_inline]
    #[inline]
    #[rustc_nounwind]
    #[track_caller]
    const fn precondition_check() {
        if !false {
            let msg =
                "unsafe precondition(s) violated: NonZero::from_mut_unchecked requires the argument to dereference as non-zero\n\nThis indicates a bug in the program. This Undefined Behavior check is optional, and cannot be relied on for safety.";
            ::core::panicking::panic_nounwind_fmt(::core::fmt::Arguments::from_str(msg),
                false);
        }
    }
    if ::core::ub_checks::check_library_ub() { precondition_check(); }
};ub_checks::assert_unsafe_precondition!(
561                        check_library_ub,
562                        "NonZero::from_mut_unchecked requires the argument to dereference as non-zero",
563                        () => false,
564                    );
565                    intrinsics::unreachable()
566                }
567            }
568        }
569    }
570
571    /// Implementation of `From<&NonZero<T>> for &T`.
572    #[must_use]
573    #[inline]
574    fn as_ref(&self) -> &T {
575        // SAFETY: `repr(transparent)` ensures that `NonZero<T>` has same layout as `T`
576        unsafe { &*(ptr::from_ref(self).cast::<T>()) }
577    }
578
579    /// Implementation of `TryFrom<&T> for &NonZero<T>`.
580    #[must_use]
581    #[inline]
582    fn from_ref(n: &T) -> Option<&Self> {
583        // SAFETY: Memory layout optimization guarantees that `Option<NonZero<T>>` has
584        //         the same layout and size as `T`, with `0` representing `None`.
585        let opt_n = unsafe { &*(ptr::from_ref(n).cast::<Option<Self>>()) };
586
587        opt_n.as_ref()
588    }
589
590    /// Implementation of `TryFrom<&[T]> for &[NonZero<T>]`.
591    #[must_use]
592    #[inline]
593    fn from_slice(n: &[T]) -> Option<&[Self]> {
594        if n.iter().all(|x| NonZero::new(*x).is_some()) {
595            // SAFETY: We explicitly checked that all elements are nonzero, and because of `repr(transparent)`
596            //   the layout remains unchanged
597            Some(unsafe { slice::from_raw_parts(n.as_ptr().cast::<NonZero<T>>(), n.len()) })
598        } else {
599            None
600        }
601    }
602
603    /// Implementation of `TryFrom<[T; N]> for [NonZero<T>; N]`.
604    #[must_use]
605    #[inline]
606    fn from_array<const N: usize>(n: [T; N]) -> Option<[Self; N]> {
607        n.try_map(NonZero::new)
608    }
609
610    /// Returns the contained value as a primitive type.
611    #[stable(feature = "nonzero", since = "1.28.0")]
612    #[rustc_const_stable(feature = "const_nonzero_get", since = "1.34.0")]
613    #[inline]
614    pub const fn get(self) -> T {
615        // Rustc can set range metadata only if it loads `self` from
616        // memory somewhere. If the value of `self` was from by-value argument
617        // of some not-inlined function, LLVM don't have range metadata
618        // to understand that the value cannot be zero.
619        //
620        // Using the transmute `assume`s the range at runtime.
621        //
622        // Even once LLVM supports `!range` metadata for function arguments
623        // (see <https://github.com/llvm/llvm-project/issues/76628>), this can't
624        // be `.0` because MCP#807 bans field-projecting into `scalar_valid_range`
625        // types, and it arguably wouldn't want to be anyway because if this is
626        // MIR-inlined, there's no opportunity to put that argument metadata anywhere.
627        //
628        // The good answer here will eventually be pattern types, which will hopefully
629        // allow it to go back to `.0`, maybe with a cast of some sort.
630        //
631        // SAFETY: `ZeroablePrimitive` guarantees that the size and bit validity
632        // of `.0` is such that this transmute is sound.
633        unsafe { intrinsics::transmute_unchecked(self) }
634    }
635}
636
637impl<T, const N: usize> [NonZero<T>; N]
638where
639    T: ZeroablePrimitive,
640{
641    /// Implementation of `From<[NonZero<T>; N]> for [T; N]`.
642    #[must_use]
643    #[inline]
644    fn into_zeroable(self) -> [T; N] {
645        self.map(NonZero::get)
646    }
647}
648
649macro_rules! nonzero_integer {
650    (
651        #[$stability:meta]
652        Self = $Ty:ident,
653        Primitive = $signedness:ident $Int:ident,
654        SignedPrimitive = $Sint:ty,
655        UnsignedPrimitive = $Uint:ty,
656
657        // Used in doc comments.
658        rot = $rot:literal,
659        rot_op = $rot_op:literal,
660        rot_result = $rot_result:literal,
661        swap_op = $swap_op:literal,
662        swapped = $swapped:literal,
663        reversed = $reversed:literal,
664        leading_zeros_test = $leading_zeros_test:expr,
665    ) => {
666        #[doc = sign_dependent_expr!{
667            $signedness ?
668            if signed {
669                concat!("An [`", stringify!($Int), "`] that is known not to equal zero.")
670            }
671            if unsigned {
672                concat!("A [`", stringify!($Int), "`] that is known not to equal zero.")
673            }
674        }]
675        ///
676        /// This enables some memory layout optimization.
677        #[doc = concat!("For example, `Option<", stringify!($Ty), ">` is the same size as `", stringify!($Int), "`:")]
678        ///
679        /// ```rust
680        #[doc = concat!("assert_eq!(size_of::<Option<core::num::", stringify!($Ty), ">>(), size_of::<", stringify!($Int), ">());")]
681        /// ```
682        ///
683        /// # Layout
684        ///
685        #[doc = concat!("`", stringify!($Ty), "` is guaranteed to have the same layout and bit validity as `", stringify!($Int), "`")]
686        /// with the exception that `0` is not a valid instance.
687        #[doc = concat!("`Option<", stringify!($Ty), ">` is guaranteed to be ABI-compatible with `", stringify!($Int), "`,")]
688        /// including in FFI.
689        ///
690        /// Thanks to the [null pointer optimization],
691        #[doc = concat!("`", stringify!($Ty), "` and `Option<", stringify!($Ty), ">`")]
692        /// are guaranteed to have the same size and alignment:
693        ///
694        /// ```
695        #[doc = concat!("use std::num::", stringify!($Ty), ";")]
696        ///
697        #[doc = concat!("assert_eq!(size_of::<", stringify!($Ty), ">(), size_of::<Option<", stringify!($Ty), ">>());")]
698        #[doc = concat!("assert_eq!(align_of::<", stringify!($Ty), ">(), align_of::<Option<", stringify!($Ty), ">>());")]
699        /// ```
700        ///
701        /// # Compile-time creation
702        ///
703        /// Since both [`Option::unwrap()`] and [`Option::expect()`] are `const`, it is possible to
704        /// define a new
705        #[doc = concat!("`", stringify!($Ty), "`")]
706        /// at compile time via:
707        /// ```
708        #[doc = concat!("use std::num::", stringify!($Ty), ";")]
709        ///
710        #[doc = concat!("const TEN: ", stringify!($Ty), " = ", stringify!($Ty) , r#"::new(10).expect("ten is non-zero");"#)]
711        /// ```
712        ///
713        /// [null pointer optimization]: crate::option#representation
714        #[$stability]
715        pub type $Ty = NonZero<$Int>;
716
717        impl NonZero<$Int> {
718            /// The size of this non-zero integer type in bits.
719            ///
720            #[doc = concat!("This value is equal to [`", stringify!($Int), "::BITS`].")]
721            ///
722            /// # Examples
723            ///
724            /// ```
725            /// # use std::num::NonZero;
726            /// #
727            #[doc = concat!("assert_eq!(NonZero::<", stringify!($Int), ">::BITS, ", stringify!($Int), "::BITS);")]
728            /// ```
729            #[stable(feature = "nonzero_bits", since = "1.67.0")]
730            pub const BITS: u32 = <$Int>::BITS;
731
732            /// Returns the number of leading zeros in the binary representation of `self`.
733            ///
734            /// On many architectures, this function can perform better than `leading_zeros()` on the underlying integer type, as special handling of zero can be avoided.
735            ///
736            /// # Examples
737            ///
738            /// ```
739            /// # use std::num::NonZero;
740            /// #
741            /// # fn main() { test().unwrap(); }
742            /// # fn test() -> Option<()> {
743            #[doc = concat!("let n = NonZero::<", stringify!($Int), ">::new(", $leading_zeros_test, ")?;")]
744            ///
745            /// assert_eq!(n.leading_zeros(), 0);
746            /// # Some(())
747            /// # }
748            /// ```
749            #[stable(feature = "nonzero_leading_trailing_zeros", since = "1.53.0")]
750            #[rustc_const_stable(feature = "nonzero_leading_trailing_zeros", since = "1.53.0")]
751            #[must_use = "this returns the result of the operation, \
752                          without modifying the original"]
753            #[inline]
754            pub const fn leading_zeros(self) -> u32 {
755                // SAFETY: since `self` cannot be zero, it is safe to call `ctlz_nonzero`.
756                unsafe {
757                    intrinsics::ctlz_nonzero(self.get() as $Uint)
758                }
759            }
760
761            /// Returns the number of trailing zeros in the binary representation
762            /// of `self`.
763            ///
764            /// On many architectures, this function can perform better than `trailing_zeros()` on the underlying integer type, as special handling of zero can be avoided.
765            ///
766            /// # Examples
767            ///
768            /// ```
769            /// # use std::num::NonZero;
770            /// #
771            /// # fn main() { test().unwrap(); }
772            /// # fn test() -> Option<()> {
773            #[doc = concat!("let n = NonZero::<", stringify!($Int), ">::new(0b0101000)?;")]
774            ///
775            /// assert_eq!(n.trailing_zeros(), 3);
776            /// # Some(())
777            /// # }
778            /// ```
779            #[stable(feature = "nonzero_leading_trailing_zeros", since = "1.53.0")]
780            #[rustc_const_stable(feature = "nonzero_leading_trailing_zeros", since = "1.53.0")]
781            #[must_use = "this returns the result of the operation, \
782                          without modifying the original"]
783            #[inline]
784            pub const fn trailing_zeros(self) -> u32 {
785                // SAFETY: since `self` cannot be zero, it is safe to call `cttz_nonzero`.
786                unsafe {
787                    intrinsics::cttz_nonzero(self.get() as $Uint)
788                }
789            }
790
791            /// Returns `self` with only the most significant bit set.
792            ///
793            /// # Example
794            ///
795            /// ```
796            /// # use core::num::NonZero;
797            /// # fn main() { test().unwrap(); }
798            /// # fn test() -> Option<()> {
799            #[doc = concat!("let a = NonZero::<", stringify!($Int), ">::new(0b_01100100)?;")]
800            #[doc = concat!("let b = NonZero::<", stringify!($Int), ">::new(0b_01000000)?;")]
801            ///
802            /// assert_eq!(a.isolate_highest_one(), b);
803            /// # Some(())
804            /// # }
805            /// ```
806            #[stable(feature = "isolate_most_least_significant_one", since = "1.97.0")]
807            #[rustc_const_stable(feature = "isolate_most_least_significant_one", since = "1.97.0")]
808            #[must_use = "this returns the result of the operation, \
809                        without modifying the original"]
810            #[inline(always)]
811            pub const fn isolate_highest_one(self) -> Self {
812                // SAFETY:
813                // `self` is non-zero, so masking to preserve only the most
814                // significant set bit will result in a non-zero `n`.
815                // and self.leading_zeros() is always < $INT::BITS since
816                // at least one of the bits in the number is not zero
817                unsafe {
818                    let bit = (((1 as $Uint) << (<$Uint>::BITS - 1)).unchecked_shr(self.leading_zeros()));
819                    NonZero::new_unchecked(bit as $Int)
820                }
821            }
822
823            /// Returns `self` with only the least significant bit set.
824            ///
825            /// # Example
826            ///
827            /// ```
828            /// # use core::num::NonZero;
829            /// # fn main() { test().unwrap(); }
830            /// # fn test() -> Option<()> {
831            #[doc = concat!("let a = NonZero::<", stringify!($Int), ">::new(0b_01100100)?;")]
832            #[doc = concat!("let b = NonZero::<", stringify!($Int), ">::new(0b_00000100)?;")]
833            ///
834            /// assert_eq!(a.isolate_lowest_one(), b);
835            /// # Some(())
836            /// # }
837            /// ```
838            #[stable(feature = "isolate_most_least_significant_one", since = "1.97.0")]
839            #[rustc_const_stable(feature = "isolate_most_least_significant_one", since = "1.97.0")]
840            #[must_use = "this returns the result of the operation, \
841                        without modifying the original"]
842            #[inline(always)]
843            pub const fn isolate_lowest_one(self) -> Self {
844                let n = self.get();
845                let n = n & n.wrapping_neg();
846
847                // SAFETY: `self` is non-zero, so `self` with only its least
848                // significant set bit will remain non-zero.
849                unsafe { NonZero::new_unchecked(n) }
850            }
851
852            /// Returns the index of the highest bit set to one in `self`.
853            ///
854            #[doc = sign_dependent_expr!{
855                $signedness ?
856                if signed {
857                    ""
858                }
859                if unsigned {
860                    "Note that this is equivalent to [`ilog2`](Self::ilog2)."
861                }
862            }]
863            ///
864            /// # Examples
865            ///
866            /// ```
867            /// # use core::num::NonZero;
868            /// # fn main() { test().unwrap(); }
869            /// # fn test() -> Option<()> {
870            #[doc = concat!("assert_eq!(NonZero::<", stringify!($Int), ">::new(0b1)?.highest_one(), 0);")]
871            #[doc = concat!("assert_eq!(NonZero::<", stringify!($Int), ">::new(0b1_0000)?.highest_one(), 4);")]
872            #[doc = concat!("assert_eq!(NonZero::<", stringify!($Int), ">::new(0b1_1111)?.highest_one(), 4);")]
873            /// # Some(())
874            /// # }
875            /// ```
876            #[stable(feature = "int_lowest_highest_one", since = "1.97.0")]
877            #[rustc_const_stable(feature = "int_lowest_highest_one", since = "1.97.0")]
878            #[must_use = "this returns the result of the operation, \
879                          without modifying the original"]
880            #[inline(always)]
881            pub const fn highest_one(self) -> u32 {
882                Self::BITS - 1 - self.leading_zeros()
883            }
884
885            /// Returns the index of the lowest bit set to one in `self`.
886            ///
887            /// # Examples
888            ///
889            /// ```
890            /// # use core::num::NonZero;
891            /// # fn main() { test().unwrap(); }
892            /// # fn test() -> Option<()> {
893            #[doc = concat!("assert_eq!(NonZero::<", stringify!($Int), ">::new(0b1)?.lowest_one(), 0);")]
894            #[doc = concat!("assert_eq!(NonZero::<", stringify!($Int), ">::new(0b1_0000)?.lowest_one(), 4);")]
895            #[doc = concat!("assert_eq!(NonZero::<", stringify!($Int), ">::new(0b1_1111)?.lowest_one(), 0);")]
896            /// # Some(())
897            /// # }
898            /// ```
899            #[stable(feature = "int_lowest_highest_one", since = "1.97.0")]
900            #[rustc_const_stable(feature = "int_lowest_highest_one", since = "1.97.0")]
901            #[must_use = "this returns the result of the operation, \
902                          without modifying the original"]
903            #[inline(always)]
904            pub const fn lowest_one(self) -> u32 {
905                self.trailing_zeros()
906            }
907
908            /// Returns the number of ones in the binary representation of `self`.
909            ///
910            /// # Examples
911            ///
912            /// ```
913            /// # use std::num::NonZero;
914            /// #
915            /// # fn main() { test().unwrap(); }
916            /// # fn test() -> Option<()> {
917            #[doc = concat!("let a = NonZero::<", stringify!($Int), ">::new(0b100_0000)?;")]
918            #[doc = concat!("let b = NonZero::<", stringify!($Int), ">::new(0b100_0011)?;")]
919            ///
920            /// assert_eq!(a.count_ones(), NonZero::new(1)?);
921            /// assert_eq!(b.count_ones(), NonZero::new(3)?);
922            /// # Some(())
923            /// # }
924            /// ```
925            ///
926            #[stable(feature = "non_zero_count_ones", since = "1.86.0")]
927            #[rustc_const_stable(feature = "non_zero_count_ones", since = "1.86.0")]
928            #[doc(alias = "popcount")]
929            #[doc(alias = "popcnt")]
930            #[must_use = "this returns the result of the operation, \
931                        without modifying the original"]
932            #[inline(always)]
933            pub const fn count_ones(self) -> NonZero<u32> {
934                // SAFETY:
935                // `self` is non-zero, which means it has at least one bit set, which means
936                // that the result of `count_ones` is non-zero.
937                unsafe { NonZero::new_unchecked(self.get().count_ones()) }
938            }
939
940            /// Shifts the bits to the left by a specified amount, `n`,
941            /// wrapping the truncated bits to the end of the resulting integer.
942            ///
943            /// Please note this isn't the same operation as the `<<` shifting operator!
944            ///
945            /// # Examples
946            ///
947            /// ```
948            /// #![feature(nonzero_bitwise)]
949            /// # use std::num::NonZero;
950            /// #
951            /// # fn main() { test().unwrap(); }
952            /// # fn test() -> Option<()> {
953            #[doc = concat!("let n = NonZero::new(", $rot_op, stringify!($Int), ")?;")]
954            #[doc = concat!("let m = NonZero::new(", $rot_result, ")?;")]
955            ///
956            #[doc = concat!("assert_eq!(n.rotate_left(", $rot, "), m);")]
957            /// # Some(())
958            /// # }
959            /// ```
960            #[unstable(feature = "nonzero_bitwise", issue = "128281")]
961            #[must_use = "this returns the result of the operation, \
962                        without modifying the original"]
963            #[inline(always)]
964            pub const fn rotate_left(self, n: u32) -> Self {
965                let result = self.get().rotate_left(n);
966                // SAFETY: Rotating bits preserves the property int > 0.
967                unsafe { Self::new_unchecked(result) }
968            }
969
970            /// Shifts the bits to the right by a specified amount, `n`,
971            /// wrapping the truncated bits to the beginning of the resulting
972            /// integer.
973            ///
974            /// Please note this isn't the same operation as the `>>` shifting operator!
975            ///
976            /// # Examples
977            ///
978            /// ```
979            /// #![feature(nonzero_bitwise)]
980            /// # use std::num::NonZero;
981            /// #
982            /// # fn main() { test().unwrap(); }
983            /// # fn test() -> Option<()> {
984            #[doc = concat!("let n = NonZero::new(", $rot_result, stringify!($Int), ")?;")]
985            #[doc = concat!("let m = NonZero::new(", $rot_op, ")?;")]
986            ///
987            #[doc = concat!("assert_eq!(n.rotate_right(", $rot, "), m);")]
988            /// # Some(())
989            /// # }
990            /// ```
991            #[unstable(feature = "nonzero_bitwise", issue = "128281")]
992            #[must_use = "this returns the result of the operation, \
993                        without modifying the original"]
994            #[inline(always)]
995            pub const fn rotate_right(self, n: u32) -> Self {
996                let result = self.get().rotate_right(n);
997                // SAFETY: Rotating bits preserves the property int > 0.
998                unsafe { Self::new_unchecked(result) }
999            }
1000
1001            /// Reverses the byte order of the integer.
1002            ///
1003            /// # Examples
1004            ///
1005            /// ```
1006            /// #![feature(nonzero_bitwise)]
1007            /// # use std::num::NonZero;
1008            /// #
1009            /// # fn main() { test().unwrap(); }
1010            /// # fn test() -> Option<()> {
1011            #[doc = concat!("let n = NonZero::new(", $swap_op, stringify!($Int), ")?;")]
1012            /// let m = n.swap_bytes();
1013            ///
1014            #[doc = concat!("assert_eq!(m, NonZero::new(", $swapped, ")?);")]
1015            /// # Some(())
1016            /// # }
1017            /// ```
1018            #[unstable(feature = "nonzero_bitwise", issue = "128281")]
1019            #[must_use = "this returns the result of the operation, \
1020                        without modifying the original"]
1021            #[inline(always)]
1022            pub const fn swap_bytes(self) -> Self {
1023                let result = self.get().swap_bytes();
1024                // SAFETY: Shuffling bytes preserves the property int > 0.
1025                unsafe { Self::new_unchecked(result) }
1026            }
1027
1028            /// Reverses the order of bits in the integer. The least significant bit becomes the most significant bit,
1029            /// second least-significant bit becomes second most-significant bit, etc.
1030            ///
1031            /// # Examples
1032            ///
1033            /// ```
1034            /// #![feature(nonzero_bitwise)]
1035            /// # use std::num::NonZero;
1036            /// #
1037            /// # fn main() { test().unwrap(); }
1038            /// # fn test() -> Option<()> {
1039            #[doc = concat!("let n = NonZero::new(", $swap_op, stringify!($Int), ")?;")]
1040            /// let m = n.reverse_bits();
1041            ///
1042            #[doc = concat!("assert_eq!(m, NonZero::new(", $reversed, ")?);")]
1043            /// # Some(())
1044            /// # }
1045            /// ```
1046            #[unstable(feature = "nonzero_bitwise", issue = "128281")]
1047            #[must_use = "this returns the result of the operation, \
1048                        without modifying the original"]
1049            #[inline(always)]
1050            pub const fn reverse_bits(self) -> Self {
1051                let result = self.get().reverse_bits();
1052                // SAFETY: Reversing bits preserves the property int > 0.
1053                unsafe { Self::new_unchecked(result) }
1054            }
1055
1056            /// Converts an integer from big endian to the target's endianness.
1057            ///
1058            /// On big endian this is a no-op. On little endian the bytes are
1059            /// swapped.
1060            ///
1061            /// # Examples
1062            ///
1063            /// ```
1064            /// #![feature(nonzero_bitwise)]
1065            /// # use std::num::NonZero;
1066            #[doc = concat!("use std::num::", stringify!($Ty), ";")]
1067            /// #
1068            /// # fn main() { test().unwrap(); }
1069            /// # fn test() -> Option<()> {
1070            #[doc = concat!("let n = NonZero::new(0x1A", stringify!($Int), ")?;")]
1071            ///
1072            /// if cfg!(target_endian = "big") {
1073            #[doc = concat!("    assert_eq!(", stringify!($Ty), "::from_be(n), n)")]
1074            /// } else {
1075            #[doc = concat!("    assert_eq!(", stringify!($Ty), "::from_be(n), n.swap_bytes())")]
1076            /// }
1077            /// # Some(())
1078            /// # }
1079            /// ```
1080            #[unstable(feature = "nonzero_bitwise", issue = "128281")]
1081            #[must_use]
1082            #[inline(always)]
1083            pub const fn from_be(x: Self) -> Self {
1084                let result = $Int::from_be(x.get());
1085                // SAFETY: Shuffling bytes preserves the property int > 0.
1086                unsafe { Self::new_unchecked(result) }
1087            }
1088
1089            /// Converts an integer from little endian to the target's endianness.
1090            ///
1091            /// On little endian this is a no-op. On big endian the bytes are
1092            /// swapped.
1093            ///
1094            /// # Examples
1095            ///
1096            /// ```
1097            /// #![feature(nonzero_bitwise)]
1098            /// # use std::num::NonZero;
1099            #[doc = concat!("use std::num::", stringify!($Ty), ";")]
1100            /// #
1101            /// # fn main() { test().unwrap(); }
1102            /// # fn test() -> Option<()> {
1103            #[doc = concat!("let n = NonZero::new(0x1A", stringify!($Int), ")?;")]
1104            ///
1105            /// if cfg!(target_endian = "little") {
1106            #[doc = concat!("    assert_eq!(", stringify!($Ty), "::from_le(n), n)")]
1107            /// } else {
1108            #[doc = concat!("    assert_eq!(", stringify!($Ty), "::from_le(n), n.swap_bytes())")]
1109            /// }
1110            /// # Some(())
1111            /// # }
1112            /// ```
1113            #[unstable(feature = "nonzero_bitwise", issue = "128281")]
1114            #[must_use]
1115            #[inline(always)]
1116            pub const fn from_le(x: Self) -> Self {
1117                let result = $Int::from_le(x.get());
1118                // SAFETY: Shuffling bytes preserves the property int > 0.
1119                unsafe { Self::new_unchecked(result) }
1120            }
1121
1122            /// Converts `self` to big endian from the target's endianness.
1123            ///
1124            /// On big endian this is a no-op. On little endian the bytes are
1125            /// swapped.
1126            ///
1127            /// # Examples
1128            ///
1129            /// ```
1130            /// #![feature(nonzero_bitwise)]
1131            /// # use std::num::NonZero;
1132            /// #
1133            /// # fn main() { test().unwrap(); }
1134            /// # fn test() -> Option<()> {
1135            #[doc = concat!("let n = NonZero::new(0x1A", stringify!($Int), ")?;")]
1136            ///
1137            /// if cfg!(target_endian = "big") {
1138            ///     assert_eq!(n.to_be(), n)
1139            /// } else {
1140            ///     assert_eq!(n.to_be(), n.swap_bytes())
1141            /// }
1142            /// # Some(())
1143            /// # }
1144            /// ```
1145            #[unstable(feature = "nonzero_bitwise", issue = "128281")]
1146            #[must_use = "this returns the result of the operation, \
1147                        without modifying the original"]
1148            #[inline(always)]
1149            pub const fn to_be(self) -> Self {
1150                let result = self.get().to_be();
1151                // SAFETY: Shuffling bytes preserves the property int > 0.
1152                unsafe { Self::new_unchecked(result) }
1153            }
1154
1155            /// Converts `self` to little endian from the target's endianness.
1156            ///
1157            /// On little endian this is a no-op. On big endian the bytes are
1158            /// swapped.
1159            ///
1160            /// # Examples
1161            ///
1162            /// ```
1163            /// #![feature(nonzero_bitwise)]
1164            /// # use std::num::NonZero;
1165            /// #
1166            /// # fn main() { test().unwrap(); }
1167            /// # fn test() -> Option<()> {
1168            #[doc = concat!("let n = NonZero::new(0x1A", stringify!($Int), ")?;")]
1169            ///
1170            /// if cfg!(target_endian = "little") {
1171            ///     assert_eq!(n.to_le(), n)
1172            /// } else {
1173            ///     assert_eq!(n.to_le(), n.swap_bytes())
1174            /// }
1175            /// # Some(())
1176            /// # }
1177            /// ```
1178            #[unstable(feature = "nonzero_bitwise", issue = "128281")]
1179            #[must_use = "this returns the result of the operation, \
1180                        without modifying the original"]
1181            #[inline(always)]
1182            pub const fn to_le(self) -> Self {
1183                let result = self.get().to_le();
1184                // SAFETY: Shuffling bytes preserves the property int > 0.
1185                unsafe { Self::new_unchecked(result) }
1186            }
1187
1188            nonzero_integer_signedness_dependent_methods! {
1189                Primitive = $signedness $Int,
1190                SignedPrimitive = $Sint,
1191                UnsignedPrimitive = $Uint,
1192            }
1193
1194            /// Multiplies two non-zero integers together.
1195            /// Checks for overflow and returns [`None`] on overflow.
1196            /// As a consequence, the result cannot wrap to zero.
1197            ///
1198            /// # Examples
1199            ///
1200            /// ```
1201            /// # use std::num::NonZero;
1202            /// #
1203            /// # fn main() { test().unwrap(); }
1204            /// # fn test() -> Option<()> {
1205            #[doc = concat!("let two = NonZero::new(2", stringify!($Int), ")?;")]
1206            #[doc = concat!("let four = NonZero::new(4", stringify!($Int), ")?;")]
1207            #[doc = concat!("let max = NonZero::new(", stringify!($Int), "::MAX)?;")]
1208            ///
1209            /// assert_eq!(Some(four), two.checked_mul(two));
1210            /// assert_eq!(None, max.checked_mul(two));
1211            /// # Some(())
1212            /// # }
1213            /// ```
1214            #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
1215            #[rustc_const_stable(feature = "const_nonzero_checked_ops", since = "1.64.0")]
1216            #[must_use = "this returns the result of the operation, \
1217                          without modifying the original"]
1218            #[inline]
1219            pub const fn checked_mul(self, other: Self) -> Option<Self> {
1220                if let Some(result) = self.get().checked_mul(other.get()) {
1221                    // SAFETY:
1222                    // - `checked_mul` returns `None` on overflow
1223                    // - `self` and `other` are non-zero
1224                    // - the only way to get zero from a multiplication without overflow is for one
1225                    //   of the sides to be zero
1226                    //
1227                    // So the result cannot be zero.
1228                    Some(unsafe { Self::new_unchecked(result) })
1229                } else {
1230                    None
1231                }
1232            }
1233
1234            /// Multiplies two non-zero integers together, panicking if
1235            /// overflow occurs.
1236            ///
1237            /// # Panics
1238            ///
1239            /// ## Overflow behavior
1240            ///
1241            /// This function always panics on overflow, regardless of whether
1242            /// overflow checks are enabled.
1243            ///
1244            /// # Examples
1245            ///
1246            /// ```
1247            /// #![feature(nonzero_strict_ops)]
1248            ///
1249            /// # use std::num::NonZero;
1250            /// #
1251            /// # fn main() { test().unwrap(); }
1252            /// # fn test() -> Option<()> {
1253            #[doc = concat!("let three = NonZero::new(3", stringify!($Int), ")?;")]
1254            #[doc = concat!("let nine = NonZero::new(9", stringify!($Int), ")?;")]
1255            ///
1256            /// assert_eq!(nine, three.strict_mul(three));
1257            /// # Some(())
1258            /// # }
1259            /// ```
1260            ///
1261            /// The following panics because of overflow:
1262            ///
1263            /// ```should_panic
1264            /// #![feature(nonzero_strict_ops)]
1265            ///
1266            /// # use std::num::NonZero;
1267            /// #
1268            /// # fn main() { test().unwrap(); }
1269            /// # fn test() -> Option<()> {
1270            #[doc = concat!("let two = NonZero::new(2", stringify!($Int), ")?;")]
1271            #[doc = concat!("let max = NonZero::new(", stringify!($Int), "::MAX)?;")]
1272            ///
1273            /// let _ = max.strict_mul(two);
1274            /// # Some(())
1275            /// # }
1276            /// ```
1277            #[unstable(feature = "nonzero_strict_ops", issue = "164850")]
1278            #[rustc_const_unstable(feature = "const_nonzero_strict_ops", issue = "164850")]
1279            #[must_use = "this returns the result of the operation, \
1280                          without modifying the original"]
1281            #[inline]
1282            #[track_caller]
1283            pub const fn strict_mul(self, other: Self) -> Self {
1284                // SAFETY:
1285                // - `$Int::strict_mul` panics on overflow;
1286                // - `self` and `other` are nonzero;
1287                // - the only way to get zero from a multiplication without
1288                //   overflow is for either operand to be zero.
1289                //
1290                // So the result cannot be zero.
1291                unsafe { Self::new_unchecked(self.get().strict_mul(other.get())) }
1292            }
1293
1294            /// Multiplies two non-zero integers together.
1295            #[doc = concat!("Return [`NonZero::<", stringify!($Int), ">::MAX`] on overflow.")]
1296            ///
1297            /// # Examples
1298            ///
1299            /// ```
1300            /// # use std::num::NonZero;
1301            /// #
1302            /// # fn main() { test().unwrap(); }
1303            /// # fn test() -> Option<()> {
1304            #[doc = concat!("let two = NonZero::new(2", stringify!($Int), ")?;")]
1305            #[doc = concat!("let four = NonZero::new(4", stringify!($Int), ")?;")]
1306            #[doc = concat!("let max = NonZero::new(", stringify!($Int), "::MAX)?;")]
1307            ///
1308            /// assert_eq!(four, two.saturating_mul(two));
1309            /// assert_eq!(max, four.saturating_mul(max));
1310            /// # Some(())
1311            /// # }
1312            /// ```
1313            #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
1314            #[rustc_const_stable(feature = "const_nonzero_checked_ops", since = "1.64.0")]
1315            #[must_use = "this returns the result of the operation, \
1316                          without modifying the original"]
1317            #[inline]
1318            pub const fn saturating_mul(self, other: Self) -> Self {
1319                // SAFETY:
1320                // - `saturating_mul` returns `u*::MAX`/`i*::MAX`/`i*::MIN` on overflow/underflow,
1321                //   all of which are non-zero
1322                // - `self` and `other` are non-zero
1323                // - the only way to get zero from a multiplication without overflow is for one
1324                //   of the sides to be zero
1325                //
1326                // So the result cannot be zero.
1327                unsafe { Self::new_unchecked(self.get().saturating_mul(other.get())) }
1328            }
1329
1330            /// Multiplies two non-zero integers together,
1331            /// assuming overflow cannot occur.
1332            /// Overflow is unchecked, and it is undefined behavior to overflow
1333            /// *even if the result would wrap to a non-zero value*.
1334            ///
1335            /// # Safety
1336            ///
1337            /// This results in undefined behavior when overflow occurs, i.e.
1338            /// when [`checked_mul`] would return `None`.
1339            ///
1340            /// # Examples
1341            ///
1342            /// ```
1343            /// # use std::num::NonZero;
1344            /// #
1345            /// # fn main() { test().unwrap(); }
1346            /// # fn test() -> Option<()> {
1347            #[doc = concat!("let two = NonZero::new(2", stringify!($Int), ")?;")]
1348            #[doc = concat!("let four = NonZero::new(4", stringify!($Int), ")?;")]
1349            ///
1350            /// assert_eq!(four, unsafe { two.unchecked_mul(two) });
1351            /// # Some(())
1352            /// # }
1353            /// ```
1354            ///
1355            /// [`checked_mul`]: Self::checked_mul
1356            #[stable(feature = "nonzero_ops", since = "CURRENT_RUSTC_VERSION")]
1357            #[rustc_const_stable(feature = "nonzero_ops", since = "CURRENT_RUSTC_VERSION")]
1358            #[must_use = "this returns the result of the operation, \
1359                          without modifying the original"]
1360            #[inline]
1361            pub const unsafe fn unchecked_mul(self, other: Self) -> Self {
1362                // SAFETY:
1363                // - the caller promises that the multiplication does not overflow;
1364                // - `self` and `other` are non-zero;
1365                // - the only way to get zero from a multiplication without overflow
1366                //   is for either factor to be zero.
1367                unsafe { Self::new_unchecked(self.get().unchecked_mul(other.get())) }
1368            }
1369
1370            /// Raises non-zero value to an integer power.
1371            /// Checks for overflow and returns [`None`] on overflow.
1372            /// As a consequence, the result cannot wrap to zero.
1373            ///
1374            /// # Examples
1375            ///
1376            /// ```
1377            /// # use std::num::NonZero;
1378            /// #
1379            /// # fn main() { test().unwrap(); }
1380            /// # fn test() -> Option<()> {
1381            #[doc = concat!("let three = NonZero::new(3", stringify!($Int), ")?;")]
1382            #[doc = concat!("let twenty_seven = NonZero::new(27", stringify!($Int), ")?;")]
1383            #[doc = concat!("let half_max = NonZero::new(", stringify!($Int), "::MAX / 2)?;")]
1384            ///
1385            /// assert_eq!(Some(twenty_seven), three.checked_pow(3));
1386            /// assert_eq!(None, half_max.checked_pow(3));
1387            /// # Some(())
1388            /// # }
1389            /// ```
1390            #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
1391            #[rustc_const_stable(feature = "const_nonzero_checked_ops", since = "1.64.0")]
1392            #[must_use = "this returns the result of the operation, \
1393                          without modifying the original"]
1394            #[inline]
1395            pub const fn checked_pow(self, other: u32) -> Option<Self> {
1396                if let Some(result) = self.get().checked_pow(other) {
1397                    // SAFETY:
1398                    // - `checked_pow` returns `None` on overflow/underflow
1399                    // - `self` is non-zero
1400                    // - the only way to get zero from an exponentiation without overflow is
1401                    //   for base to be zero
1402                    //
1403                    // So the result cannot be zero.
1404                    Some(unsafe { Self::new_unchecked(result) })
1405                } else {
1406                    None
1407                }
1408            }
1409
1410            /// Raises a non-zero value to an integer power, panicking if
1411            /// overflow occurs.
1412            ///
1413            /// # Panics
1414            ///
1415            /// ## Overflow behavior
1416            ///
1417            /// This function always panics on overflow, regardless of whether
1418            /// overflow checks are enabled.
1419            ///
1420            /// # Examples
1421            ///
1422            /// ```
1423            /// #![feature(nonzero_strict_ops)]
1424            ///
1425            /// # use std::num::NonZero;
1426            /// #
1427            /// # fn main() { test().unwrap(); }
1428            /// # fn test() -> Option<()> {
1429            #[doc = concat!("let two = NonZero::new(2", stringify!($Int), ")?;")]
1430            #[doc = concat!("let sixteen = NonZero::new(16", stringify!($Int), ")?;")]
1431            ///
1432            /// assert_eq!(sixteen, two.strict_pow(4));
1433            /// # Some(())
1434            /// # }
1435            /// ```
1436            ///
1437            /// The following panics because of overflow:
1438            ///
1439            /// ```should_panic
1440            /// #![feature(nonzero_strict_ops)]
1441            ///
1442            /// # use std::num::NonZero;
1443            /// #
1444            /// # fn main() { test().unwrap(); }
1445            /// # fn test() -> Option<()> {
1446            #[doc = concat!("let half_max = NonZero::new(", stringify!($Int), "::MAX / 2)?;")]
1447            ///
1448            /// let _ = half_max.strict_pow(2);
1449            /// # Some(())
1450            /// # }
1451            /// ```
1452            #[unstable(feature = "nonzero_strict_ops", issue = "164850")]
1453            #[rustc_const_unstable(feature = "const_nonzero_strict_ops", issue = "164850")]
1454            #[must_use = "this returns the result of the operation, \
1455                          without modifying the original"]
1456            #[inline]
1457            #[track_caller]
1458            pub const fn strict_pow(self, exp: u32) -> Self {
1459                // SAFETY:
1460                // - `$Int::strict_pow` panics on overflow;
1461                // - `self` is nonzero;
1462                // - the only way to get zero from an exponentiation without
1463                //   overflow is for the base to be zero.
1464                //
1465                // So the result cannot be zero.
1466                unsafe { Self::new_unchecked(self.get().strict_pow(exp)) }
1467            }
1468
1469            /// Raise non-zero value to an integer power.
1470            #[doc = sign_dependent_expr!{
1471                $signedness ?
1472                if signed {
1473                    concat!("Return [`NonZero::<", stringify!($Int), ">::MIN`] ",
1474                                "or [`NonZero::<", stringify!($Int), ">::MAX`] on overflow.")
1475                }
1476                if unsigned {
1477                    concat!("Return [`NonZero::<", stringify!($Int), ">::MAX`] on overflow.")
1478                }
1479            }]
1480            ///
1481            /// # Examples
1482            ///
1483            /// ```
1484            /// # use std::num::NonZero;
1485            /// #
1486            /// # fn main() { test().unwrap(); }
1487            /// # fn test() -> Option<()> {
1488            #[doc = concat!("let three = NonZero::new(3", stringify!($Int), ")?;")]
1489            #[doc = concat!("let twenty_seven = NonZero::new(27", stringify!($Int), ")?;")]
1490            #[doc = concat!("let max = NonZero::new(", stringify!($Int), "::MAX)?;")]
1491            ///
1492            /// assert_eq!(twenty_seven, three.saturating_pow(3));
1493            /// assert_eq!(max, max.saturating_pow(3));
1494            /// # Some(())
1495            /// # }
1496            /// ```
1497            #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
1498            #[rustc_const_stable(feature = "const_nonzero_checked_ops", since = "1.64.0")]
1499            #[must_use = "this returns the result of the operation, \
1500                          without modifying the original"]
1501            #[inline]
1502            pub const fn saturating_pow(self, other: u32) -> Self {
1503                // SAFETY:
1504                // - `saturating_pow` returns `u*::MAX`/`i*::MAX`/`i*::MIN` on overflow/underflow,
1505                //   all of which are non-zero
1506                // - `self` is non-zero
1507                // - the only way to get zero from an exponentiation without overflow is
1508                //   for base to be zero
1509                //
1510                // So the result cannot be zero.
1511                unsafe { Self::new_unchecked(self.get().saturating_pow(other)) }
1512            }
1513
1514            /// Parses a non-zero integer from an ASCII-byte slice with decimal digits.
1515            ///
1516            /// The characters are expected to be an optional
1517            #[doc = sign_dependent_expr!{
1518                $signedness ?
1519                if signed {
1520                    " `+` or `-` "
1521                }
1522                if unsigned {
1523                    " `+` "
1524                }
1525            }]
1526            /// sign followed by only digits. Leading and trailing non-digit characters (including
1527            /// whitespace) represent an error. Underscores (which are accepted in Rust literals)
1528            /// also represent an error.
1529            ///
1530            /// # Examples
1531            ///
1532            /// ```
1533            /// # use std::num::NonZero;
1534            /// #
1535            /// # fn main() { test().unwrap(); }
1536            /// # fn test() -> Option<()> {
1537            #[doc = concat!("assert_eq!(NonZero::<", stringify!($Int), ">::from_ascii_bytes(b\"+10\"), Ok(NonZero::new(10)?));")]
1538            /// # Some(())
1539            /// # }
1540            /// ```
1541            ///
1542            /// Trailing space returns error:
1543            ///
1544            /// ```
1545            /// # use std::num::NonZero;
1546            /// #
1547            #[doc = concat!("assert!(NonZero::<", stringify!($Int), ">::from_ascii_bytes(b\"1 \").is_err());")]
1548            /// ```
1549            #[stable(feature = "int_from_ascii", since = "CURRENT_RUSTC_VERSION")]
1550            #[rustc_const_unstable(feature = "const_convert", issue = "143773")]
1551            #[inline]
1552            pub const fn from_ascii_bytes<T>(src: T) -> Result<Self, ParseIntError>
1553            where
1554                T: [const] AsRef<[u8]> + [const] crate::marker::Destruct
1555            {
1556                Self::from_ascii_bytes_radix_impl(src.as_ref(), 10)
1557            }
1558
1559            /// Parses a non-zero integer from an ASCII-byte slice with digits in a given base.
1560            ///
1561            /// The characters are expected to be an optional
1562            #[doc = sign_dependent_expr!{
1563                $signedness ?
1564                if signed {
1565                    " `+` or `-` "
1566                }
1567                if unsigned {
1568                    " `+` "
1569                }
1570            }]
1571            /// sign followed by only digits. Leading and trailing non-digit characters (including
1572            /// whitespace) represent an error. Underscores (which are accepted in Rust literals)
1573            /// also represent an error.
1574            ///
1575            /// Digits are a subset of these characters, depending on `radix`:
1576            ///
1577            /// - `0-9`
1578            /// - `a-z`
1579            /// - `A-Z`
1580            ///
1581            /// # Panics
1582            ///
1583            /// This method panics if `radix` is not in the range from 2 to 36.
1584            ///
1585            /// # Examples
1586            ///
1587            /// ```
1588            /// # use std::num::NonZero;
1589            /// #
1590            /// # fn main() { test().unwrap(); }
1591            /// # fn test() -> Option<()> {
1592            #[doc = concat!("assert_eq!(NonZero::<", stringify!($Int), ">::from_ascii_bytes_radix(b\"A\", 16), Ok(NonZero::new(10)?));")]
1593            /// # Some(())
1594            /// # }
1595            /// ```
1596            ///
1597            /// Trailing space returns error:
1598            ///
1599            /// ```
1600            /// # use std::num::NonZero;
1601            /// #
1602            #[doc = concat!("assert!(NonZero::<", stringify!($Int), ">::from_ascii_bytes_radix(b\"1 \", 10).is_err());")]
1603            /// ```
1604            #[stable(feature = "int_from_ascii", since = "CURRENT_RUSTC_VERSION")]
1605            #[rustc_const_unstable(feature = "const_convert", issue = "143773")]
1606            #[inline]
1607            pub const fn from_ascii_bytes_radix<T>(src: T, radix: u32) -> Result<Self, ParseIntError>
1608            where
1609                T: [const] AsRef<[u8]> + [const] crate::marker::Destruct
1610            {
1611                Self::from_ascii_bytes_radix_impl(src.as_ref(), radix)
1612            }
1613
1614            #[inline]
1615            const fn from_ascii_bytes_radix_impl(src: &[u8], radix: u32) -> Result<Self, ParseIntError> {
1616                // FIXME(const-hack): This should use `?` again, once it's `const`
1617                let n = match <$Int>::from_ascii_bytes_radix_impl(src, radix) {
1618                    Ok(n) => n,
1619                    Err(err) => return Err(err),
1620                };
1621                // FIXME(const-hack): This should use `Option::ok_or` again, once it's `const`
1622                if let Some(n) = Self::new(n) {
1623                    Ok(n)
1624                } else {
1625                    Err(ParseIntError { kind: IntErrorKind::Zero })
1626                }
1627            }
1628
1629            /// Parses a non-zero integer from a string slice with digits in a given base.
1630            ///
1631            /// The string is expected to be an optional
1632            #[doc = sign_dependent_expr!{
1633                $signedness ?
1634                if signed {
1635                    " `+` or `-` "
1636                }
1637                if unsigned {
1638                    " `+` "
1639                }
1640            }]
1641            /// sign followed by only digits. Leading and trailing non-digit characters (including
1642            /// whitespace) represent an error. Underscores (which are accepted in Rust literals)
1643            /// also represent an error.
1644            ///
1645            /// Digits are a subset of these characters, depending on `radix`:
1646            ///
1647            /// - `0-9`
1648            /// - `a-z`
1649            /// - `A-Z`
1650            ///
1651            /// # Panics
1652            ///
1653            /// This method panics if `radix` is not in the range from 2 to 36.
1654            ///
1655            /// # Examples
1656            ///
1657            /// ```
1658            /// # use std::num::NonZero;
1659            /// #
1660            /// # fn main() { test().unwrap(); }
1661            /// # fn test() -> Option<()> {
1662            #[doc = concat!("assert_eq!(NonZero::<", stringify!($Int), ">::from_str_radix(\"A\", 16), Ok(NonZero::new(10)?));")]
1663            /// # Some(())
1664            /// # }
1665            /// ```
1666            ///
1667            /// Trailing space returns error:
1668            ///
1669            /// ```
1670            /// # use std::num::NonZero;
1671            /// #
1672            #[doc = concat!("assert!(NonZero::<", stringify!($Int), ">::from_str_radix(\"1 \", 10).is_err());")]
1673            /// ```
1674            #[stable(feature = "nonzero_from_str_radix", since = "1.98.0")]
1675            #[rustc_const_stable(feature = "nonzero_from_str_radix", since = "1.98.0")]
1676            #[inline]
1677            pub const fn from_str_radix(src: &str, radix: u32) -> Result<Self, ParseIntError> {
1678                Self::from_ascii_bytes_radix_impl(src.as_bytes(), radix)
1679            }
1680        }
1681
1682        #[stable(feature = "nonzero_parse", since = "1.35.0")]
1683        #[rustc_const_unstable(feature = "const_convert", issue = "143773")]
1684        const impl FromStr for NonZero<$Int> {
1685            type Err = ParseIntError;
1686
1687            /// Parses a non-zero integer from a string slice with decimal digits.
1688            ///
1689            /// The characters are expected to be an optional
1690            #[doc = sign_dependent_expr!{
1691                $signedness ?
1692                if signed {
1693                    " `+` or `-` "
1694                }
1695                if unsigned {
1696                    " `+` "
1697                }
1698            }]
1699            /// sign followed by only digits. Leading and trailing non-digit characters (including
1700            /// whitespace) represent an error. Underscores (which are accepted in Rust literals)
1701            /// also represent an error.
1702            ///
1703            /// # Examples
1704            ///
1705            /// ```
1706            /// use std::num::NonZero;
1707            /// use std::str::FromStr;
1708            ///
1709            #[doc = concat!("assert_eq!(NonZero::<", stringify!($Int), ">::from_str(\"+10\"), Ok(NonZero::new(10).unwrap()));")]
1710            /// ```
1711            ///
1712            /// Trailing space returns error:
1713            ///
1714            /// ```
1715            /// use std::num::NonZero;
1716            /// use std::str::FromStr;
1717            ///
1718            #[doc = concat!("assert!(NonZero::<", stringify!($Int), ">::from_str(\"1 \").is_err());")]
1719            /// ```
1720            #[inline]
1721            fn from_str(src: &str) -> Result<Self, Self::Err> {
1722                Self::from_str_radix(src, 10)
1723            }
1724        }
1725
1726        nonzero_integer_signedness_dependent_impls!($signedness $Int);
1727    };
1728
1729    (
1730        Self = $Ty:ident,
1731        Primitive = unsigned $Int:ident,
1732        SignedPrimitive = $Sint:ident,
1733        rot = $rot:literal,
1734        rot_op = $rot_op:literal,
1735        rot_result = $rot_result:literal,
1736        swap_op = $swap_op:literal,
1737        swapped = $swapped:literal,
1738        reversed = $reversed:literal,
1739        $(,)?
1740    ) => {
1741        nonzero_integer! {
1742            #[stable(feature = "nonzero", since = "1.28.0")]
1743            Self = $Ty,
1744            Primitive = unsigned $Int,
1745            SignedPrimitive = $Sint,
1746            UnsignedPrimitive = $Int,
1747            rot = $rot,
1748            rot_op = $rot_op,
1749            rot_result = $rot_result,
1750            swap_op = $swap_op,
1751            swapped = $swapped,
1752            reversed = $reversed,
1753            leading_zeros_test = concat!(stringify!($Int), "::MAX"),
1754        }
1755    };
1756
1757    (
1758        Self = $Ty:ident,
1759        Primitive = signed $Int:ident,
1760        UnsignedPrimitive = $Uint:ident,
1761        rot = $rot:literal,
1762        rot_op = $rot_op:literal,
1763        rot_result = $rot_result:literal,
1764        swap_op = $swap_op:literal,
1765        swapped = $swapped:literal,
1766        reversed = $reversed:literal,
1767    ) => {
1768        nonzero_integer! {
1769            #[stable(feature = "signed_nonzero", since = "1.34.0")]
1770            Self = $Ty,
1771            Primitive = signed $Int,
1772            SignedPrimitive = $Int,
1773            UnsignedPrimitive = $Uint,
1774            rot = $rot,
1775            rot_op = $rot_op,
1776            rot_result = $rot_result,
1777            swap_op = $swap_op,
1778            swapped = $swapped,
1779            reversed = $reversed,
1780            leading_zeros_test = concat!("-1", stringify!($Int)),
1781        }
1782    };
1783}
1784
1785macro_rules! nonzero_integer_signedness_dependent_impls {
1786    // Impls for unsigned nonzero types only.
1787    (unsigned $Int:ty) => {
1788        #[stable(feature = "nonzero_div", since = "1.51.0")]
1789        #[rustc_const_unstable(feature = "const_ops", issue = "143802")]
1790        const impl Div<NonZero<$Int>> for $Int {
1791            type Output = $Int;
1792
1793            /// Same as `self / other.get()`, but because `other` is a `NonZero<_>`,
1794            /// there's never a runtime check for division-by-zero.
1795            ///
1796            /// This operation rounds towards zero, truncating any fractional
1797            /// part of the exact result, and cannot panic.
1798            #[doc(alias = "unchecked_div")]
1799            #[inline]
1800            fn div(self, other: NonZero<$Int>) -> $Int {
1801                // SAFETY: Division by zero is checked because `other` is non-zero,
1802                // and MIN/-1 is checked because `self` is an unsigned int.
1803                unsafe { intrinsics::unchecked_div(self, other.get()) }
1804            }
1805        }
1806
1807        #[stable(feature = "nonzero_div_assign", since = "1.79.0")]
1808        #[rustc_const_unstable(feature = "const_ops", issue = "143802")]
1809        const impl DivAssign<NonZero<$Int>> for $Int {
1810            /// Same as `self /= other.get()`, but because `other` is a `NonZero<_>`,
1811            /// there's never a runtime check for division-by-zero.
1812            ///
1813            /// This operation rounds towards zero, truncating any fractional
1814            /// part of the exact result, and cannot panic.
1815            #[inline]
1816            fn div_assign(&mut self, other: NonZero<$Int>) {
1817                *self = *self / other;
1818            }
1819        }
1820
1821        #[stable(feature = "nonzero_div", since = "1.51.0")]
1822        #[rustc_const_unstable(feature = "const_ops", issue = "143802")]
1823        const impl Rem<NonZero<$Int>> for $Int {
1824            type Output = $Int;
1825
1826            /// This operation satisfies `n % d == n - (n / d) * d`, and cannot panic.
1827            #[inline]
1828            fn rem(self, other: NonZero<$Int>) -> $Int {
1829                // SAFETY: Remainder by zero is checked because `other` is non-zero,
1830                // and MIN/-1 is checked because `self` is an unsigned int.
1831                unsafe { intrinsics::unchecked_rem(self, other.get()) }
1832            }
1833        }
1834
1835        #[stable(feature = "nonzero_div_assign", since = "1.79.0")]
1836        #[rustc_const_unstable(feature = "const_ops", issue = "143802")]
1837        const impl RemAssign<NonZero<$Int>> for $Int {
1838            /// This operation satisfies `n % d == n - (n / d) * d`, and cannot panic.
1839            #[inline]
1840            fn rem_assign(&mut self, other: NonZero<$Int>) {
1841                *self = *self % other;
1842            }
1843        }
1844    };
1845    // Impls for signed nonzero types only.
1846    (signed $Int:ty) => {
1847        #[stable(feature = "signed_nonzero_neg", since = "1.71.0")]
1848        #[rustc_const_unstable(feature = "const_ops", issue = "143802")]
1849        const impl Neg for NonZero<$Int> {
1850            type Output = Self;
1851
1852            #[inline]
1853            fn neg(self) -> Self {
1854                // SAFETY: negation of nonzero cannot yield zero values.
1855                unsafe { Self::new_unchecked(self.get().neg()) }
1856            }
1857        }
1858
1859        forward_ref_unop! { impl Neg, neg for NonZero<$Int>,
1860        #[stable(feature = "signed_nonzero_neg", since = "1.71.0")]
1861        #[rustc_const_unstable(feature = "const_ops", issue = "143802")] }
1862    };
1863}
1864
1865#[rustfmt::skip] // https://github.com/rust-lang/rustfmt/issues/5974
1866macro_rules! nonzero_integer_signedness_dependent_methods {
1867    // Associated items for unsigned nonzero types only.
1868    (
1869        Primitive = unsigned $Int:ident,
1870        SignedPrimitive = $Sint:ty,
1871        UnsignedPrimitive = $Uint:ty,
1872    ) => {
1873        /// The smallest value that can be represented by this non-zero
1874        /// integer type, 1.
1875        ///
1876        /// # Examples
1877        ///
1878        /// ```
1879        /// # use std::num::NonZero;
1880        /// #
1881        #[doc = concat!("assert_eq!(NonZero::<", stringify!($Int), ">::MIN.get(), 1", stringify!($Int), ");")]
1882        /// ```
1883        #[stable(feature = "nonzero_min_max", since = "1.70.0")]
1884        pub const MIN: Self = Self::new(1).unwrap();
1885
1886        /// The largest value that can be represented by this non-zero
1887        /// integer type,
1888        #[doc = concat!("equal to [`", stringify!($Int), "::MAX`].")]
1889        ///
1890        /// # Examples
1891        ///
1892        /// ```
1893        /// # use std::num::NonZero;
1894        /// #
1895        #[doc = concat!("assert_eq!(NonZero::<", stringify!($Int), ">::MAX.get(), ", stringify!($Int), "::MAX);")]
1896        /// ```
1897        #[stable(feature = "nonzero_min_max", since = "1.70.0")]
1898        pub const MAX: Self = Self::new(<$Int>::MAX).unwrap();
1899
1900        /// Adds an unsigned integer to a non-zero value.
1901        /// Checks for overflow and returns [`None`] on overflow.
1902        /// As a consequence, the result cannot wrap to zero.
1903        ///
1904        ///
1905        /// # Examples
1906        ///
1907        /// ```
1908        /// # use std::num::NonZero;
1909        /// #
1910        /// # fn main() { test().unwrap(); }
1911        /// # fn test() -> Option<()> {
1912        #[doc = concat!("let one = NonZero::new(1", stringify!($Int), ")?;")]
1913        #[doc = concat!("let two = NonZero::new(2", stringify!($Int), ")?;")]
1914        #[doc = concat!("let max = NonZero::new(", stringify!($Int), "::MAX)?;")]
1915        ///
1916        /// assert_eq!(Some(two), one.checked_add(1));
1917        /// assert_eq!(None, max.checked_add(1));
1918        /// # Some(())
1919        /// # }
1920        /// ```
1921        #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
1922        #[rustc_const_stable(feature = "const_nonzero_checked_ops", since = "1.64.0")]
1923        #[must_use = "this returns the result of the operation, \
1924                      without modifying the original"]
1925        #[inline]
1926        pub const fn checked_add(self, other: $Int) -> Option<Self> {
1927            if let Some(result) = self.get().checked_add(other) {
1928                // SAFETY:
1929                // - `checked_add` returns `None` on overflow
1930                // - `self` is non-zero
1931                // - the only way to get zero from an addition without overflow is for both
1932                //   sides to be zero
1933                //
1934                // So the result cannot be zero.
1935                Some(unsafe { Self::new_unchecked(result) })
1936            } else {
1937                None
1938            }
1939        }
1940
1941        /// Adds an unsigned integer to a non-zero value, panicking
1942        /// if overflow occurs.
1943        ///
1944        /// # Panics
1945        ///
1946        /// ## Overflow behavior
1947        ///
1948        /// This function always panics on overflow, regardless of whether
1949        /// overflow checks are enabled.
1950        ///
1951        /// # Examples
1952        ///
1953        /// ```
1954        /// #![feature(nonzero_strict_ops)]
1955        ///
1956        /// # use std::num::NonZero;
1957        /// #
1958        /// # fn main() { test().unwrap(); }
1959        /// # fn test() -> Option<()> {
1960        #[doc = concat!("let two = NonZero::new(2", stringify!($Int), ")?;")]
1961        #[doc = concat!("let three = NonZero::new(3", stringify!($Int), ")?;")]
1962        ///
1963        /// assert_eq!(three, two.strict_add(1));
1964        /// # Some(())
1965        /// # }
1966        /// ```
1967        ///
1968        /// The following panics because of overflow:
1969        ///
1970        /// ```should_panic
1971        /// #![feature(nonzero_strict_ops)]
1972        ///
1973        /// # use std::num::NonZero;
1974        /// #
1975        /// # fn main() { test().unwrap(); }
1976        /// # fn test() -> Option<()> {
1977        #[doc = concat!("let max = NonZero::new(", stringify!($Int), "::MAX)?;")]
1978        ///
1979        /// let _ = max.strict_add(1);
1980        /// # Some(())
1981        /// # }
1982        /// ```
1983        #[unstable(feature = "nonzero_strict_ops", issue = "164850")]
1984        #[rustc_const_unstable(feature = "const_nonzero_strict_ops", issue = "164850")]
1985        #[must_use = "this returns the result of the operation, \
1986                      without modifying the original"]
1987        #[inline]
1988        #[track_caller]
1989        pub const fn strict_add(self, other: $Int) -> Self {
1990            // SAFETY:
1991            // - `$Int::strict_add` panics on overflow;
1992            // - `self` is nonzero;
1993            // - the only way to get zero from an unsigned addition without
1994            //   overflow is for both addends to be zero.
1995            //
1996            // So the result cannot be zero.
1997            unsafe { Self::new_unchecked(self.get().strict_add(other)) }
1998        }
1999
2000        /// Adds an unsigned integer to a non-zero value.
2001        #[doc = concat!("Return [`NonZero::<", stringify!($Int), ">::MAX`] on overflow.")]
2002        ///
2003        /// # Examples
2004        ///
2005        /// ```
2006        /// # use std::num::NonZero;
2007        /// #
2008        /// # fn main() { test().unwrap(); }
2009        /// # fn test() -> Option<()> {
2010        #[doc = concat!("let one = NonZero::new(1", stringify!($Int), ")?;")]
2011        #[doc = concat!("let two = NonZero::new(2", stringify!($Int), ")?;")]
2012        #[doc = concat!("let max = NonZero::new(", stringify!($Int), "::MAX)?;")]
2013        ///
2014        /// assert_eq!(two, one.saturating_add(1));
2015        /// assert_eq!(max, max.saturating_add(1));
2016        /// # Some(())
2017        /// # }
2018        /// ```
2019        #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
2020        #[rustc_const_stable(feature = "const_nonzero_checked_ops", since = "1.64.0")]
2021        #[must_use = "this returns the result of the operation, \
2022                      without modifying the original"]
2023        #[inline]
2024        pub const fn saturating_add(self, other: $Int) -> Self {
2025            // SAFETY:
2026            // - `saturating_add` returns `u*::MAX` on overflow, which is non-zero
2027            // - `self` is non-zero
2028            // - the only way to get zero from an addition without overflow is for both
2029            //   sides to be zero
2030            //
2031            // So the result cannot be zero.
2032            unsafe { Self::new_unchecked(self.get().saturating_add(other)) }
2033        }
2034
2035        /// Adds an unsigned integer to a non-zero value,
2036        /// assuming overflow cannot occur.
2037        /// Overflow is unchecked, and it is undefined behavior to overflow
2038        /// *even if the result would wrap to a non-zero value*.
2039        ///
2040        /// # Safety
2041        ///
2042        /// This results in undefined behavior when overflow occurs, i.e. when
2043        /// [`checked_add`] would return `None`.
2044        ///
2045        /// # Examples
2046        ///
2047        /// ```
2048        /// # use std::num::NonZero;
2049        /// #
2050        /// # fn main() { test().unwrap(); }
2051        /// # fn test() -> Option<()> {
2052        #[doc = concat!("let one = NonZero::new(1", stringify!($Int), ")?;")]
2053        #[doc = concat!("let two = NonZero::new(2", stringify!($Int), ")?;")]
2054        ///
2055        /// assert_eq!(two, unsafe { one.unchecked_add(1) });
2056        /// # Some(())
2057        /// # }
2058        /// ```
2059        ///
2060        /// [`checked_add`]: Self::checked_add
2061        #[stable(feature = "nonzero_ops", since = "CURRENT_RUSTC_VERSION")]
2062        #[rustc_const_stable(feature = "nonzero_ops", since = "CURRENT_RUSTC_VERSION")]
2063        #[must_use = "this returns the result of the operation, \
2064                      without modifying the original"]
2065        #[inline]
2066        pub const unsafe fn unchecked_add(self, other: $Int) -> Self {
2067            // SAFETY:
2068            // - the caller promises that the addition does not overflow;
2069            // - `self` is non-zero;
2070            // - the only way to get zero from an addition of unsigned integers
2071            //   without overflow is for both addends to be zero.
2072            unsafe { Self::new_unchecked(self.get().unchecked_add(other)) }
2073        }
2074
2075        /// Calculates the quotient of `self` and `rhs`, rounding the result towards positive infinity.
2076        ///
2077        /// The result is guaranteed to be non-zero.
2078        ///
2079        /// # Examples
2080        ///
2081        /// ```
2082        /// # use std::num::NonZero;
2083        #[doc = concat!("let one = NonZero::new(1", stringify!($Int), ").unwrap();")]
2084        #[doc = concat!("let max = NonZero::new(", stringify!($Int), "::MAX).unwrap();")]
2085        /// assert_eq!(one.div_ceil(max), one);
2086        ///
2087        #[doc = concat!("let two = NonZero::new(2", stringify!($Int), ").unwrap();")]
2088        #[doc = concat!("let three = NonZero::new(3", stringify!($Int), ").unwrap();")]
2089        /// assert_eq!(three.div_ceil(two), two);
2090        /// ```
2091        #[stable(feature = "unsigned_nonzero_div_ceil", since = "1.92.0")]
2092        #[rustc_const_stable(feature = "unsigned_nonzero_div_ceil", since = "1.92.0")]
2093        #[must_use = "this returns the result of the operation, \
2094                      without modifying the original"]
2095        #[inline]
2096        pub const fn div_ceil(self, rhs: Self) -> Self {
2097            // An implementation of the function without calculating the remainder.
2098            // It is better than the implementation for normal integers, but it can only
2099            // be used here because of the possibility to subtract by one without overflow.
2100            let v = (self.get() - 1) / rhs.get() + 1;
2101            // SAFETY: ceiled division of two positive integers can never be zero.
2102            unsafe { Self::new_unchecked(v) }
2103        }
2104
2105        /// Returns the smallest power of two greater than or equal to `self`.
2106        /// Checks for overflow and returns [`None`]
2107        /// if the next power of two is greater than the type’s maximum value.
2108        /// As a consequence, the result cannot wrap to zero.
2109        ///
2110        /// # Examples
2111        ///
2112        /// ```
2113        /// # use std::num::NonZero;
2114        /// #
2115        /// # fn main() { test().unwrap(); }
2116        /// # fn test() -> Option<()> {
2117        #[doc = concat!("let two = NonZero::new(2", stringify!($Int), ")?;")]
2118        #[doc = concat!("let three = NonZero::new(3", stringify!($Int), ")?;")]
2119        #[doc = concat!("let four = NonZero::new(4", stringify!($Int), ")?;")]
2120        #[doc = concat!("let max = NonZero::new(", stringify!($Int), "::MAX)?;")]
2121        ///
2122        /// assert_eq!(Some(two), two.checked_next_power_of_two() );
2123        /// assert_eq!(Some(four), three.checked_next_power_of_two() );
2124        /// assert_eq!(None, max.checked_next_power_of_two() );
2125        /// # Some(())
2126        /// # }
2127        /// ```
2128        #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
2129        #[rustc_const_stable(feature = "const_nonzero_checked_ops", since = "1.64.0")]
2130        #[must_use = "this returns the result of the operation, \
2131                      without modifying the original"]
2132        #[inline]
2133        pub const fn checked_next_power_of_two(self) -> Option<Self> {
2134            if let Some(nz) = self.get().checked_next_power_of_two() {
2135                // SAFETY: The next power of two is positive
2136                // and overflow is checked.
2137                Some(unsafe { Self::new_unchecked(nz) })
2138            } else {
2139                None
2140            }
2141        }
2142
2143        /// Returns the base 2 logarithm of the number, rounded down.
2144        ///
2145        /// This is the same operation as
2146        #[doc = concat!("[`", stringify!($Int), "::ilog2`],")]
2147        /// except that it has no failure cases to worry about
2148        /// since this value can never be zero.
2149        ///
2150        /// Note that this is equivalent to [`highest_one`](Self::highest_one).
2151        ///
2152        /// # Examples
2153        ///
2154        /// ```
2155        /// # use std::num::NonZero;
2156        /// #
2157        /// # fn main() { test().unwrap(); }
2158        /// # fn test() -> Option<()> {
2159        #[doc = concat!("assert_eq!(NonZero::new(7", stringify!($Int), ")?.ilog2(), 2);")]
2160        #[doc = concat!("assert_eq!(NonZero::new(8", stringify!($Int), ")?.ilog2(), 3);")]
2161        #[doc = concat!("assert_eq!(NonZero::new(9", stringify!($Int), ")?.ilog2(), 3);")]
2162        /// # Some(())
2163        /// # }
2164        /// ```
2165        #[stable(feature = "int_log", since = "1.67.0")]
2166        #[rustc_const_stable(feature = "int_log", since = "1.67.0")]
2167        #[must_use = "this returns the result of the operation, \
2168                      without modifying the original"]
2169        #[inline]
2170        pub const fn ilog2(self) -> u32 {
2171            Self::BITS - 1 - self.leading_zeros()
2172        }
2173
2174        /// Returns the base 10 logarithm of the number, rounded down.
2175        ///
2176        /// This is the same operation as
2177        #[doc = concat!("[`", stringify!($Int), "::ilog10`],")]
2178        /// except that it has no failure cases to worry about
2179        /// since this value can never be zero.
2180        ///
2181        /// # Examples
2182        ///
2183        /// ```
2184        /// # use std::num::NonZero;
2185        /// #
2186        /// # fn main() { test().unwrap(); }
2187        /// # fn test() -> Option<()> {
2188        #[doc = concat!("assert_eq!(NonZero::new(99", stringify!($Int), ")?.ilog10(), 1);")]
2189        #[doc = concat!("assert_eq!(NonZero::new(100", stringify!($Int), ")?.ilog10(), 2);")]
2190        #[doc = concat!("assert_eq!(NonZero::new(101", stringify!($Int), ")?.ilog10(), 2);")]
2191        /// # Some(())
2192        /// # }
2193        /// ```
2194        #[stable(feature = "int_log", since = "1.67.0")]
2195        #[rustc_const_stable(feature = "int_log", since = "1.67.0")]
2196        #[must_use = "this returns the result of the operation, \
2197                      without modifying the original"]
2198        #[inline]
2199        pub const fn ilog10(self) -> u32 {
2200            imp::int_log10::$Int(self)
2201        }
2202
2203        /// Calculates the midpoint (average) between `self` and `rhs`.
2204        ///
2205        /// `midpoint(a, b)` is `(a + b) >> 1` as if it were performed in a
2206        /// sufficiently-large signed integral type. This implies that the result is
2207        /// always rounded towards negative infinity and that no overflow will ever occur.
2208        ///
2209        /// # Examples
2210        ///
2211        /// ```
2212        /// # use std::num::NonZero;
2213        /// #
2214        /// # fn main() { test().unwrap(); }
2215        /// # fn test() -> Option<()> {
2216        #[doc = concat!("let one = NonZero::new(1", stringify!($Int), ")?;")]
2217        #[doc = concat!("let two = NonZero::new(2", stringify!($Int), ")?;")]
2218        #[doc = concat!("let four = NonZero::new(4", stringify!($Int), ")?;")]
2219        ///
2220        /// assert_eq!(one.midpoint(four), two);
2221        /// assert_eq!(four.midpoint(one), two);
2222        /// # Some(())
2223        /// # }
2224        /// ```
2225        #[stable(feature = "num_midpoint", since = "1.85.0")]
2226        #[rustc_const_stable(feature = "num_midpoint", since = "1.85.0")]
2227        #[must_use = "this returns the result of the operation, \
2228                      without modifying the original"]
2229        #[doc(alias = "average_floor")]
2230        #[doc(alias = "average")]
2231        #[inline]
2232        pub const fn midpoint(self, rhs: Self) -> Self {
2233            // SAFETY: The only way to get `0` with midpoint is to have two opposite or
2234            // near opposite numbers: (-5, 5), (0, 1), (0, 0) which is impossible because
2235            // of the unsignedness of this number and also because `Self` is guaranteed to
2236            // never being 0.
2237            unsafe { Self::new_unchecked(self.get().midpoint(rhs.get())) }
2238        }
2239
2240        /// Returns `true` if and only if `self == (1 << k)` for some `k`.
2241        ///
2242        /// On many architectures, this function can perform better than `is_power_of_two()`
2243        /// on the underlying integer type, as special handling of zero can be avoided.
2244        ///
2245        /// # Examples
2246        ///
2247        /// ```
2248        /// # use std::num::NonZero;
2249        /// #
2250        /// # fn main() { test().unwrap(); }
2251        /// # fn test() -> Option<()> {
2252        #[doc = concat!("let eight = NonZero::new(8", stringify!($Int), ")?;")]
2253        /// assert!(eight.is_power_of_two());
2254        #[doc = concat!("let ten = NonZero::new(10", stringify!($Int), ")?;")]
2255        /// assert!(!ten.is_power_of_two());
2256        /// # Some(())
2257        /// # }
2258        /// ```
2259        #[must_use]
2260        #[stable(feature = "nonzero_is_power_of_two", since = "1.59.0")]
2261        #[rustc_const_stable(feature = "nonzero_is_power_of_two", since = "1.59.0")]
2262        #[inline]
2263        pub const fn is_power_of_two(self) -> bool {
2264            // LLVM 11 normalizes `unchecked_sub(x, 1) & x == 0` to the implementation seen here.
2265            // On the basic x86-64 target, this saves 3 instructions for the zero check.
2266            // On x86_64 with BMI1, being nonzero lets it codegen to `BLSR`, which saves an instruction
2267            // compared to the `POPCNT` implementation on the underlying integer type.
2268
2269            intrinsics::ctpop(self.get()) < 2
2270        }
2271
2272        /// Returns the square root of the number, rounded down.
2273        ///
2274        /// # Examples
2275        ///
2276        /// ```
2277        /// # use std::num::NonZero;
2278        /// #
2279        /// # fn main() { test().unwrap(); }
2280        /// # fn test() -> Option<()> {
2281        #[doc = concat!("let ten = NonZero::new(10", stringify!($Int), ")?;")]
2282        #[doc = concat!("let three = NonZero::new(3", stringify!($Int), ")?;")]
2283        ///
2284        /// assert_eq!(ten.isqrt(), three);
2285        /// # Some(())
2286        /// # }
2287        /// ```
2288        #[stable(feature = "isqrt", since = "1.84.0")]
2289        #[rustc_const_stable(feature = "isqrt", since = "1.84.0")]
2290        #[must_use = "this returns the result of the operation, \
2291                      without modifying the original"]
2292        #[inline]
2293        pub const fn isqrt(self) -> Self {
2294            let result = self.get().isqrt();
2295
2296            // SAFETY: Integer square root is a monotonically nondecreasing
2297            // function, which means that increasing the input will never cause
2298            // the output to decrease. Thus, since the input for nonzero
2299            // unsigned integers has a lower bound of 1, the lower bound of the
2300            // results will be sqrt(1), which is 1, so a result can't be zero.
2301            unsafe { Self::new_unchecked(result) }
2302        }
2303
2304        /// Returns the bit pattern of `self` reinterpreted as a signed integer of the same size.
2305        ///
2306        /// # Examples
2307        ///
2308        /// ```
2309        /// # use std::num::NonZero;
2310        ///
2311        #[doc = concat!("let n = NonZero::<", stringify!($Int), ">::MAX;")]
2312        ///
2313        #[doc = concat!("assert_eq!(n.cast_signed(), NonZero::new(-1", stringify!($Sint), ").unwrap());")]
2314        /// ```
2315        #[stable(feature = "integer_sign_cast", since = "1.87.0")]
2316        #[rustc_const_stable(feature = "integer_sign_cast", since = "1.87.0")]
2317        #[must_use = "this returns the result of the operation, \
2318                      without modifying the original"]
2319        #[inline(always)]
2320        pub const fn cast_signed(self) -> NonZero<$Sint> {
2321            // SAFETY: `self.get()` can't be zero
2322            unsafe { NonZero::new_unchecked(self.get().cast_signed()) }
2323        }
2324
2325        /// Returns the minimum number of bits required to represent `self`.
2326        ///
2327        /// # Examples
2328        ///
2329        /// ```
2330        /// # use core::num::NonZero;
2331        /// #
2332        /// # fn main() { test().unwrap(); }
2333        /// # fn test() -> Option<()> {
2334        #[doc = concat!("assert_eq!(NonZero::<", stringify!($Int), ">::new(0b1)?.bit_width(), NonZero::new(1)?);")]
2335        #[doc = concat!("assert_eq!(NonZero::<", stringify!($Int), ">::new(0b111)?.bit_width(), NonZero::new(3)?);")]
2336        #[doc = concat!("assert_eq!(NonZero::<", stringify!($Int), ">::new(0b1110)?.bit_width(), NonZero::new(4)?);")]
2337        /// # Some(())
2338        /// # }
2339        /// ```
2340        #[stable(feature = "uint_bit_width", since = "1.97.0")]
2341        #[rustc_const_stable(feature = "uint_bit_width", since = "1.97.0")]
2342        #[must_use = "this returns the result of the operation, \
2343                      without modifying the original"]
2344        #[inline(always)]
2345        pub const fn bit_width(self) -> NonZero<u32> {
2346            // SAFETY: Since `self.leading_zeros()` is always less than
2347            // `Self::BITS`, this subtraction can never be zero.
2348            unsafe { NonZero::new_unchecked(Self::BITS - self.leading_zeros()) }
2349        }
2350    };
2351
2352    // Associated items for signed nonzero types only.
2353    (
2354        Primitive = signed $Int:ident,
2355        SignedPrimitive = $Sint:ty,
2356        UnsignedPrimitive = $Uint:ty,
2357    ) => {
2358        /// The smallest value that can be represented by this non-zero
2359        /// integer type,
2360        #[doc = concat!("equal to [`", stringify!($Int), "::MIN`].")]
2361        ///
2362        /// Note: While most integer types are defined for every whole
2363        /// number between `MIN` and `MAX`, signed non-zero integers are
2364        /// a special case. They have a "gap" at 0.
2365        ///
2366        /// # Examples
2367        ///
2368        /// ```
2369        /// # use std::num::NonZero;
2370        /// #
2371        #[doc = concat!("assert_eq!(NonZero::<", stringify!($Int), ">::MIN.get(), ", stringify!($Int), "::MIN);")]
2372        /// ```
2373        #[stable(feature = "nonzero_min_max", since = "1.70.0")]
2374        pub const MIN: Self = Self::new(<$Int>::MIN).unwrap();
2375
2376        /// The largest value that can be represented by this non-zero
2377        /// integer type,
2378        #[doc = concat!("equal to [`", stringify!($Int), "::MAX`].")]
2379        ///
2380        /// Note: While most integer types are defined for every whole
2381        /// number between `MIN` and `MAX`, signed non-zero integers are
2382        /// a special case. They have a "gap" at 0.
2383        ///
2384        /// # Examples
2385        ///
2386        /// ```
2387        /// # use std::num::NonZero;
2388        /// #
2389        #[doc = concat!("assert_eq!(NonZero::<", stringify!($Int), ">::MAX.get(), ", stringify!($Int), "::MAX);")]
2390        /// ```
2391        #[stable(feature = "nonzero_min_max", since = "1.70.0")]
2392        pub const MAX: Self = Self::new(<$Int>::MAX).unwrap();
2393
2394        /// Computes the absolute value of self.
2395        #[doc = concat!("See [`", stringify!($Int), "::abs`]")]
2396        /// for documentation on overflow behavior.
2397        ///
2398        /// # Example
2399        ///
2400        /// ```
2401        /// # use std::num::NonZero;
2402        /// #
2403        /// # fn main() { test().unwrap(); }
2404        /// # fn test() -> Option<()> {
2405        #[doc = concat!("let pos = NonZero::new(1", stringify!($Int), ")?;")]
2406        #[doc = concat!("let neg = NonZero::new(-1", stringify!($Int), ")?;")]
2407        ///
2408        /// assert_eq!(pos, pos.abs());
2409        /// assert_eq!(pos, neg.abs());
2410        /// # Some(())
2411        /// # }
2412        /// ```
2413        #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
2414        #[rustc_const_stable(feature = "const_nonzero_checked_ops", since = "1.64.0")]
2415        #[must_use = "this returns the result of the operation, \
2416                      without modifying the original"]
2417        #[inline]
2418        pub const fn abs(self) -> Self {
2419            // SAFETY: This cannot overflow to zero.
2420            unsafe { Self::new_unchecked(self.get().abs()) }
2421        }
2422
2423        /// Checked absolute value.
2424        /// Checks for overflow and returns [`None`] if
2425        #[doc = concat!("`self == NonZero::<", stringify!($Int), ">::MIN`.")]
2426        /// The result cannot be zero.
2427        ///
2428        /// # Example
2429        ///
2430        /// ```
2431        /// # use std::num::NonZero;
2432        /// #
2433        /// # fn main() { test().unwrap(); }
2434        /// # fn test() -> Option<()> {
2435        #[doc = concat!("let pos = NonZero::new(1", stringify!($Int), ")?;")]
2436        #[doc = concat!("let neg = NonZero::new(-1", stringify!($Int), ")?;")]
2437        #[doc = concat!("let min = NonZero::new(", stringify!($Int), "::MIN)?;")]
2438        ///
2439        /// assert_eq!(Some(pos), neg.checked_abs());
2440        /// assert_eq!(None, min.checked_abs());
2441        /// # Some(())
2442        /// # }
2443        /// ```
2444        #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
2445        #[rustc_const_stable(feature = "const_nonzero_checked_ops", since = "1.64.0")]
2446        #[must_use = "this returns the result of the operation, \
2447                      without modifying the original"]
2448        #[inline]
2449        pub const fn checked_abs(self) -> Option<Self> {
2450            if let Some(nz) = self.get().checked_abs() {
2451                // SAFETY: absolute value of nonzero cannot yield zero values.
2452                Some(unsafe { Self::new_unchecked(nz) })
2453            } else {
2454                None
2455            }
2456        }
2457
2458        /// Computes the absolute value of self,
2459        /// with overflow information, see
2460        #[doc = concat!("[`", stringify!($Int), "::overflowing_abs`].")]
2461        ///
2462        /// # Example
2463        ///
2464        /// ```
2465        /// # use std::num::NonZero;
2466        /// #
2467        /// # fn main() { test().unwrap(); }
2468        /// # fn test() -> Option<()> {
2469        #[doc = concat!("let pos = NonZero::new(1", stringify!($Int), ")?;")]
2470        #[doc = concat!("let neg = NonZero::new(-1", stringify!($Int), ")?;")]
2471        #[doc = concat!("let min = NonZero::new(", stringify!($Int), "::MIN)?;")]
2472        ///
2473        /// assert_eq!((pos, false), pos.overflowing_abs());
2474        /// assert_eq!((pos, false), neg.overflowing_abs());
2475        /// assert_eq!((min, true), min.overflowing_abs());
2476        /// # Some(())
2477        /// # }
2478        /// ```
2479        #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
2480        #[rustc_const_stable(feature = "const_nonzero_checked_ops", since = "1.64.0")]
2481        #[must_use = "this returns the result of the operation, \
2482                      without modifying the original"]
2483        #[inline]
2484        pub const fn overflowing_abs(self) -> (Self, bool) {
2485            let (nz, flag) = self.get().overflowing_abs();
2486            (
2487                // SAFETY: absolute value of nonzero cannot yield zero values.
2488                unsafe { Self::new_unchecked(nz) },
2489                flag,
2490            )
2491        }
2492
2493        /// Saturating absolute value, see
2494        #[doc = concat!("[`", stringify!($Int), "::saturating_abs`].")]
2495        ///
2496        /// # Example
2497        ///
2498        /// ```
2499        /// # use std::num::NonZero;
2500        /// #
2501        /// # fn main() { test().unwrap(); }
2502        /// # fn test() -> Option<()> {
2503        #[doc = concat!("let pos = NonZero::new(1", stringify!($Int), ")?;")]
2504        #[doc = concat!("let neg = NonZero::new(-1", stringify!($Int), ")?;")]
2505        #[doc = concat!("let min = NonZero::new(", stringify!($Int), "::MIN)?;")]
2506        #[doc = concat!("let min_plus = NonZero::new(", stringify!($Int), "::MIN + 1)?;")]
2507        #[doc = concat!("let max = NonZero::new(", stringify!($Int), "::MAX)?;")]
2508        ///
2509        /// assert_eq!(pos, pos.saturating_abs());
2510        /// assert_eq!(pos, neg.saturating_abs());
2511        /// assert_eq!(max, min.saturating_abs());
2512        /// assert_eq!(max, min_plus.saturating_abs());
2513        /// # Some(())
2514        /// # }
2515        /// ```
2516        #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
2517        #[rustc_const_stable(feature = "const_nonzero_checked_ops", since = "1.64.0")]
2518        #[must_use = "this returns the result of the operation, \
2519                      without modifying the original"]
2520        #[inline]
2521        pub const fn saturating_abs(self) -> Self {
2522            // SAFETY: absolute value of nonzero cannot yield zero values.
2523            unsafe { Self::new_unchecked(self.get().saturating_abs()) }
2524        }
2525
2526        /// Wrapping absolute value, see
2527        #[doc = concat!("[`", stringify!($Int), "::wrapping_abs`].")]
2528        ///
2529        /// # Example
2530        ///
2531        /// ```
2532        /// # use std::num::NonZero;
2533        /// #
2534        /// # fn main() { test().unwrap(); }
2535        /// # fn test() -> Option<()> {
2536        #[doc = concat!("let pos = NonZero::new(1", stringify!($Int), ")?;")]
2537        #[doc = concat!("let neg = NonZero::new(-1", stringify!($Int), ")?;")]
2538        #[doc = concat!("let min = NonZero::new(", stringify!($Int), "::MIN)?;")]
2539        #[doc = concat!("# let max = NonZero::new(", stringify!($Int), "::MAX)?;")]
2540        ///
2541        /// assert_eq!(pos, pos.wrapping_abs());
2542        /// assert_eq!(pos, neg.wrapping_abs());
2543        /// assert_eq!(min, min.wrapping_abs());
2544        /// assert_eq!(max, (-max).wrapping_abs());
2545        /// # Some(())
2546        /// # }
2547        /// ```
2548        #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
2549        #[rustc_const_stable(feature = "const_nonzero_checked_ops", since = "1.64.0")]
2550        #[must_use = "this returns the result of the operation, \
2551                      without modifying the original"]
2552        #[inline]
2553        pub const fn wrapping_abs(self) -> Self {
2554            // SAFETY: absolute value of nonzero cannot yield zero values.
2555            unsafe { Self::new_unchecked(self.get().wrapping_abs()) }
2556        }
2557
2558        /// Computes the absolute value of self
2559        /// without any wrapping or panicking.
2560        ///
2561        /// # Example
2562        ///
2563        /// ```
2564        /// # use std::num::NonZero;
2565        /// #
2566        /// # fn main() { test().unwrap(); }
2567        /// # fn test() -> Option<()> {
2568        #[doc = concat!("let u_pos = NonZero::new(1", stringify!($Uint), ")?;")]
2569        #[doc = concat!("let i_pos = NonZero::new(1", stringify!($Int), ")?;")]
2570        #[doc = concat!("let i_neg = NonZero::new(-1", stringify!($Int), ")?;")]
2571        #[doc = concat!("let i_min = NonZero::new(", stringify!($Int), "::MIN)?;")]
2572        #[doc = concat!("let u_max = NonZero::new(", stringify!($Uint), "::MAX / 2 + 1)?;")]
2573        ///
2574        /// assert_eq!(u_pos, i_pos.unsigned_abs());
2575        /// assert_eq!(u_pos, i_neg.unsigned_abs());
2576        /// assert_eq!(u_max, i_min.unsigned_abs());
2577        /// # Some(())
2578        /// # }
2579        /// ```
2580        #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
2581        #[rustc_const_stable(feature = "const_nonzero_checked_ops", since = "1.64.0")]
2582        #[must_use = "this returns the result of the operation, \
2583                      without modifying the original"]
2584        #[inline]
2585        pub const fn unsigned_abs(self) -> NonZero<$Uint> {
2586            // SAFETY: absolute value of nonzero cannot yield zero values.
2587            unsafe { NonZero::new_unchecked(self.get().unsigned_abs()) }
2588        }
2589
2590        /// Returns `true` if `self` is positive and `false` if the
2591        /// number is negative.
2592        ///
2593        /// # Example
2594        ///
2595        /// ```
2596        /// # use std::num::NonZero;
2597        /// #
2598        /// # fn main() { test().unwrap(); }
2599        /// # fn test() -> Option<()> {
2600        #[doc = concat!("let pos_five = NonZero::new(5", stringify!($Int), ")?;")]
2601        #[doc = concat!("let neg_five = NonZero::new(-5", stringify!($Int), ")?;")]
2602        ///
2603        /// assert!(pos_five.is_positive());
2604        /// assert!(!neg_five.is_positive());
2605        /// # Some(())
2606        /// # }
2607        /// ```
2608        #[must_use]
2609        #[inline]
2610        #[stable(feature = "nonzero_negation_ops", since = "1.71.0")]
2611        #[rustc_const_stable(feature = "nonzero_negation_ops", since = "1.71.0")]
2612        pub const fn is_positive(self) -> bool {
2613            self.get().is_positive()
2614        }
2615
2616        /// Returns `true` if `self` is negative and `false` if the
2617        /// number is positive.
2618        ///
2619        /// # Example
2620        ///
2621        /// ```
2622        /// # use std::num::NonZero;
2623        /// #
2624        /// # fn main() { test().unwrap(); }
2625        /// # fn test() -> Option<()> {
2626        #[doc = concat!("let pos_five = NonZero::new(5", stringify!($Int), ")?;")]
2627        #[doc = concat!("let neg_five = NonZero::new(-5", stringify!($Int), ")?;")]
2628        ///
2629        /// assert!(neg_five.is_negative());
2630        /// assert!(!pos_five.is_negative());
2631        /// # Some(())
2632        /// # }
2633        /// ```
2634        #[must_use]
2635        #[inline]
2636        #[stable(feature = "nonzero_negation_ops", since = "1.71.0")]
2637        #[rustc_const_stable(feature = "nonzero_negation_ops", since = "1.71.0")]
2638        pub const fn is_negative(self) -> bool {
2639            self.get().is_negative()
2640        }
2641
2642        /// Checked negation. Computes `-self`,
2643        #[doc = concat!("returning `None` if `self == NonZero::<", stringify!($Int), ">::MIN`.")]
2644        ///
2645        /// # Example
2646        ///
2647        /// ```
2648        /// # use std::num::NonZero;
2649        /// #
2650        /// # fn main() { test().unwrap(); }
2651        /// # fn test() -> Option<()> {
2652        #[doc = concat!("let pos_five = NonZero::new(5", stringify!($Int), ")?;")]
2653        #[doc = concat!("let neg_five = NonZero::new(-5", stringify!($Int), ")?;")]
2654        #[doc = concat!("let min = NonZero::new(", stringify!($Int), "::MIN)?;")]
2655        ///
2656        /// assert_eq!(pos_five.checked_neg(), Some(neg_five));
2657        /// assert_eq!(min.checked_neg(), None);
2658        /// # Some(())
2659        /// # }
2660        /// ```
2661        #[inline]
2662        #[stable(feature = "nonzero_negation_ops", since = "1.71.0")]
2663        #[rustc_const_stable(feature = "nonzero_negation_ops", since = "1.71.0")]
2664        pub const fn checked_neg(self) -> Option<Self> {
2665            if let Some(result) = self.get().checked_neg() {
2666                // SAFETY: negation of nonzero cannot yield zero values.
2667                return Some(unsafe { Self::new_unchecked(result) });
2668            }
2669            None
2670        }
2671
2672        /// Checked negation. Computes `-self`, panicking if `self == MIN`.
2673        ///
2674        /// # Panics
2675        ///
2676        /// ## Overflow behavior
2677        ///
2678        /// This function always panics on overflow, regardless of whether
2679        /// overflow checks are enabled.
2680        ///
2681        /// # Examples
2682        ///
2683        /// ```
2684        /// #![feature(nonzero_strict_ops)]
2685        ///
2686        /// # use std::num::NonZero;
2687        /// #
2688        /// # fn main() { test().unwrap(); }
2689        /// # fn test() -> Option<()> {
2690        #[doc = concat!("let pos_six = NonZero::new(6", stringify!($Int), ")?;")]
2691        #[doc = concat!("let neg_six = NonZero::new(-6", stringify!($Int), ")?;")]
2692        ///
2693        /// assert_eq!(pos_six.strict_neg(), neg_six);
2694        /// # Some(())
2695        /// # }
2696        /// ```
2697        ///
2698        /// The following panics because of overflow:
2699        ///
2700        /// ```should_panic
2701        /// #![feature(nonzero_strict_ops)]
2702        ///
2703        /// # use std::num::NonZero;
2704        /// #
2705        /// # fn main() { test().unwrap(); }
2706        /// # fn test() -> Option<()> {
2707        #[doc = concat!("let min = NonZero::new(", stringify!($Int), "::MIN)?;")]
2708        ///
2709        /// let _ = min.strict_neg();
2710        /// # Some(())
2711        /// # }
2712        /// ```
2713        #[unstable(feature = "nonzero_strict_ops", issue = "164850")]
2714        #[rustc_const_unstable(feature = "const_nonzero_strict_ops", issue = "164850")]
2715        #[must_use = "this returns the result of the operation, \
2716                      without modifying the original"]
2717        #[inline]
2718        #[track_caller]
2719        pub const fn strict_neg(self) -> Self {
2720            // SAFETY:
2721            // - `$Int::strict_neg` panics on overflow;
2722            // - `self` is nonzero;
2723            // - the only way to get zero from a negation without overflow
2724            //   is for the input to be zero.
2725            //
2726            // So the result cannot be zero.
2727            unsafe { Self::new_unchecked(self.get().strict_neg()) }
2728        }
2729
2730        /// Negates self, overflowing if this is equal to the minimum value.
2731        ///
2732        #[doc = concat!("See [`", stringify!($Int), "::overflowing_neg`]")]
2733        /// for documentation on overflow behavior.
2734        ///
2735        /// # Example
2736        ///
2737        /// ```
2738        /// # use std::num::NonZero;
2739        /// #
2740        /// # fn main() { test().unwrap(); }
2741        /// # fn test() -> Option<()> {
2742        #[doc = concat!("let pos_five = NonZero::new(5", stringify!($Int), ")?;")]
2743        #[doc = concat!("let neg_five = NonZero::new(-5", stringify!($Int), ")?;")]
2744        #[doc = concat!("let min = NonZero::new(", stringify!($Int), "::MIN)?;")]
2745        ///
2746        /// assert_eq!(pos_five.overflowing_neg(), (neg_five, false));
2747        /// assert_eq!(min.overflowing_neg(), (min, true));
2748        /// # Some(())
2749        /// # }
2750        /// ```
2751        #[inline]
2752        #[stable(feature = "nonzero_negation_ops", since = "1.71.0")]
2753        #[rustc_const_stable(feature = "nonzero_negation_ops", since = "1.71.0")]
2754        pub const fn overflowing_neg(self) -> (Self, bool) {
2755            let (result, overflow) = self.get().overflowing_neg();
2756            // SAFETY: negation of nonzero cannot yield zero values.
2757            ((unsafe { Self::new_unchecked(result) }), overflow)
2758        }
2759
2760        /// Saturating negation. Computes `-self`,
2761        #[doc = concat!("returning [`NonZero::<", stringify!($Int), ">::MAX`]")]
2762        #[doc = concat!("if `self == NonZero::<", stringify!($Int), ">::MIN`")]
2763        /// instead of overflowing.
2764        ///
2765        /// # Example
2766        ///
2767        /// ```
2768        /// # use std::num::NonZero;
2769        /// #
2770        /// # fn main() { test().unwrap(); }
2771        /// # fn test() -> Option<()> {
2772        #[doc = concat!("let pos_five = NonZero::new(5", stringify!($Int), ")?;")]
2773        #[doc = concat!("let neg_five = NonZero::new(-5", stringify!($Int), ")?;")]
2774        #[doc = concat!("let min = NonZero::new(", stringify!($Int), "::MIN)?;")]
2775        #[doc = concat!("let min_plus_one = NonZero::new(", stringify!($Int), "::MIN + 1)?;")]
2776        #[doc = concat!("let max = NonZero::new(", stringify!($Int), "::MAX)?;")]
2777        ///
2778        /// assert_eq!(pos_five.saturating_neg(), neg_five);
2779        /// assert_eq!(min.saturating_neg(), max);
2780        /// assert_eq!(max.saturating_neg(), min_plus_one);
2781        /// # Some(())
2782        /// # }
2783        /// ```
2784        #[inline]
2785        #[stable(feature = "nonzero_negation_ops", since = "1.71.0")]
2786        #[rustc_const_stable(feature = "nonzero_negation_ops", since = "1.71.0")]
2787        pub const fn saturating_neg(self) -> Self {
2788            if let Some(result) = self.checked_neg() {
2789                return result;
2790            }
2791            Self::MAX
2792        }
2793
2794        /// Wrapping (modular) negation. Computes `-self`, wrapping around at the boundary
2795        /// of the type.
2796        ///
2797        #[doc = concat!("See [`", stringify!($Int), "::wrapping_neg`]")]
2798        /// for documentation on overflow behavior.
2799        ///
2800        /// # Example
2801        ///
2802        /// ```
2803        /// # use std::num::NonZero;
2804        /// #
2805        /// # fn main() { test().unwrap(); }
2806        /// # fn test() -> Option<()> {
2807        #[doc = concat!("let pos_five = NonZero::new(5", stringify!($Int), ")?;")]
2808        #[doc = concat!("let neg_five = NonZero::new(-5", stringify!($Int), ")?;")]
2809        #[doc = concat!("let min = NonZero::new(", stringify!($Int), "::MIN)?;")]
2810        ///
2811        /// assert_eq!(pos_five.wrapping_neg(), neg_five);
2812        /// assert_eq!(min.wrapping_neg(), min);
2813        /// # Some(())
2814        /// # }
2815        /// ```
2816        #[inline]
2817        #[stable(feature = "nonzero_negation_ops", since = "1.71.0")]
2818        #[rustc_const_stable(feature = "nonzero_negation_ops", since = "1.71.0")]
2819        pub const fn wrapping_neg(self) -> Self {
2820            let result = self.get().wrapping_neg();
2821            // SAFETY: negation of nonzero cannot yield zero values.
2822            unsafe { Self::new_unchecked(result) }
2823        }
2824
2825        /// Returns the bit pattern of `self` reinterpreted as an unsigned integer of the same size.
2826        ///
2827        /// # Examples
2828        ///
2829        /// ```
2830        /// # use std::num::NonZero;
2831        ///
2832        #[doc = concat!("let n = NonZero::new(-1", stringify!($Int), ").unwrap();")]
2833        ///
2834        #[doc = concat!("assert_eq!(n.cast_unsigned(), NonZero::<", stringify!($Uint), ">::MAX);")]
2835        /// ```
2836        #[stable(feature = "integer_sign_cast", since = "1.87.0")]
2837        #[rustc_const_stable(feature = "integer_sign_cast", since = "1.87.0")]
2838        #[must_use = "this returns the result of the operation, \
2839                      without modifying the original"]
2840        #[inline(always)]
2841        pub const fn cast_unsigned(self) -> NonZero<$Uint> {
2842            // SAFETY: `self.get()` can't be zero
2843            unsafe { NonZero::new_unchecked(self.get().cast_unsigned()) }
2844        }
2845
2846        /// Clamps this number to a symmetric range centred around zero.
2847        ///
2848        /// The method clamps the number's magnitude (absolute value) to be at most `limit`.
2849        ///
2850        /// This is functionally equivalent to `self.clamp(-limit, limit)`, but is more
2851        /// explicit about the intent.
2852        ///
2853        /// # Examples
2854        ///
2855        /// ```
2856        /// #![feature(clamp_magnitude)]
2857        /// # use std::num::NonZero;
2858        /// #
2859        #[doc = concat!("let limit = NonZero::<", stringify!($Uint), ">::new(100).unwrap();")]
2860        ///
2861        /// assert_eq!(
2862        #[doc = concat!("    NonZero::<", stringify!($Int), ">::new(120).unwrap().clamp_magnitude(limit),")]
2863        #[doc = concat!("    NonZero::<", stringify!($Int), ">::new(100).unwrap(),")]
2864        /// );
2865        ///
2866        /// assert_eq!(
2867        #[doc = concat!("    NonZero::<", stringify!($Int), ">::new(-120).unwrap().clamp_magnitude(limit),")]
2868        #[doc = concat!("    NonZero::<", stringify!($Int), ">::new(-100).unwrap(),")]
2869        /// );
2870        ///
2871        /// assert_eq!(
2872        #[doc = concat!("    NonZero::<", stringify!($Int), ">::new(80).unwrap().clamp_magnitude(limit),")]
2873        #[doc = concat!("    NonZero::<", stringify!($Int), ">::new(80).unwrap(),")]
2874        /// );
2875        ///
2876        /// assert_eq!(
2877        #[doc = concat!("    NonZero::<", stringify!($Int), ">::new(-80).unwrap().clamp_magnitude(limit),")]
2878        #[doc = concat!("    NonZero::<", stringify!($Int), ">::new(-80).unwrap(),")]
2879        /// );
2880        /// ```
2881        #[inline]
2882        #[must_use = "method returns a new number and does not mutate the original value"]
2883        #[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
2884        #[unstable(feature = "clamp_magnitude", issue = "148519")]
2885        pub const fn clamp_magnitude(self, limit: NonZero<$Uint>) -> Self {
2886            // SAFETY: a non-zero value clamped to the magnitude of a non-zero value is still non-zero.
2887            unsafe { Self::new_unchecked(self.get().clamp_magnitude(limit.get())) }
2888        }
2889
2890    };
2891}
2892
2893#[doc = "A [`u8`] that is known not to equal zero."]
///
/// This enables some memory layout optimization.
#[doc = "For example, `Option<NonZeroU8>` is the same size as `u8`:"]
///
/// ```rust
#[doc =
"assert_eq!(size_of::<Option<core::num::NonZeroU8>>(), size_of::<u8>());"]
/// ```
///
/// # Layout
///
#[doc =
"`NonZeroU8` is guaranteed to have the same layout and bit validity as `u8`"]
/// with the exception that `0` is not a valid instance.
#[doc = "`Option<NonZeroU8>` is guaranteed to be ABI-compatible with `u8`,"]
/// including in FFI.
///
/// Thanks to the [null pointer optimization],
#[doc = "`NonZeroU8` and `Option<NonZeroU8>`"]
/// are guaranteed to have the same size and alignment:
///
/// ```
#[doc = "use std::num::NonZeroU8;"]
///
#[doc = "assert_eq!(size_of::<NonZeroU8>(), size_of::<Option<NonZeroU8>>());"]
#[doc =
"assert_eq!(align_of::<NonZeroU8>(), align_of::<Option<NonZeroU8>>());"]
/// ```
///
/// # Compile-time creation
///
/// Since both [`Option::unwrap()`] and [`Option::expect()`] are `const`, it is possible to
/// define a new
#[doc = "`NonZeroU8`"]
/// at compile time via:
/// ```
#[doc = "use std::num::NonZeroU8;"]
///
#[doc =
"const TEN: NonZeroU8 = NonZeroU8::new(10).expect(\"ten is non-zero\");"]
/// ```
///
/// [null pointer optimization]: crate::option#representation
#[stable(feature = "nonzero", since = "1.28.0")]
pub type NonZeroU8 = NonZero<u8>;
impl NonZero<u8> {
    /// The size of this non-zero integer type in bits.
    ///
    #[doc = "This value is equal to [`u8::BITS`]."]
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    #[doc = "assert_eq!(NonZero::<u8>::BITS, u8::BITS);"]
    /// ```
    #[stable(feature = "nonzero_bits", since = "1.67.0")]
    pub const BITS: u32 = <u8>::BITS;
    /// Returns the number of leading zeros in the binary representation of `self`.
    ///
    /// On many architectures, this function can perform better than `leading_zeros()` on the underlying integer type, as special handling of zero can be avoided.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::<u8>::new(u8::MAX)?;"]
    ///
    /// assert_eq!(n.leading_zeros(), 0);
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_leading_trailing_zeros", since = "1.53.0")]
    #[rustc_const_stable(feature = "nonzero_leading_trailing_zeros", since =
    "1.53.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const fn leading_zeros(self) -> u32 {
        unsafe { intrinsics::ctlz_nonzero(self.get() as u8) }
    }
    /// Returns the number of trailing zeros in the binary representation
    /// of `self`.
    ///
    /// On many architectures, this function can perform better than `trailing_zeros()` on the underlying integer type, as special handling of zero can be avoided.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::<u8>::new(0b0101000)?;"]
    ///
    /// assert_eq!(n.trailing_zeros(), 3);
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_leading_trailing_zeros", since = "1.53.0")]
    #[rustc_const_stable(feature = "nonzero_leading_trailing_zeros", since =
    "1.53.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const fn trailing_zeros(self) -> u32 {
        unsafe { intrinsics::cttz_nonzero(self.get() as u8) }
    }
    /// Returns `self` with only the most significant bit set.
    ///
    /// # Example
    ///
    /// ```
    /// # use core::num::NonZero;
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let a = NonZero::<u8>::new(0b_01100100)?;"]
    #[doc = "let b = NonZero::<u8>::new(0b_01000000)?;"]
    ///
    /// assert_eq!(a.isolate_highest_one(), b);
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "isolate_most_least_significant_one", since =
    "1.97.0")]
    #[rustc_const_stable(feature = "isolate_most_least_significant_one", since
    = "1.97.0")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn isolate_highest_one(self) -> Self {
        unsafe {
            let bit =
                (((1 as u8) <<
                                (<u8>::BITS - 1)).unchecked_shr(self.leading_zeros()));
            NonZero::new_unchecked(bit as u8)
        }
    }
    /// Returns `self` with only the least significant bit set.
    ///
    /// # Example
    ///
    /// ```
    /// # use core::num::NonZero;
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let a = NonZero::<u8>::new(0b_01100100)?;"]
    #[doc = "let b = NonZero::<u8>::new(0b_00000100)?;"]
    ///
    /// assert_eq!(a.isolate_lowest_one(), b);
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "isolate_most_least_significant_one", since =
    "1.97.0")]
    #[rustc_const_stable(feature = "isolate_most_least_significant_one", since
    = "1.97.0")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn isolate_lowest_one(self) -> Self {
        let n = self.get();
        let n = n & n.wrapping_neg();
        unsafe { NonZero::new_unchecked(n) }
    }
    /// Returns the index of the highest bit set to one in `self`.
    ///
    #[doc = "Note that this is equivalent to [`ilog2`](Self::ilog2)."]
    ///
    /// # Examples
    ///
    /// ```
    /// # use core::num::NonZero;
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "assert_eq!(NonZero::<u8>::new(0b1)?.highest_one(), 0);"]
    #[doc = "assert_eq!(NonZero::<u8>::new(0b1_0000)?.highest_one(), 4);"]
    #[doc = "assert_eq!(NonZero::<u8>::new(0b1_1111)?.highest_one(), 4);"]
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "int_lowest_highest_one", since = "1.97.0")]
    #[rustc_const_stable(feature = "int_lowest_highest_one", since =
    "1.97.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline(always)]
    pub const fn highest_one(self) -> u32 {
        Self::BITS - 1 - self.leading_zeros()
    }
    /// Returns the index of the lowest bit set to one in `self`.
    ///
    /// # Examples
    ///
    /// ```
    /// # use core::num::NonZero;
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "assert_eq!(NonZero::<u8>::new(0b1)?.lowest_one(), 0);"]
    #[doc = "assert_eq!(NonZero::<u8>::new(0b1_0000)?.lowest_one(), 4);"]
    #[doc = "assert_eq!(NonZero::<u8>::new(0b1_1111)?.lowest_one(), 0);"]
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "int_lowest_highest_one", since = "1.97.0")]
    #[rustc_const_stable(feature = "int_lowest_highest_one", since =
    "1.97.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline(always)]
    pub const fn lowest_one(self) -> u32 { self.trailing_zeros() }
    /// Returns the number of ones in the binary representation of `self`.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let a = NonZero::<u8>::new(0b100_0000)?;"]
    #[doc = "let b = NonZero::<u8>::new(0b100_0011)?;"]
    ///
    /// assert_eq!(a.count_ones(), NonZero::new(1)?);
    /// assert_eq!(b.count_ones(), NonZero::new(3)?);
    /// # Some(())
    /// # }
    /// ```
    ///
    #[stable(feature = "non_zero_count_ones", since = "1.86.0")]
    #[rustc_const_stable(feature = "non_zero_count_ones", since = "1.86.0")]
    #[doc(alias = "popcount")]
    #[doc(alias = "popcnt")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn count_ones(self) -> NonZero<u32> {
        unsafe { NonZero::new_unchecked(self.get().count_ones()) }
    }
    /// Shifts the bits to the left by a specified amount, `n`,
    /// wrapping the truncated bits to the end of the resulting integer.
    ///
    /// Please note this isn't the same operation as the `<<` shifting operator!
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x82u8)?;"]
    #[doc = "let m = NonZero::new(0xa)?;"]
    ///
    #[doc = "assert_eq!(n.rotate_left(2), m);"]
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn rotate_left(self, n: u32) -> Self {
        let result = self.get().rotate_left(n);
        unsafe { Self::new_unchecked(result) }
    }
    /// Shifts the bits to the right by a specified amount, `n`,
    /// wrapping the truncated bits to the beginning of the resulting
    /// integer.
    ///
    /// Please note this isn't the same operation as the `>>` shifting operator!
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0xau8)?;"]
    #[doc = "let m = NonZero::new(0x82)?;"]
    ///
    #[doc = "assert_eq!(n.rotate_right(2), m);"]
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn rotate_right(self, n: u32) -> Self {
        let result = self.get().rotate_right(n);
        unsafe { Self::new_unchecked(result) }
    }
    /// Reverses the byte order of the integer.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x12u8)?;"]
    /// let m = n.swap_bytes();
    ///
    #[doc = "assert_eq!(m, NonZero::new(0x12)?);"]
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn swap_bytes(self) -> Self {
        let result = self.get().swap_bytes();
        unsafe { Self::new_unchecked(result) }
    }
    /// Reverses the order of bits in the integer. The least significant bit becomes the most significant bit,
    /// second least-significant bit becomes second most-significant bit, etc.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x12u8)?;"]
    /// let m = n.reverse_bits();
    ///
    #[doc = "assert_eq!(m, NonZero::new(0x48)?);"]
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn reverse_bits(self) -> Self {
        let result = self.get().reverse_bits();
        unsafe { Self::new_unchecked(result) }
    }
    /// Converts an integer from big endian to the target's endianness.
    ///
    /// On big endian this is a no-op. On little endian the bytes are
    /// swapped.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    #[doc = "use std::num::NonZeroU8;"]
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x1Au8)?;"]
    ///
    /// if cfg!(target_endian = "big") {
    #[doc = "    assert_eq!(NonZeroU8::from_be(n), n)"]
    /// } else {
    #[doc = "    assert_eq!(NonZeroU8::from_be(n), n.swap_bytes())"]
    /// }
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use]
    #[inline(always)]
    pub const fn from_be(x: Self) -> Self {
        let result = u8::from_be(x.get());
        unsafe { Self::new_unchecked(result) }
    }
    /// Converts an integer from little endian to the target's endianness.
    ///
    /// On little endian this is a no-op. On big endian the bytes are
    /// swapped.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    #[doc = "use std::num::NonZeroU8;"]
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x1Au8)?;"]
    ///
    /// if cfg!(target_endian = "little") {
    #[doc = "    assert_eq!(NonZeroU8::from_le(n), n)"]
    /// } else {
    #[doc = "    assert_eq!(NonZeroU8::from_le(n), n.swap_bytes())"]
    /// }
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use]
    #[inline(always)]
    pub const fn from_le(x: Self) -> Self {
        let result = u8::from_le(x.get());
        unsafe { Self::new_unchecked(result) }
    }
    /// Converts `self` to big endian from the target's endianness.
    ///
    /// On big endian this is a no-op. On little endian the bytes are
    /// swapped.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x1Au8)?;"]
    ///
    /// if cfg!(target_endian = "big") {
    ///     assert_eq!(n.to_be(), n)
    /// } else {
    ///     assert_eq!(n.to_be(), n.swap_bytes())
    /// }
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn to_be(self) -> Self {
        let result = self.get().to_be();
        unsafe { Self::new_unchecked(result) }
    }
    /// Converts `self` to little endian from the target's endianness.
    ///
    /// On little endian this is a no-op. On big endian the bytes are
    /// swapped.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x1Au8)?;"]
    ///
    /// if cfg!(target_endian = "little") {
    ///     assert_eq!(n.to_le(), n)
    /// } else {
    ///     assert_eq!(n.to_le(), n.swap_bytes())
    /// }
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn to_le(self) -> Self {
        let result = self.get().to_le();
        unsafe { Self::new_unchecked(result) }
    }
    /// The smallest value that can be represented by this non-zero
    /// integer type, 1.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    #[doc = "assert_eq!(NonZero::<u8>::MIN.get(), 1u8);"]
    /// ```
    #[stable(feature = "nonzero_min_max", since = "1.70.0")]
    pub const MIN: Self = Self::new(1).unwrap();
    /// The largest value that can be represented by this non-zero
    /// integer type,
    #[doc = "equal to [`u8::MAX`]."]
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    #[doc = "assert_eq!(NonZero::<u8>::MAX.get(), u8::MAX);"]
    /// ```
    #[stable(feature = "nonzero_min_max", since = "1.70.0")]
    pub const MAX: Self = Self::new(<u8>::MAX).unwrap();
    /// Adds an unsigned integer to a non-zero value.
    /// Checks for overflow and returns [`None`] on overflow.
    /// As a consequence, the result cannot wrap to zero.
    ///
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let one = NonZero::new(1u8)?;"]
    #[doc = "let two = NonZero::new(2u8)?;"]
    #[doc = "let max = NonZero::new(u8::MAX)?;"]
    ///
    /// assert_eq!(Some(two), one.checked_add(1));
    /// assert_eq!(None, max.checked_add(1));
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const fn checked_add(self, other: u8) -> Option<Self> {
        if let Some(result) = self.get().checked_add(other) {
            Some(unsafe { Self::new_unchecked(result) })
        } else { None }
    }
    /// Adds an unsigned integer to a non-zero value, panicking
    /// if overflow occurs.
    ///
    /// # Panics
    ///
    /// ## Overflow behavior
    ///
    /// This function always panics on overflow, regardless of whether
    /// overflow checks are enabled.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_strict_ops)]
    ///
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let two = NonZero::new(2u8)?;"]
    #[doc = "let three = NonZero::new(3u8)?;"]
    ///
    /// assert_eq!(three, two.strict_add(1));
    /// # Some(())
    /// # }
    /// ```
    ///
    /// The following panics because of overflow:
    ///
    /// ```should_panic
    /// #![feature(nonzero_strict_ops)]
    ///
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let max = NonZero::new(u8::MAX)?;"]
    ///
    /// let _ = max.strict_add(1);
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_strict_ops", issue = "164850")]
    #[rustc_const_unstable(feature = "const_nonzero_strict_ops", issue =
    "164850")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    #[track_caller]
    pub const fn strict_add(self, other: u8) -> Self {
        unsafe { Self::new_unchecked(self.get().strict_add(other)) }
    }
    /// Adds an unsigned integer to a non-zero value.
    #[doc = "Return [`NonZero::<u8>::MAX`] on overflow."]
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let one = NonZero::new(1u8)?;"]
    #[doc = "let two = NonZero::new(2u8)?;"]
    #[doc = "let max = NonZero::new(u8::MAX)?;"]
    ///
    /// assert_eq!(two, one.saturating_add(1));
    /// assert_eq!(max, max.saturating_add(1));
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const fn saturating_add(self, other: u8) -> Self {
        unsafe { Self::new_unchecked(self.get().saturating_add(other)) }
    }
    /// Adds an unsigned integer to a non-zero value,
    /// assuming overflow cannot occur.
    /// Overflow is unchecked, and it is undefined behavior to overflow
    /// *even if the result would wrap to a non-zero value*.
    ///
    /// # Safety
    ///
    /// This results in undefined behavior when overflow occurs, i.e. when
    /// [`checked_add`] would return `None`.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let one = NonZero::new(1u8)?;"]
    #[doc = "let two = NonZero::new(2u8)?;"]
    ///
    /// assert_eq!(two, unsafe { one.unchecked_add(1) });
    /// # Some(())
    /// # }
    /// ```
    ///
    /// [`checked_add`]: Self::checked_add
    #[stable(feature = "nonzero_ops", since = "CURRENT_RUSTC_VERSION")]
    #[rustc_const_stable(feature = "nonzero_ops", since =
    "CURRENT_RUSTC_VERSION")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const unsafe fn unchecked_add(self, other: u8) -> Self {
        unsafe { Self::new_unchecked(self.get().unchecked_add(other)) }
    }
    /// Calculates the quotient of `self` and `rhs`, rounding the result towards positive infinity.
    ///
    /// The result is guaranteed to be non-zero.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    #[doc = "let one = NonZero::new(1u8).unwrap();"]
    #[doc = "let max = NonZero::new(u8::MAX).unwrap();"]
    /// assert_eq!(one.div_ceil(max), one);
    ///
    #[doc = "let two = NonZero::new(2u8).unwrap();"]
    #[doc = "let three = NonZero::new(3u8).unwrap();"]
    /// assert_eq!(three.div_ceil(two), two);
    /// ```
    #[stable(feature = "unsigned_nonzero_div_ceil", since = "1.92.0")]
    #[rustc_const_stable(feature = "unsigned_nonzero_div_ceil", since =
    "1.92.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const fn div_ceil(self, rhs: Self) -> Self {
        let v = (self.get() - 1) / rhs.get() + 1;
        unsafe { Self::new_unchecked(v) }
    }
    /// Returns the smallest power of two greater than or equal to `self`.
    /// Checks for overflow and returns [`None`]
    /// if the next power of two is greater than the type’s maximum value.
    /// As a consequence, the result cannot wrap to zero.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let two = NonZero::new(2u8)?;"]
    #[doc = "let three = NonZero::new(3u8)?;"]
    #[doc = "let four = NonZero::new(4u8)?;"]
    #[doc = "let max = NonZero::new(u8::MAX)?;"]
    ///
    /// assert_eq!(Some(two), two.checked_next_power_of_two() );
    /// assert_eq!(Some(four), three.checked_next_power_of_two() );
    /// assert_eq!(None, max.checked_next_power_of_two() );
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const fn checked_next_power_of_two(self) -> Option<Self> {
        if let Some(nz) = self.get().checked_next_power_of_two() {
            Some(unsafe { Self::new_unchecked(nz) })
        } else { None }
    }
    /// Returns the base 2 logarithm of the number, rounded down.
    ///
    /// This is the same operation as
    #[doc = "[`u8::ilog2`],"]
    /// except that it has no failure cases to worry about
    /// since this value can never be zero.
    ///
    /// Note that this is equivalent to [`highest_one`](Self::highest_one).
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "assert_eq!(NonZero::new(7u8)?.ilog2(), 2);"]
    #[doc = "assert_eq!(NonZero::new(8u8)?.ilog2(), 3);"]
    #[doc = "assert_eq!(NonZero::new(9u8)?.ilog2(), 3);"]
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "int_log", since = "1.67.0")]
    #[rustc_const_stable(feature = "int_log", since = "1.67.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const fn ilog2(self) -> u32 { Self::BITS - 1 - self.leading_zeros() }
    /// Returns the base 10 logarithm of the number, rounded down.
    ///
    /// This is the same operation as
    #[doc = "[`u8::ilog10`],"]
    /// except that it has no failure cases to worry about
    /// since this value can never be zero.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "assert_eq!(NonZero::new(99u8)?.ilog10(), 1);"]
    #[doc = "assert_eq!(NonZero::new(100u8)?.ilog10(), 2);"]
    #[doc = "assert_eq!(NonZero::new(101u8)?.ilog10(), 2);"]
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "int_log", since = "1.67.0")]
    #[rustc_const_stable(feature = "int_log", since = "1.67.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const fn ilog10(self) -> u32 { imp::int_log10::u8(self) }
    /// Calculates the midpoint (average) between `self` and `rhs`.
    ///
    /// `midpoint(a, b)` is `(a + b) >> 1` as if it were performed in a
    /// sufficiently-large signed integral type. This implies that the result is
    /// always rounded towards negative infinity and that no overflow will ever occur.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let one = NonZero::new(1u8)?;"]
    #[doc = "let two = NonZero::new(2u8)?;"]
    #[doc = "let four = NonZero::new(4u8)?;"]
    ///
    /// assert_eq!(one.midpoint(four), two);
    /// assert_eq!(four.midpoint(one), two);
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "num_midpoint", since = "1.85.0")]
    #[rustc_const_stable(feature = "num_midpoint", since = "1.85.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[doc(alias = "average_floor")]
    #[doc(alias = "average")]
    #[inline]
    pub const fn midpoint(self, rhs: Self) -> Self {
        unsafe { Self::new_unchecked(self.get().midpoint(rhs.get())) }
    }
    /// Returns `true` if and only if `self == (1 << k)` for some `k`.
    ///
    /// On many architectures, this function can perform better than `is_power_of_two()`
    /// on the underlying integer type, as special handling of zero can be avoided.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let eight = NonZero::new(8u8)?;"]
    /// assert!(eight.is_power_of_two());
    #[doc = "let ten = NonZero::new(10u8)?;"]
    /// assert!(!ten.is_power_of_two());
    /// # Some(())
    /// # }
    /// ```
    #[must_use]
    #[stable(feature = "nonzero_is_power_of_two", since = "1.59.0")]
    #[rustc_const_stable(feature = "nonzero_is_power_of_two", since =
    "1.59.0")]
    #[inline]
    pub const fn is_power_of_two(self) -> bool {
        intrinsics::ctpop(self.get()) < 2
    }
    /// Returns the square root of the number, rounded down.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let ten = NonZero::new(10u8)?;"]
    #[doc = "let three = NonZero::new(3u8)?;"]
    ///
    /// assert_eq!(ten.isqrt(), three);
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "isqrt", since = "1.84.0")]
    #[rustc_const_stable(feature = "isqrt", since = "1.84.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const fn isqrt(self) -> Self {
        let result = self.get().isqrt();
        unsafe { Self::new_unchecked(result) }
    }
    /// Returns the bit pattern of `self` reinterpreted as a signed integer of the same size.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    ///
    #[doc = "let n = NonZero::<u8>::MAX;"]
    ///
    #[doc = "assert_eq!(n.cast_signed(), NonZero::new(-1i8).unwrap());"]
    /// ```
    #[stable(feature = "integer_sign_cast", since = "1.87.0")]
    #[rustc_const_stable(feature = "integer_sign_cast", since = "1.87.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline(always)]
    pub const fn cast_signed(self) -> NonZero<i8> {
        unsafe { NonZero::new_unchecked(self.get().cast_signed()) }
    }
    /// Returns the minimum number of bits required to represent `self`.
    ///
    /// # Examples
    ///
    /// ```
    /// # use core::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc =
    "assert_eq!(NonZero::<u8>::new(0b1)?.bit_width(), NonZero::new(1)?);"]
    #[doc =
    "assert_eq!(NonZero::<u8>::new(0b111)?.bit_width(), NonZero::new(3)?);"]
    #[doc =
    "assert_eq!(NonZero::<u8>::new(0b1110)?.bit_width(), NonZero::new(4)?);"]
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "uint_bit_width", since = "1.97.0")]
    #[rustc_const_stable(feature = "uint_bit_width", since = "1.97.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline(always)]
    pub const fn bit_width(self) -> NonZero<u32> {
        unsafe { NonZero::new_unchecked(Self::BITS - self.leading_zeros()) }
    }
    /// Multiplies two non-zero integers together.
    /// Checks for overflow and returns [`None`] on overflow.
    /// As a consequence, the result cannot wrap to zero.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let two = NonZero::new(2u8)?;"]
    #[doc = "let four = NonZero::new(4u8)?;"]
    #[doc = "let max = NonZero::new(u8::MAX)?;"]
    ///
    /// assert_eq!(Some(four), two.checked_mul(two));
    /// assert_eq!(None, max.checked_mul(two));
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const fn checked_mul(self, other: Self) -> Option<Self> {
        if let Some(result) = self.get().checked_mul(other.get()) {
            Some(unsafe { Self::new_unchecked(result) })
        } else { None }
    }
    /// Multiplies two non-zero integers together, panicking if
    /// overflow occurs.
    ///
    /// # Panics
    ///
    /// ## Overflow behavior
    ///
    /// This function always panics on overflow, regardless of whether
    /// overflow checks are enabled.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_strict_ops)]
    ///
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let three = NonZero::new(3u8)?;"]
    #[doc = "let nine = NonZero::new(9u8)?;"]
    ///
    /// assert_eq!(nine, three.strict_mul(three));
    /// # Some(())
    /// # }
    /// ```
    ///
    /// The following panics because of overflow:
    ///
    /// ```should_panic
    /// #![feature(nonzero_strict_ops)]
    ///
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let two = NonZero::new(2u8)?;"]
    #[doc = "let max = NonZero::new(u8::MAX)?;"]
    ///
    /// let _ = max.strict_mul(two);
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_strict_ops", issue = "164850")]
    #[rustc_const_unstable(feature = "const_nonzero_strict_ops", issue =
    "164850")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    #[track_caller]
    pub const fn strict_mul(self, other: Self) -> Self {
        unsafe { Self::new_unchecked(self.get().strict_mul(other.get())) }
    }
    /// Multiplies two non-zero integers together.
    #[doc = "Return [`NonZero::<u8>::MAX`] on overflow."]
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let two = NonZero::new(2u8)?;"]
    #[doc = "let four = NonZero::new(4u8)?;"]
    #[doc = "let max = NonZero::new(u8::MAX)?;"]
    ///
    /// assert_eq!(four, two.saturating_mul(two));
    /// assert_eq!(max, four.saturating_mul(max));
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const fn saturating_mul(self, other: Self) -> Self {
        unsafe { Self::new_unchecked(self.get().saturating_mul(other.get())) }
    }
    /// Multiplies two non-zero integers together,
    /// assuming overflow cannot occur.
    /// Overflow is unchecked, and it is undefined behavior to overflow
    /// *even if the result would wrap to a non-zero value*.
    ///
    /// # Safety
    ///
    /// This results in undefined behavior when overflow occurs, i.e.
    /// when [`checked_mul`] would return `None`.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let two = NonZero::new(2u8)?;"]
    #[doc = "let four = NonZero::new(4u8)?;"]
    ///
    /// assert_eq!(four, unsafe { two.unchecked_mul(two) });
    /// # Some(())
    /// # }
    /// ```
    ///
    /// [`checked_mul`]: Self::checked_mul
    #[stable(feature = "nonzero_ops", since = "CURRENT_RUSTC_VERSION")]
    #[rustc_const_stable(feature = "nonzero_ops", since =
    "CURRENT_RUSTC_VERSION")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const unsafe fn unchecked_mul(self, other: Self) -> Self {
        unsafe { Self::new_unchecked(self.get().unchecked_mul(other.get())) }
    }
    /// Raises non-zero value to an integer power.
    /// Checks for overflow and returns [`None`] on overflow.
    /// As a consequence, the result cannot wrap to zero.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let three = NonZero::new(3u8)?;"]
    #[doc = "let twenty_seven = NonZero::new(27u8)?;"]
    #[doc = "let half_max = NonZero::new(u8::MAX / 2)?;"]
    ///
    /// assert_eq!(Some(twenty_seven), three.checked_pow(3));
    /// assert_eq!(None, half_max.checked_pow(3));
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const fn checked_pow(self, other: u32) -> Option<Self> {
        if let Some(result) = self.get().checked_pow(other) {
            Some(unsafe { Self::new_unchecked(result) })
        } else { None }
    }
    /// Raises a non-zero value to an integer power, panicking if
    /// overflow occurs.
    ///
    /// # Panics
    ///
    /// ## Overflow behavior
    ///
    /// This function always panics on overflow, regardless of whether
    /// overflow checks are enabled.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_strict_ops)]
    ///
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let two = NonZero::new(2u8)?;"]
    #[doc = "let sixteen = NonZero::new(16u8)?;"]
    ///
    /// assert_eq!(sixteen, two.strict_pow(4));
    /// # Some(())
    /// # }
    /// ```
    ///
    /// The following panics because of overflow:
    ///
    /// ```should_panic
    /// #![feature(nonzero_strict_ops)]
    ///
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let half_max = NonZero::new(u8::MAX / 2)?;"]
    ///
    /// let _ = half_max.strict_pow(2);
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_strict_ops", issue = "164850")]
    #[rustc_const_unstable(feature = "const_nonzero_strict_ops", issue =
    "164850")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    #[track_caller]
    pub const fn strict_pow(self, exp: u32) -> Self {
        unsafe { Self::new_unchecked(self.get().strict_pow(exp)) }
    }
    /// Raise non-zero value to an integer power.
    #[doc = "Return [`NonZero::<u8>::MAX`] on overflow."]
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let three = NonZero::new(3u8)?;"]
    #[doc = "let twenty_seven = NonZero::new(27u8)?;"]
    #[doc = "let max = NonZero::new(u8::MAX)?;"]
    ///
    /// assert_eq!(twenty_seven, three.saturating_pow(3));
    /// assert_eq!(max, max.saturating_pow(3));
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const fn saturating_pow(self, other: u32) -> Self {
        unsafe { Self::new_unchecked(self.get().saturating_pow(other)) }
    }
    /// Parses a non-zero integer from an ASCII-byte slice with decimal digits.
    ///
    /// The characters are expected to be an optional
    #[doc = " `+` "]
    /// sign followed by only digits. Leading and trailing non-digit characters (including
    /// whitespace) represent an error. Underscores (which are accepted in Rust literals)
    /// also represent an error.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc =
    "assert_eq!(NonZero::<u8>::from_ascii_bytes(b\"+10\"), Ok(NonZero::new(10)?));"]
    /// # Some(())
    /// # }
    /// ```
    ///
    /// Trailing space returns error:
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    #[doc = "assert!(NonZero::<u8>::from_ascii_bytes(b\"1 \").is_err());"]
    /// ```
    #[stable(feature = "int_from_ascii", since = "CURRENT_RUSTC_VERSION")]
    #[rustc_const_unstable(feature = "const_convert", issue = "143773")]
    #[inline]
    pub const fn from_ascii_bytes<T>(src: T) -> Result<Self, ParseIntError>
        where T: [const] AsRef<[u8]> + [const] crate::marker::Destruct {
        Self::from_ascii_bytes_radix_impl(src.as_ref(), 10)
    }
    /// Parses a non-zero integer from an ASCII-byte slice with digits in a given base.
    ///
    /// The characters are expected to be an optional
    #[doc = " `+` "]
    /// sign followed by only digits. Leading and trailing non-digit characters (including
    /// whitespace) represent an error. Underscores (which are accepted in Rust literals)
    /// also represent an error.
    ///
    /// Digits are a subset of these characters, depending on `radix`:
    ///
    /// - `0-9`
    /// - `a-z`
    /// - `A-Z`
    ///
    /// # Panics
    ///
    /// This method panics if `radix` is not in the range from 2 to 36.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc =
    "assert_eq!(NonZero::<u8>::from_ascii_bytes_radix(b\"A\", 16), Ok(NonZero::new(10)?));"]
    /// # Some(())
    /// # }
    /// ```
    ///
    /// Trailing space returns error:
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    #[doc =
    "assert!(NonZero::<u8>::from_ascii_bytes_radix(b\"1 \", 10).is_err());"]
    /// ```
    #[stable(feature = "int_from_ascii", since = "CURRENT_RUSTC_VERSION")]
    #[rustc_const_unstable(feature = "const_convert", issue = "143773")]
    #[inline]
    pub const fn from_ascii_bytes_radix<T>(src: T, radix: u32)
        -> Result<Self, ParseIntError> where T: [const] AsRef<[u8]> + [const]
        crate::marker::Destruct {
        Self::from_ascii_bytes_radix_impl(src.as_ref(), radix)
    }
    #[inline]
    const fn from_ascii_bytes_radix_impl(src: &[u8], radix: u32)
        -> Result<Self, ParseIntError> {
        let n =
            match <u8>::from_ascii_bytes_radix_impl(src, radix) {
                Ok(n) => n,
                Err(err) => return Err(err),
            };
        if let Some(n) = Self::new(n) {
            Ok(n)
        } else { Err(ParseIntError { kind: IntErrorKind::Zero }) }
    }
    /// Parses a non-zero integer from a string slice with digits in a given base.
    ///
    /// The string is expected to be an optional
    #[doc = " `+` "]
    /// sign followed by only digits. Leading and trailing non-digit characters (including
    /// whitespace) represent an error. Underscores (which are accepted in Rust literals)
    /// also represent an error.
    ///
    /// Digits are a subset of these characters, depending on `radix`:
    ///
    /// - `0-9`
    /// - `a-z`
    /// - `A-Z`
    ///
    /// # Panics
    ///
    /// This method panics if `radix` is not in the range from 2 to 36.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc =
    "assert_eq!(NonZero::<u8>::from_str_radix(\"A\", 16), Ok(NonZero::new(10)?));"]
    /// # Some(())
    /// # }
    /// ```
    ///
    /// Trailing space returns error:
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    #[doc = "assert!(NonZero::<u8>::from_str_radix(\"1 \", 10).is_err());"]
    /// ```
    #[stable(feature = "nonzero_from_str_radix", since = "1.98.0")]
    #[rustc_const_stable(feature = "nonzero_from_str_radix", since =
    "1.98.0")]
    #[inline]
    pub const fn from_str_radix(src: &str, radix: u32)
        -> Result<Self, ParseIntError> {
        Self::from_ascii_bytes_radix_impl(src.as_bytes(), radix)
    }
}
#[stable(feature = "nonzero_parse", since = "1.35.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl FromStr for NonZero<u8> {
    type Err = ParseIntError;
    /// Parses a non-zero integer from a string slice with decimal digits.
    ///
    /// The characters are expected to be an optional
    #[doc = " `+` "]
    /// sign followed by only digits. Leading and trailing non-digit characters (including
    /// whitespace) represent an error. Underscores (which are accepted in Rust literals)
    /// also represent an error.
    ///
    /// # Examples
    ///
    /// ```
    /// use std::num::NonZero;
    /// use std::str::FromStr;
    ///
    #[doc =
    "assert_eq!(NonZero::<u8>::from_str(\"+10\"), Ok(NonZero::new(10).unwrap()));"]
    /// ```
    ///
    /// Trailing space returns error:
    ///
    /// ```
    /// use std::num::NonZero;
    /// use std::str::FromStr;
    ///
    #[doc = "assert!(NonZero::<u8>::from_str(\"1 \").is_err());"]
    /// ```
    #[inline]
    fn from_str(src: &str) -> Result<Self, Self::Err> {
        Self::from_str_radix(src, 10)
    }
}
#[stable(feature = "nonzero_div", since = "1.51.0")]
#[rustc_const_unstable(feature = "const_ops", issue = "143802")]
const impl Div<NonZero<u8>> for u8 {
    type Output = u8;
    /// Same as `self / other.get()`, but because `other` is a `NonZero<_>`,
    /// there's never a runtime check for division-by-zero.
    ///
    /// This operation rounds towards zero, truncating any fractional
    /// part of the exact result, and cannot panic.
    #[doc(alias = "unchecked_div")]
    #[inline]
    fn div(self, other: NonZero<u8>) -> u8 {
        unsafe { intrinsics::unchecked_div(self, other.get()) }
    }
}
#[stable(feature = "nonzero_div_assign", since = "1.79.0")]
#[rustc_const_unstable(feature = "const_ops", issue = "143802")]
const impl DivAssign<NonZero<u8>> for u8 {
    /// Same as `self /= other.get()`, but because `other` is a `NonZero<_>`,
    /// there's never a runtime check for division-by-zero.
    ///
    /// This operation rounds towards zero, truncating any fractional
    /// part of the exact result, and cannot panic.
    #[inline]
    fn div_assign(&mut self, other: NonZero<u8>) { *self = *self / other; }
}
#[stable(feature = "nonzero_div", since = "1.51.0")]
#[rustc_const_unstable(feature = "const_ops", issue = "143802")]
const impl Rem<NonZero<u8>> for u8 {
    type Output = u8;
    /// This operation satisfies `n % d == n - (n / d) * d`, and cannot panic.
    #[inline]
    fn rem(self, other: NonZero<u8>) -> u8 {
        unsafe { intrinsics::unchecked_rem(self, other.get()) }
    }
}
#[stable(feature = "nonzero_div_assign", since = "1.79.0")]
#[rustc_const_unstable(feature = "const_ops", issue = "143802")]
const impl RemAssign<NonZero<u8>> for u8 {
    /// This operation satisfies `n % d == n - (n / d) * d`, and cannot panic.
    #[inline]
    fn rem_assign(&mut self, other: NonZero<u8>) { *self = *self % other; }
}nonzero_integer! {
2894    Self = NonZeroU8,
2895    Primitive = unsigned u8,
2896    SignedPrimitive = i8,
2897    rot = 2,
2898    rot_op = "0x82",
2899    rot_result = "0xa",
2900    swap_op = "0x12",
2901    swapped = "0x12",
2902    reversed = "0x48",
2903}
2904
2905#[doc = "A [`u16`] that is known not to equal zero."]
///
/// This enables some memory layout optimization.
#[doc = "For example, `Option<NonZeroU16>` is the same size as `u16`:"]
///
/// ```rust
#[doc =
"assert_eq!(size_of::<Option<core::num::NonZeroU16>>(), size_of::<u16>());"]
/// ```
///
/// # Layout
///
#[doc =
"`NonZeroU16` is guaranteed to have the same layout and bit validity as `u16`"]
/// with the exception that `0` is not a valid instance.
#[doc = "`Option<NonZeroU16>` is guaranteed to be ABI-compatible with `u16`,"]
/// including in FFI.
///
/// Thanks to the [null pointer optimization],
#[doc = "`NonZeroU16` and `Option<NonZeroU16>`"]
/// are guaranteed to have the same size and alignment:
///
/// ```
#[doc = "use std::num::NonZeroU16;"]
///
#[doc =
"assert_eq!(size_of::<NonZeroU16>(), size_of::<Option<NonZeroU16>>());"]
#[doc =
"assert_eq!(align_of::<NonZeroU16>(), align_of::<Option<NonZeroU16>>());"]
/// ```
///
/// # Compile-time creation
///
/// Since both [`Option::unwrap()`] and [`Option::expect()`] are `const`, it is possible to
/// define a new
#[doc = "`NonZeroU16`"]
/// at compile time via:
/// ```
#[doc = "use std::num::NonZeroU16;"]
///
#[doc =
"const TEN: NonZeroU16 = NonZeroU16::new(10).expect(\"ten is non-zero\");"]
/// ```
///
/// [null pointer optimization]: crate::option#representation
#[stable(feature = "nonzero", since = "1.28.0")]
pub type NonZeroU16 = NonZero<u16>;
impl NonZero<u16> {
    /// The size of this non-zero integer type in bits.
    ///
    #[doc = "This value is equal to [`u16::BITS`]."]
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    #[doc = "assert_eq!(NonZero::<u16>::BITS, u16::BITS);"]
    /// ```
    #[stable(feature = "nonzero_bits", since = "1.67.0")]
    pub const BITS: u32 = <u16>::BITS;
    /// Returns the number of leading zeros in the binary representation of `self`.
    ///
    /// On many architectures, this function can perform better than `leading_zeros()` on the underlying integer type, as special handling of zero can be avoided.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::<u16>::new(u16::MAX)?;"]
    ///
    /// assert_eq!(n.leading_zeros(), 0);
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_leading_trailing_zeros", since = "1.53.0")]
    #[rustc_const_stable(feature = "nonzero_leading_trailing_zeros", since =
    "1.53.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const fn leading_zeros(self) -> u32 {
        unsafe { intrinsics::ctlz_nonzero(self.get() as u16) }
    }
    /// Returns the number of trailing zeros in the binary representation
    /// of `self`.
    ///
    /// On many architectures, this function can perform better than `trailing_zeros()` on the underlying integer type, as special handling of zero can be avoided.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::<u16>::new(0b0101000)?;"]
    ///
    /// assert_eq!(n.trailing_zeros(), 3);
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_leading_trailing_zeros", since = "1.53.0")]
    #[rustc_const_stable(feature = "nonzero_leading_trailing_zeros", since =
    "1.53.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const fn trailing_zeros(self) -> u32 {
        unsafe { intrinsics::cttz_nonzero(self.get() as u16) }
    }
    /// Returns `self` with only the most significant bit set.
    ///
    /// # Example
    ///
    /// ```
    /// # use core::num::NonZero;
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let a = NonZero::<u16>::new(0b_01100100)?;"]
    #[doc = "let b = NonZero::<u16>::new(0b_01000000)?;"]
    ///
    /// assert_eq!(a.isolate_highest_one(), b);
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "isolate_most_least_significant_one", since =
    "1.97.0")]
    #[rustc_const_stable(feature = "isolate_most_least_significant_one", since
    = "1.97.0")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn isolate_highest_one(self) -> Self {
        unsafe {
            let bit =
                (((1 as u16) <<
                                (<u16>::BITS - 1)).unchecked_shr(self.leading_zeros()));
            NonZero::new_unchecked(bit as u16)
        }
    }
    /// Returns `self` with only the least significant bit set.
    ///
    /// # Example
    ///
    /// ```
    /// # use core::num::NonZero;
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let a = NonZero::<u16>::new(0b_01100100)?;"]
    #[doc = "let b = NonZero::<u16>::new(0b_00000100)?;"]
    ///
    /// assert_eq!(a.isolate_lowest_one(), b);
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "isolate_most_least_significant_one", since =
    "1.97.0")]
    #[rustc_const_stable(feature = "isolate_most_least_significant_one", since
    = "1.97.0")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn isolate_lowest_one(self) -> Self {
        let n = self.get();
        let n = n & n.wrapping_neg();
        unsafe { NonZero::new_unchecked(n) }
    }
    /// Returns the index of the highest bit set to one in `self`.
    ///
    #[doc = "Note that this is equivalent to [`ilog2`](Self::ilog2)."]
    ///
    /// # Examples
    ///
    /// ```
    /// # use core::num::NonZero;
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "assert_eq!(NonZero::<u16>::new(0b1)?.highest_one(), 0);"]
    #[doc = "assert_eq!(NonZero::<u16>::new(0b1_0000)?.highest_one(), 4);"]
    #[doc = "assert_eq!(NonZero::<u16>::new(0b1_1111)?.highest_one(), 4);"]
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "int_lowest_highest_one", since = "1.97.0")]
    #[rustc_const_stable(feature = "int_lowest_highest_one", since =
    "1.97.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline(always)]
    pub const fn highest_one(self) -> u32 {
        Self::BITS - 1 - self.leading_zeros()
    }
    /// Returns the index of the lowest bit set to one in `self`.
    ///
    /// # Examples
    ///
    /// ```
    /// # use core::num::NonZero;
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "assert_eq!(NonZero::<u16>::new(0b1)?.lowest_one(), 0);"]
    #[doc = "assert_eq!(NonZero::<u16>::new(0b1_0000)?.lowest_one(), 4);"]
    #[doc = "assert_eq!(NonZero::<u16>::new(0b1_1111)?.lowest_one(), 0);"]
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "int_lowest_highest_one", since = "1.97.0")]
    #[rustc_const_stable(feature = "int_lowest_highest_one", since =
    "1.97.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline(always)]
    pub const fn lowest_one(self) -> u32 { self.trailing_zeros() }
    /// Returns the number of ones in the binary representation of `self`.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let a = NonZero::<u16>::new(0b100_0000)?;"]
    #[doc = "let b = NonZero::<u16>::new(0b100_0011)?;"]
    ///
    /// assert_eq!(a.count_ones(), NonZero::new(1)?);
    /// assert_eq!(b.count_ones(), NonZero::new(3)?);
    /// # Some(())
    /// # }
    /// ```
    ///
    #[stable(feature = "non_zero_count_ones", since = "1.86.0")]
    #[rustc_const_stable(feature = "non_zero_count_ones", since = "1.86.0")]
    #[doc(alias = "popcount")]
    #[doc(alias = "popcnt")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn count_ones(self) -> NonZero<u32> {
        unsafe { NonZero::new_unchecked(self.get().count_ones()) }
    }
    /// Shifts the bits to the left by a specified amount, `n`,
    /// wrapping the truncated bits to the end of the resulting integer.
    ///
    /// Please note this isn't the same operation as the `<<` shifting operator!
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0xa003u16)?;"]
    #[doc = "let m = NonZero::new(0x3a)?;"]
    ///
    #[doc = "assert_eq!(n.rotate_left(4), m);"]
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn rotate_left(self, n: u32) -> Self {
        let result = self.get().rotate_left(n);
        unsafe { Self::new_unchecked(result) }
    }
    /// Shifts the bits to the right by a specified amount, `n`,
    /// wrapping the truncated bits to the beginning of the resulting
    /// integer.
    ///
    /// Please note this isn't the same operation as the `>>` shifting operator!
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x3au16)?;"]
    #[doc = "let m = NonZero::new(0xa003)?;"]
    ///
    #[doc = "assert_eq!(n.rotate_right(4), m);"]
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn rotate_right(self, n: u32) -> Self {
        let result = self.get().rotate_right(n);
        unsafe { Self::new_unchecked(result) }
    }
    /// Reverses the byte order of the integer.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x1234u16)?;"]
    /// let m = n.swap_bytes();
    ///
    #[doc = "assert_eq!(m, NonZero::new(0x3412)?);"]
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn swap_bytes(self) -> Self {
        let result = self.get().swap_bytes();
        unsafe { Self::new_unchecked(result) }
    }
    /// Reverses the order of bits in the integer. The least significant bit becomes the most significant bit,
    /// second least-significant bit becomes second most-significant bit, etc.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x1234u16)?;"]
    /// let m = n.reverse_bits();
    ///
    #[doc = "assert_eq!(m, NonZero::new(0x2c48)?);"]
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn reverse_bits(self) -> Self {
        let result = self.get().reverse_bits();
        unsafe { Self::new_unchecked(result) }
    }
    /// Converts an integer from big endian to the target's endianness.
    ///
    /// On big endian this is a no-op. On little endian the bytes are
    /// swapped.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    #[doc = "use std::num::NonZeroU16;"]
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x1Au16)?;"]
    ///
    /// if cfg!(target_endian = "big") {
    #[doc = "    assert_eq!(NonZeroU16::from_be(n), n)"]
    /// } else {
    #[doc = "    assert_eq!(NonZeroU16::from_be(n), n.swap_bytes())"]
    /// }
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use]
    #[inline(always)]
    pub const fn from_be(x: Self) -> Self {
        let result = u16::from_be(x.get());
        unsafe { Self::new_unchecked(result) }
    }
    /// Converts an integer from little endian to the target's endianness.
    ///
    /// On little endian this is a no-op. On big endian the bytes are
    /// swapped.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    #[doc = "use std::num::NonZeroU16;"]
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x1Au16)?;"]
    ///
    /// if cfg!(target_endian = "little") {
    #[doc = "    assert_eq!(NonZeroU16::from_le(n), n)"]
    /// } else {
    #[doc = "    assert_eq!(NonZeroU16::from_le(n), n.swap_bytes())"]
    /// }
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use]
    #[inline(always)]
    pub const fn from_le(x: Self) -> Self {
        let result = u16::from_le(x.get());
        unsafe { Self::new_unchecked(result) }
    }
    /// Converts `self` to big endian from the target's endianness.
    ///
    /// On big endian this is a no-op. On little endian the bytes are
    /// swapped.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x1Au16)?;"]
    ///
    /// if cfg!(target_endian = "big") {
    ///     assert_eq!(n.to_be(), n)
    /// } else {
    ///     assert_eq!(n.to_be(), n.swap_bytes())
    /// }
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn to_be(self) -> Self {
        let result = self.get().to_be();
        unsafe { Self::new_unchecked(result) }
    }
    /// Converts `self` to little endian from the target's endianness.
    ///
    /// On little endian this is a no-op. On big endian the bytes are
    /// swapped.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x1Au16)?;"]
    ///
    /// if cfg!(target_endian = "little") {
    ///     assert_eq!(n.to_le(), n)
    /// } else {
    ///     assert_eq!(n.to_le(), n.swap_bytes())
    /// }
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn to_le(self) -> Self {
        let result = self.get().to_le();
        unsafe { Self::new_unchecked(result) }
    }
    /// The smallest value that can be represented by this non-zero
    /// integer type, 1.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    #[doc = "assert_eq!(NonZero::<u16>::MIN.get(), 1u16);"]
    /// ```
    #[stable(feature = "nonzero_min_max", since = "1.70.0")]
    pub const MIN: Self = Self::new(1).unwrap();
    /// The largest value that can be represented by this non-zero
    /// integer type,
    #[doc = "equal to [`u16::MAX`]."]
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    #[doc = "assert_eq!(NonZero::<u16>::MAX.get(), u16::MAX);"]
    /// ```
    #[stable(feature = "nonzero_min_max", since = "1.70.0")]
    pub const MAX: Self = Self::new(<u16>::MAX).unwrap();
    /// Adds an unsigned integer to a non-zero value.
    /// Checks for overflow and returns [`None`] on overflow.
    /// As a consequence, the result cannot wrap to zero.
    ///
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let one = NonZero::new(1u16)?;"]
    #[doc = "let two = NonZero::new(2u16)?;"]
    #[doc = "let max = NonZero::new(u16::MAX)?;"]
    ///
    /// assert_eq!(Some(two), one.checked_add(1));
    /// assert_eq!(None, max.checked_add(1));
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const fn checked_add(self, other: u16) -> Option<Self> {
        if let Some(result) = self.get().checked_add(other) {
            Some(unsafe { Self::new_unchecked(result) })
        } else { None }
    }
    /// Adds an unsigned integer to a non-zero value, panicking
    /// if overflow occurs.
    ///
    /// # Panics
    ///
    /// ## Overflow behavior
    ///
    /// This function always panics on overflow, regardless of whether
    /// overflow checks are enabled.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_strict_ops)]
    ///
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let two = NonZero::new(2u16)?;"]
    #[doc = "let three = NonZero::new(3u16)?;"]
    ///
    /// assert_eq!(three, two.strict_add(1));
    /// # Some(())
    /// # }
    /// ```
    ///
    /// The following panics because of overflow:
    ///
    /// ```should_panic
    /// #![feature(nonzero_strict_ops)]
    ///
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let max = NonZero::new(u16::MAX)?;"]
    ///
    /// let _ = max.strict_add(1);
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_strict_ops", issue = "164850")]
    #[rustc_const_unstable(feature = "const_nonzero_strict_ops", issue =
    "164850")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    #[track_caller]
    pub const fn strict_add(self, other: u16) -> Self {
        unsafe { Self::new_unchecked(self.get().strict_add(other)) }
    }
    /// Adds an unsigned integer to a non-zero value.
    #[doc = "Return [`NonZero::<u16>::MAX`] on overflow."]
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let one = NonZero::new(1u16)?;"]
    #[doc = "let two = NonZero::new(2u16)?;"]
    #[doc = "let max = NonZero::new(u16::MAX)?;"]
    ///
    /// assert_eq!(two, one.saturating_add(1));
    /// assert_eq!(max, max.saturating_add(1));
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const fn saturating_add(self, other: u16) -> Self {
        unsafe { Self::new_unchecked(self.get().saturating_add(other)) }
    }
    /// Adds an unsigned integer to a non-zero value,
    /// assuming overflow cannot occur.
    /// Overflow is unchecked, and it is undefined behavior to overflow
    /// *even if the result would wrap to a non-zero value*.
    ///
    /// # Safety
    ///
    /// This results in undefined behavior when overflow occurs, i.e. when
    /// [`checked_add`] would return `None`.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let one = NonZero::new(1u16)?;"]
    #[doc = "let two = NonZero::new(2u16)?;"]
    ///
    /// assert_eq!(two, unsafe { one.unchecked_add(1) });
    /// # Some(())
    /// # }
    /// ```
    ///
    /// [`checked_add`]: Self::checked_add
    #[stable(feature = "nonzero_ops", since = "CURRENT_RUSTC_VERSION")]
    #[rustc_const_stable(feature = "nonzero_ops", since =
    "CURRENT_RUSTC_VERSION")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const unsafe fn unchecked_add(self, other: u16) -> Self {
        unsafe { Self::new_unchecked(self.get().unchecked_add(other)) }
    }
    /// Calculates the quotient of `self` and `rhs`, rounding the result towards positive infinity.
    ///
    /// The result is guaranteed to be non-zero.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    #[doc = "let one = NonZero::new(1u16).unwrap();"]
    #[doc = "let max = NonZero::new(u16::MAX).unwrap();"]
    /// assert_eq!(one.div_ceil(max), one);
    ///
    #[doc = "let two = NonZero::new(2u16).unwrap();"]
    #[doc = "let three = NonZero::new(3u16).unwrap();"]
    /// assert_eq!(three.div_ceil(two), two);
    /// ```
    #[stable(feature = "unsigned_nonzero_div_ceil", since = "1.92.0")]
    #[rustc_const_stable(feature = "unsigned_nonzero_div_ceil", since =
    "1.92.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const fn div_ceil(self, rhs: Self) -> Self {
        let v = (self.get() - 1) / rhs.get() + 1;
        unsafe { Self::new_unchecked(v) }
    }
    /// Returns the smallest power of two greater than or equal to `self`.
    /// Checks for overflow and returns [`None`]
    /// if the next power of two is greater than the type’s maximum value.
    /// As a consequence, the result cannot wrap to zero.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let two = NonZero::new(2u16)?;"]
    #[doc = "let three = NonZero::new(3u16)?;"]
    #[doc = "let four = NonZero::new(4u16)?;"]
    #[doc = "let max = NonZero::new(u16::MAX)?;"]
    ///
    /// assert_eq!(Some(two), two.checked_next_power_of_two() );
    /// assert_eq!(Some(four), three.checked_next_power_of_two() );
    /// assert_eq!(None, max.checked_next_power_of_two() );
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const fn checked_next_power_of_two(self) -> Option<Self> {
        if let Some(nz) = self.get().checked_next_power_of_two() {
            Some(unsafe { Self::new_unchecked(nz) })
        } else { None }
    }
    /// Returns the base 2 logarithm of the number, rounded down.
    ///
    /// This is the same operation as
    #[doc = "[`u16::ilog2`],"]
    /// except that it has no failure cases to worry about
    /// since this value can never be zero.
    ///
    /// Note that this is equivalent to [`highest_one`](Self::highest_one).
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "assert_eq!(NonZero::new(7u16)?.ilog2(), 2);"]
    #[doc = "assert_eq!(NonZero::new(8u16)?.ilog2(), 3);"]
    #[doc = "assert_eq!(NonZero::new(9u16)?.ilog2(), 3);"]
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "int_log", since = "1.67.0")]
    #[rustc_const_stable(feature = "int_log", since = "1.67.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const fn ilog2(self) -> u32 { Self::BITS - 1 - self.leading_zeros() }
    /// Returns the base 10 logarithm of the number, rounded down.
    ///
    /// This is the same operation as
    #[doc = "[`u16::ilog10`],"]
    /// except that it has no failure cases to worry about
    /// since this value can never be zero.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "assert_eq!(NonZero::new(99u16)?.ilog10(), 1);"]
    #[doc = "assert_eq!(NonZero::new(100u16)?.ilog10(), 2);"]
    #[doc = "assert_eq!(NonZero::new(101u16)?.ilog10(), 2);"]
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "int_log", since = "1.67.0")]
    #[rustc_const_stable(feature = "int_log", since = "1.67.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const fn ilog10(self) -> u32 { imp::int_log10::u16(self) }
    /// Calculates the midpoint (average) between `self` and `rhs`.
    ///
    /// `midpoint(a, b)` is `(a + b) >> 1` as if it were performed in a
    /// sufficiently-large signed integral type. This implies that the result is
    /// always rounded towards negative infinity and that no overflow will ever occur.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let one = NonZero::new(1u16)?;"]
    #[doc = "let two = NonZero::new(2u16)?;"]
    #[doc = "let four = NonZero::new(4u16)?;"]
    ///
    /// assert_eq!(one.midpoint(four), two);
    /// assert_eq!(four.midpoint(one), two);
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "num_midpoint", since = "1.85.0")]
    #[rustc_const_stable(feature = "num_midpoint", since = "1.85.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[doc(alias = "average_floor")]
    #[doc(alias = "average")]
    #[inline]
    pub const fn midpoint(self, rhs: Self) -> Self {
        unsafe { Self::new_unchecked(self.get().midpoint(rhs.get())) }
    }
    /// Returns `true` if and only if `self == (1 << k)` for some `k`.
    ///
    /// On many architectures, this function can perform better than `is_power_of_two()`
    /// on the underlying integer type, as special handling of zero can be avoided.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let eight = NonZero::new(8u16)?;"]
    /// assert!(eight.is_power_of_two());
    #[doc = "let ten = NonZero::new(10u16)?;"]
    /// assert!(!ten.is_power_of_two());
    /// # Some(())
    /// # }
    /// ```
    #[must_use]
    #[stable(feature = "nonzero_is_power_of_two", since = "1.59.0")]
    #[rustc_const_stable(feature = "nonzero_is_power_of_two", since =
    "1.59.0")]
    #[inline]
    pub const fn is_power_of_two(self) -> bool {
        intrinsics::ctpop(self.get()) < 2
    }
    /// Returns the square root of the number, rounded down.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let ten = NonZero::new(10u16)?;"]
    #[doc = "let three = NonZero::new(3u16)?;"]
    ///
    /// assert_eq!(ten.isqrt(), three);
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "isqrt", since = "1.84.0")]
    #[rustc_const_stable(feature = "isqrt", since = "1.84.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const fn isqrt(self) -> Self {
        let result = self.get().isqrt();
        unsafe { Self::new_unchecked(result) }
    }
    /// Returns the bit pattern of `self` reinterpreted as a signed integer of the same size.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    ///
    #[doc = "let n = NonZero::<u16>::MAX;"]
    ///
    #[doc = "assert_eq!(n.cast_signed(), NonZero::new(-1i16).unwrap());"]
    /// ```
    #[stable(feature = "integer_sign_cast", since = "1.87.0")]
    #[rustc_const_stable(feature = "integer_sign_cast", since = "1.87.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline(always)]
    pub const fn cast_signed(self) -> NonZero<i16> {
        unsafe { NonZero::new_unchecked(self.get().cast_signed()) }
    }
    /// Returns the minimum number of bits required to represent `self`.
    ///
    /// # Examples
    ///
    /// ```
    /// # use core::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc =
    "assert_eq!(NonZero::<u16>::new(0b1)?.bit_width(), NonZero::new(1)?);"]
    #[doc =
    "assert_eq!(NonZero::<u16>::new(0b111)?.bit_width(), NonZero::new(3)?);"]
    #[doc =
    "assert_eq!(NonZero::<u16>::new(0b1110)?.bit_width(), NonZero::new(4)?);"]
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "uint_bit_width", since = "1.97.0")]
    #[rustc_const_stable(feature = "uint_bit_width", since = "1.97.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline(always)]
    pub const fn bit_width(self) -> NonZero<u32> {
        unsafe { NonZero::new_unchecked(Self::BITS - self.leading_zeros()) }
    }
    /// Multiplies two non-zero integers together.
    /// Checks for overflow and returns [`None`] on overflow.
    /// As a consequence, the result cannot wrap to zero.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let two = NonZero::new(2u16)?;"]
    #[doc = "let four = NonZero::new(4u16)?;"]
    #[doc = "let max = NonZero::new(u16::MAX)?;"]
    ///
    /// assert_eq!(Some(four), two.checked_mul(two));
    /// assert_eq!(None, max.checked_mul(two));
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const fn checked_mul(self, other: Self) -> Option<Self> {
        if let Some(result) = self.get().checked_mul(other.get()) {
            Some(unsafe { Self::new_unchecked(result) })
        } else { None }
    }
    /// Multiplies two non-zero integers together, panicking if
    /// overflow occurs.
    ///
    /// # Panics
    ///
    /// ## Overflow behavior
    ///
    /// This function always panics on overflow, regardless of whether
    /// overflow checks are enabled.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_strict_ops)]
    ///
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let three = NonZero::new(3u16)?;"]
    #[doc = "let nine = NonZero::new(9u16)?;"]
    ///
    /// assert_eq!(nine, three.strict_mul(three));
    /// # Some(())
    /// # }
    /// ```
    ///
    /// The following panics because of overflow:
    ///
    /// ```should_panic
    /// #![feature(nonzero_strict_ops)]
    ///
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let two = NonZero::new(2u16)?;"]
    #[doc = "let max = NonZero::new(u16::MAX)?;"]
    ///
    /// let _ = max.strict_mul(two);
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_strict_ops", issue = "164850")]
    #[rustc_const_unstable(feature = "const_nonzero_strict_ops", issue =
    "164850")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    #[track_caller]
    pub const fn strict_mul(self, other: Self) -> Self {
        unsafe { Self::new_unchecked(self.get().strict_mul(other.get())) }
    }
    /// Multiplies two non-zero integers together.
    #[doc = "Return [`NonZero::<u16>::MAX`] on overflow."]
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let two = NonZero::new(2u16)?;"]
    #[doc = "let four = NonZero::new(4u16)?;"]
    #[doc = "let max = NonZero::new(u16::MAX)?;"]
    ///
    /// assert_eq!(four, two.saturating_mul(two));
    /// assert_eq!(max, four.saturating_mul(max));
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const fn saturating_mul(self, other: Self) -> Self {
        unsafe { Self::new_unchecked(self.get().saturating_mul(other.get())) }
    }
    /// Multiplies two non-zero integers together,
    /// assuming overflow cannot occur.
    /// Overflow is unchecked, and it is undefined behavior to overflow
    /// *even if the result would wrap to a non-zero value*.
    ///
    /// # Safety
    ///
    /// This results in undefined behavior when overflow occurs, i.e.
    /// when [`checked_mul`] would return `None`.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let two = NonZero::new(2u16)?;"]
    #[doc = "let four = NonZero::new(4u16)?;"]
    ///
    /// assert_eq!(four, unsafe { two.unchecked_mul(two) });
    /// # Some(())
    /// # }
    /// ```
    ///
    /// [`checked_mul`]: Self::checked_mul
    #[stable(feature = "nonzero_ops", since = "CURRENT_RUSTC_VERSION")]
    #[rustc_const_stable(feature = "nonzero_ops", since =
    "CURRENT_RUSTC_VERSION")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const unsafe fn unchecked_mul(self, other: Self) -> Self {
        unsafe { Self::new_unchecked(self.get().unchecked_mul(other.get())) }
    }
    /// Raises non-zero value to an integer power.
    /// Checks for overflow and returns [`None`] on overflow.
    /// As a consequence, the result cannot wrap to zero.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let three = NonZero::new(3u16)?;"]
    #[doc = "let twenty_seven = NonZero::new(27u16)?;"]
    #[doc = "let half_max = NonZero::new(u16::MAX / 2)?;"]
    ///
    /// assert_eq!(Some(twenty_seven), three.checked_pow(3));
    /// assert_eq!(None, half_max.checked_pow(3));
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const fn checked_pow(self, other: u32) -> Option<Self> {
        if let Some(result) = self.get().checked_pow(other) {
            Some(unsafe { Self::new_unchecked(result) })
        } else { None }
    }
    /// Raises a non-zero value to an integer power, panicking if
    /// overflow occurs.
    ///
    /// # Panics
    ///
    /// ## Overflow behavior
    ///
    /// This function always panics on overflow, regardless of whether
    /// overflow checks are enabled.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_strict_ops)]
    ///
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let two = NonZero::new(2u16)?;"]
    #[doc = "let sixteen = NonZero::new(16u16)?;"]
    ///
    /// assert_eq!(sixteen, two.strict_pow(4));
    /// # Some(())
    /// # }
    /// ```
    ///
    /// The following panics because of overflow:
    ///
    /// ```should_panic
    /// #![feature(nonzero_strict_ops)]
    ///
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let half_max = NonZero::new(u16::MAX / 2)?;"]
    ///
    /// let _ = half_max.strict_pow(2);
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_strict_ops", issue = "164850")]
    #[rustc_const_unstable(feature = "const_nonzero_strict_ops", issue =
    "164850")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    #[track_caller]
    pub const fn strict_pow(self, exp: u32) -> Self {
        unsafe { Self::new_unchecked(self.get().strict_pow(exp)) }
    }
    /// Raise non-zero value to an integer power.
    #[doc = "Return [`NonZero::<u16>::MAX`] on overflow."]
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let three = NonZero::new(3u16)?;"]
    #[doc = "let twenty_seven = NonZero::new(27u16)?;"]
    #[doc = "let max = NonZero::new(u16::MAX)?;"]
    ///
    /// assert_eq!(twenty_seven, three.saturating_pow(3));
    /// assert_eq!(max, max.saturating_pow(3));
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const fn saturating_pow(self, other: u32) -> Self {
        unsafe { Self::new_unchecked(self.get().saturating_pow(other)) }
    }
    /// Parses a non-zero integer from an ASCII-byte slice with decimal digits.
    ///
    /// The characters are expected to be an optional
    #[doc = " `+` "]
    /// sign followed by only digits. Leading and trailing non-digit characters (including
    /// whitespace) represent an error. Underscores (which are accepted in Rust literals)
    /// also represent an error.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc =
    "assert_eq!(NonZero::<u16>::from_ascii_bytes(b\"+10\"), Ok(NonZero::new(10)?));"]
    /// # Some(())
    /// # }
    /// ```
    ///
    /// Trailing space returns error:
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    #[doc = "assert!(NonZero::<u16>::from_ascii_bytes(b\"1 \").is_err());"]
    /// ```
    #[stable(feature = "int_from_ascii", since = "CURRENT_RUSTC_VERSION")]
    #[rustc_const_unstable(feature = "const_convert", issue = "143773")]
    #[inline]
    pub const fn from_ascii_bytes<T>(src: T) -> Result<Self, ParseIntError>
        where T: [const] AsRef<[u8]> + [const] crate::marker::Destruct {
        Self::from_ascii_bytes_radix_impl(src.as_ref(), 10)
    }
    /// Parses a non-zero integer from an ASCII-byte slice with digits in a given base.
    ///
    /// The characters are expected to be an optional
    #[doc = " `+` "]
    /// sign followed by only digits. Leading and trailing non-digit characters (including
    /// whitespace) represent an error. Underscores (which are accepted in Rust literals)
    /// also represent an error.
    ///
    /// Digits are a subset of these characters, depending on `radix`:
    ///
    /// - `0-9`
    /// - `a-z`
    /// - `A-Z`
    ///
    /// # Panics
    ///
    /// This method panics if `radix` is not in the range from 2 to 36.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc =
    "assert_eq!(NonZero::<u16>::from_ascii_bytes_radix(b\"A\", 16), Ok(NonZero::new(10)?));"]
    /// # Some(())
    /// # }
    /// ```
    ///
    /// Trailing space returns error:
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    #[doc =
    "assert!(NonZero::<u16>::from_ascii_bytes_radix(b\"1 \", 10).is_err());"]
    /// ```
    #[stable(feature = "int_from_ascii", since = "CURRENT_RUSTC_VERSION")]
    #[rustc_const_unstable(feature = "const_convert", issue = "143773")]
    #[inline]
    pub const fn from_ascii_bytes_radix<T>(src: T, radix: u32)
        -> Result<Self, ParseIntError> where T: [const] AsRef<[u8]> + [const]
        crate::marker::Destruct {
        Self::from_ascii_bytes_radix_impl(src.as_ref(), radix)
    }
    #[inline]
    const fn from_ascii_bytes_radix_impl(src: &[u8], radix: u32)
        -> Result<Self, ParseIntError> {
        let n =
            match <u16>::from_ascii_bytes_radix_impl(src, radix) {
                Ok(n) => n,
                Err(err) => return Err(err),
            };
        if let Some(n) = Self::new(n) {
            Ok(n)
        } else { Err(ParseIntError { kind: IntErrorKind::Zero }) }
    }
    /// Parses a non-zero integer from a string slice with digits in a given base.
    ///
    /// The string is expected to be an optional
    #[doc = " `+` "]
    /// sign followed by only digits. Leading and trailing non-digit characters (including
    /// whitespace) represent an error. Underscores (which are accepted in Rust literals)
    /// also represent an error.
    ///
    /// Digits are a subset of these characters, depending on `radix`:
    ///
    /// - `0-9`
    /// - `a-z`
    /// - `A-Z`
    ///
    /// # Panics
    ///
    /// This method panics if `radix` is not in the range from 2 to 36.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc =
    "assert_eq!(NonZero::<u16>::from_str_radix(\"A\", 16), Ok(NonZero::new(10)?));"]
    /// # Some(())
    /// # }
    /// ```
    ///
    /// Trailing space returns error:
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    #[doc = "assert!(NonZero::<u16>::from_str_radix(\"1 \", 10).is_err());"]
    /// ```
    #[stable(feature = "nonzero_from_str_radix", since = "1.98.0")]
    #[rustc_const_stable(feature = "nonzero_from_str_radix", since =
    "1.98.0")]
    #[inline]
    pub const fn from_str_radix(src: &str, radix: u32)
        -> Result<Self, ParseIntError> {
        Self::from_ascii_bytes_radix_impl(src.as_bytes(), radix)
    }
}
#[stable(feature = "nonzero_parse", since = "1.35.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl FromStr for NonZero<u16> {
    type Err = ParseIntError;
    /// Parses a non-zero integer from a string slice with decimal digits.
    ///
    /// The characters are expected to be an optional
    #[doc = " `+` "]
    /// sign followed by only digits. Leading and trailing non-digit characters (including
    /// whitespace) represent an error. Underscores (which are accepted in Rust literals)
    /// also represent an error.
    ///
    /// # Examples
    ///
    /// ```
    /// use std::num::NonZero;
    /// use std::str::FromStr;
    ///
    #[doc =
    "assert_eq!(NonZero::<u16>::from_str(\"+10\"), Ok(NonZero::new(10).unwrap()));"]
    /// ```
    ///
    /// Trailing space returns error:
    ///
    /// ```
    /// use std::num::NonZero;
    /// use std::str::FromStr;
    ///
    #[doc = "assert!(NonZero::<u16>::from_str(\"1 \").is_err());"]
    /// ```
    #[inline]
    fn from_str(src: &str) -> Result<Self, Self::Err> {
        Self::from_str_radix(src, 10)
    }
}
#[stable(feature = "nonzero_div", since = "1.51.0")]
#[rustc_const_unstable(feature = "const_ops", issue = "143802")]
const impl Div<NonZero<u16>> for u16 {
    type Output = u16;
    /// Same as `self / other.get()`, but because `other` is a `NonZero<_>`,
    /// there's never a runtime check for division-by-zero.
    ///
    /// This operation rounds towards zero, truncating any fractional
    /// part of the exact result, and cannot panic.
    #[doc(alias = "unchecked_div")]
    #[inline]
    fn div(self, other: NonZero<u16>) -> u16 {
        unsafe { intrinsics::unchecked_div(self, other.get()) }
    }
}
#[stable(feature = "nonzero_div_assign", since = "1.79.0")]
#[rustc_const_unstable(feature = "const_ops", issue = "143802")]
const impl DivAssign<NonZero<u16>> for u16 {
    /// Same as `self /= other.get()`, but because `other` is a `NonZero<_>`,
    /// there's never a runtime check for division-by-zero.
    ///
    /// This operation rounds towards zero, truncating any fractional
    /// part of the exact result, and cannot panic.
    #[inline]
    fn div_assign(&mut self, other: NonZero<u16>) { *self = *self / other; }
}
#[stable(feature = "nonzero_div", since = "1.51.0")]
#[rustc_const_unstable(feature = "const_ops", issue = "143802")]
const impl Rem<NonZero<u16>> for u16 {
    type Output = u16;
    /// This operation satisfies `n % d == n - (n / d) * d`, and cannot panic.
    #[inline]
    fn rem(self, other: NonZero<u16>) -> u16 {
        unsafe { intrinsics::unchecked_rem(self, other.get()) }
    }
}
#[stable(feature = "nonzero_div_assign", since = "1.79.0")]
#[rustc_const_unstable(feature = "const_ops", issue = "143802")]
const impl RemAssign<NonZero<u16>> for u16 {
    /// This operation satisfies `n % d == n - (n / d) * d`, and cannot panic.
    #[inline]
    fn rem_assign(&mut self, other: NonZero<u16>) { *self = *self % other; }
}nonzero_integer! {
2906    Self = NonZeroU16,
2907    Primitive = unsigned u16,
2908    SignedPrimitive = i16,
2909    rot = 4,
2910    rot_op = "0xa003",
2911    rot_result = "0x3a",
2912    swap_op = "0x1234",
2913    swapped = "0x3412",
2914    reversed = "0x2c48",
2915}
2916
2917#[doc = "A [`u32`] that is known not to equal zero."]
///
/// This enables some memory layout optimization.
#[doc = "For example, `Option<NonZeroU32>` is the same size as `u32`:"]
///
/// ```rust
#[doc =
"assert_eq!(size_of::<Option<core::num::NonZeroU32>>(), size_of::<u32>());"]
/// ```
///
/// # Layout
///
#[doc =
"`NonZeroU32` is guaranteed to have the same layout and bit validity as `u32`"]
/// with the exception that `0` is not a valid instance.
#[doc = "`Option<NonZeroU32>` is guaranteed to be ABI-compatible with `u32`,"]
/// including in FFI.
///
/// Thanks to the [null pointer optimization],
#[doc = "`NonZeroU32` and `Option<NonZeroU32>`"]
/// are guaranteed to have the same size and alignment:
///
/// ```
#[doc = "use std::num::NonZeroU32;"]
///
#[doc =
"assert_eq!(size_of::<NonZeroU32>(), size_of::<Option<NonZeroU32>>());"]
#[doc =
"assert_eq!(align_of::<NonZeroU32>(), align_of::<Option<NonZeroU32>>());"]
/// ```
///
/// # Compile-time creation
///
/// Since both [`Option::unwrap()`] and [`Option::expect()`] are `const`, it is possible to
/// define a new
#[doc = "`NonZeroU32`"]
/// at compile time via:
/// ```
#[doc = "use std::num::NonZeroU32;"]
///
#[doc =
"const TEN: NonZeroU32 = NonZeroU32::new(10).expect(\"ten is non-zero\");"]
/// ```
///
/// [null pointer optimization]: crate::option#representation
#[stable(feature = "nonzero", since = "1.28.0")]
pub type NonZeroU32 = NonZero<u32>;
impl NonZero<u32> {
    /// The size of this non-zero integer type in bits.
    ///
    #[doc = "This value is equal to [`u32::BITS`]."]
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    #[doc = "assert_eq!(NonZero::<u32>::BITS, u32::BITS);"]
    /// ```
    #[stable(feature = "nonzero_bits", since = "1.67.0")]
    pub const BITS: u32 = <u32>::BITS;
    /// Returns the number of leading zeros in the binary representation of `self`.
    ///
    /// On many architectures, this function can perform better than `leading_zeros()` on the underlying integer type, as special handling of zero can be avoided.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::<u32>::new(u32::MAX)?;"]
    ///
    /// assert_eq!(n.leading_zeros(), 0);
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_leading_trailing_zeros", since = "1.53.0")]
    #[rustc_const_stable(feature = "nonzero_leading_trailing_zeros", since =
    "1.53.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const fn leading_zeros(self) -> u32 {
        unsafe { intrinsics::ctlz_nonzero(self.get() as u32) }
    }
    /// Returns the number of trailing zeros in the binary representation
    /// of `self`.
    ///
    /// On many architectures, this function can perform better than `trailing_zeros()` on the underlying integer type, as special handling of zero can be avoided.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::<u32>::new(0b0101000)?;"]
    ///
    /// assert_eq!(n.trailing_zeros(), 3);
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_leading_trailing_zeros", since = "1.53.0")]
    #[rustc_const_stable(feature = "nonzero_leading_trailing_zeros", since =
    "1.53.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const fn trailing_zeros(self) -> u32 {
        unsafe { intrinsics::cttz_nonzero(self.get() as u32) }
    }
    /// Returns `self` with only the most significant bit set.
    ///
    /// # Example
    ///
    /// ```
    /// # use core::num::NonZero;
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let a = NonZero::<u32>::new(0b_01100100)?;"]
    #[doc = "let b = NonZero::<u32>::new(0b_01000000)?;"]
    ///
    /// assert_eq!(a.isolate_highest_one(), b);
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "isolate_most_least_significant_one", since =
    "1.97.0")]
    #[rustc_const_stable(feature = "isolate_most_least_significant_one", since
    = "1.97.0")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn isolate_highest_one(self) -> Self {
        unsafe {
            let bit =
                (((1 as u32) <<
                                (<u32>::BITS - 1)).unchecked_shr(self.leading_zeros()));
            NonZero::new_unchecked(bit as u32)
        }
    }
    /// Returns `self` with only the least significant bit set.
    ///
    /// # Example
    ///
    /// ```
    /// # use core::num::NonZero;
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let a = NonZero::<u32>::new(0b_01100100)?;"]
    #[doc = "let b = NonZero::<u32>::new(0b_00000100)?;"]
    ///
    /// assert_eq!(a.isolate_lowest_one(), b);
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "isolate_most_least_significant_one", since =
    "1.97.0")]
    #[rustc_const_stable(feature = "isolate_most_least_significant_one", since
    = "1.97.0")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn isolate_lowest_one(self) -> Self {
        let n = self.get();
        let n = n & n.wrapping_neg();
        unsafe { NonZero::new_unchecked(n) }
    }
    /// Returns the index of the highest bit set to one in `self`.
    ///
    #[doc = "Note that this is equivalent to [`ilog2`](Self::ilog2)."]
    ///
    /// # Examples
    ///
    /// ```
    /// # use core::num::NonZero;
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "assert_eq!(NonZero::<u32>::new(0b1)?.highest_one(), 0);"]
    #[doc = "assert_eq!(NonZero::<u32>::new(0b1_0000)?.highest_one(), 4);"]
    #[doc = "assert_eq!(NonZero::<u32>::new(0b1_1111)?.highest_one(), 4);"]
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "int_lowest_highest_one", since = "1.97.0")]
    #[rustc_const_stable(feature = "int_lowest_highest_one", since =
    "1.97.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline(always)]
    pub const fn highest_one(self) -> u32 {
        Self::BITS - 1 - self.leading_zeros()
    }
    /// Returns the index of the lowest bit set to one in `self`.
    ///
    /// # Examples
    ///
    /// ```
    /// # use core::num::NonZero;
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "assert_eq!(NonZero::<u32>::new(0b1)?.lowest_one(), 0);"]
    #[doc = "assert_eq!(NonZero::<u32>::new(0b1_0000)?.lowest_one(), 4);"]
    #[doc = "assert_eq!(NonZero::<u32>::new(0b1_1111)?.lowest_one(), 0);"]
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "int_lowest_highest_one", since = "1.97.0")]
    #[rustc_const_stable(feature = "int_lowest_highest_one", since =
    "1.97.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline(always)]
    pub const fn lowest_one(self) -> u32 { self.trailing_zeros() }
    /// Returns the number of ones in the binary representation of `self`.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let a = NonZero::<u32>::new(0b100_0000)?;"]
    #[doc = "let b = NonZero::<u32>::new(0b100_0011)?;"]
    ///
    /// assert_eq!(a.count_ones(), NonZero::new(1)?);
    /// assert_eq!(b.count_ones(), NonZero::new(3)?);
    /// # Some(())
    /// # }
    /// ```
    ///
    #[stable(feature = "non_zero_count_ones", since = "1.86.0")]
    #[rustc_const_stable(feature = "non_zero_count_ones", since = "1.86.0")]
    #[doc(alias = "popcount")]
    #[doc(alias = "popcnt")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn count_ones(self) -> NonZero<u32> {
        unsafe { NonZero::new_unchecked(self.get().count_ones()) }
    }
    /// Shifts the bits to the left by a specified amount, `n`,
    /// wrapping the truncated bits to the end of the resulting integer.
    ///
    /// Please note this isn't the same operation as the `<<` shifting operator!
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x10000b3u32)?;"]
    #[doc = "let m = NonZero::new(0xb301)?;"]
    ///
    #[doc = "assert_eq!(n.rotate_left(8), m);"]
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn rotate_left(self, n: u32) -> Self {
        let result = self.get().rotate_left(n);
        unsafe { Self::new_unchecked(result) }
    }
    /// Shifts the bits to the right by a specified amount, `n`,
    /// wrapping the truncated bits to the beginning of the resulting
    /// integer.
    ///
    /// Please note this isn't the same operation as the `>>` shifting operator!
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0xb301u32)?;"]
    #[doc = "let m = NonZero::new(0x10000b3)?;"]
    ///
    #[doc = "assert_eq!(n.rotate_right(8), m);"]
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn rotate_right(self, n: u32) -> Self {
        let result = self.get().rotate_right(n);
        unsafe { Self::new_unchecked(result) }
    }
    /// Reverses the byte order of the integer.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x12345678u32)?;"]
    /// let m = n.swap_bytes();
    ///
    #[doc = "assert_eq!(m, NonZero::new(0x78563412)?);"]
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn swap_bytes(self) -> Self {
        let result = self.get().swap_bytes();
        unsafe { Self::new_unchecked(result) }
    }
    /// Reverses the order of bits in the integer. The least significant bit becomes the most significant bit,
    /// second least-significant bit becomes second most-significant bit, etc.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x12345678u32)?;"]
    /// let m = n.reverse_bits();
    ///
    #[doc = "assert_eq!(m, NonZero::new(0x1e6a2c48)?);"]
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn reverse_bits(self) -> Self {
        let result = self.get().reverse_bits();
        unsafe { Self::new_unchecked(result) }
    }
    /// Converts an integer from big endian to the target's endianness.
    ///
    /// On big endian this is a no-op. On little endian the bytes are
    /// swapped.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    #[doc = "use std::num::NonZeroU32;"]
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x1Au32)?;"]
    ///
    /// if cfg!(target_endian = "big") {
    #[doc = "    assert_eq!(NonZeroU32::from_be(n), n)"]
    /// } else {
    #[doc = "    assert_eq!(NonZeroU32::from_be(n), n.swap_bytes())"]
    /// }
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use]
    #[inline(always)]
    pub const fn from_be(x: Self) -> Self {
        let result = u32::from_be(x.get());
        unsafe { Self::new_unchecked(result) }
    }
    /// Converts an integer from little endian to the target's endianness.
    ///
    /// On little endian this is a no-op. On big endian the bytes are
    /// swapped.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    #[doc = "use std::num::NonZeroU32;"]
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x1Au32)?;"]
    ///
    /// if cfg!(target_endian = "little") {
    #[doc = "    assert_eq!(NonZeroU32::from_le(n), n)"]
    /// } else {
    #[doc = "    assert_eq!(NonZeroU32::from_le(n), n.swap_bytes())"]
    /// }
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use]
    #[inline(always)]
    pub const fn from_le(x: Self) -> Self {
        let result = u32::from_le(x.get());
        unsafe { Self::new_unchecked(result) }
    }
    /// Converts `self` to big endian from the target's endianness.
    ///
    /// On big endian this is a no-op. On little endian the bytes are
    /// swapped.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x1Au32)?;"]
    ///
    /// if cfg!(target_endian = "big") {
    ///     assert_eq!(n.to_be(), n)
    /// } else {
    ///     assert_eq!(n.to_be(), n.swap_bytes())
    /// }
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn to_be(self) -> Self {
        let result = self.get().to_be();
        unsafe { Self::new_unchecked(result) }
    }
    /// Converts `self` to little endian from the target's endianness.
    ///
    /// On little endian this is a no-op. On big endian the bytes are
    /// swapped.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x1Au32)?;"]
    ///
    /// if cfg!(target_endian = "little") {
    ///     assert_eq!(n.to_le(), n)
    /// } else {
    ///     assert_eq!(n.to_le(), n.swap_bytes())
    /// }
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn to_le(self) -> Self {
        let result = self.get().to_le();
        unsafe { Self::new_unchecked(result) }
    }
    /// The smallest value that can be represented by this non-zero
    /// integer type, 1.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    #[doc = "assert_eq!(NonZero::<u32>::MIN.get(), 1u32);"]
    /// ```
    #[stable(feature = "nonzero_min_max", since = "1.70.0")]
    pub const MIN: Self = Self::new(1).unwrap();
    /// The largest value that can be represented by this non-zero
    /// integer type,
    #[doc = "equal to [`u32::MAX`]."]
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    #[doc = "assert_eq!(NonZero::<u32>::MAX.get(), u32::MAX);"]
    /// ```
    #[stable(feature = "nonzero_min_max", since = "1.70.0")]
    pub const MAX: Self = Self::new(<u32>::MAX).unwrap();
    /// Adds an unsigned integer to a non-zero value.
    /// Checks for overflow and returns [`None`] on overflow.
    /// As a consequence, the result cannot wrap to zero.
    ///
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let one = NonZero::new(1u32)?;"]
    #[doc = "let two = NonZero::new(2u32)?;"]
    #[doc = "let max = NonZero::new(u32::MAX)?;"]
    ///
    /// assert_eq!(Some(two), one.checked_add(1));
    /// assert_eq!(None, max.checked_add(1));
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const fn checked_add(self, other: u32) -> Option<Self> {
        if let Some(result) = self.get().checked_add(other) {
            Some(unsafe { Self::new_unchecked(result) })
        } else { None }
    }
    /// Adds an unsigned integer to a non-zero value, panicking
    /// if overflow occurs.
    ///
    /// # Panics
    ///
    /// ## Overflow behavior
    ///
    /// This function always panics on overflow, regardless of whether
    /// overflow checks are enabled.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_strict_ops)]
    ///
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let two = NonZero::new(2u32)?;"]
    #[doc = "let three = NonZero::new(3u32)?;"]
    ///
    /// assert_eq!(three, two.strict_add(1));
    /// # Some(())
    /// # }
    /// ```
    ///
    /// The following panics because of overflow:
    ///
    /// ```should_panic
    /// #![feature(nonzero_strict_ops)]
    ///
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let max = NonZero::new(u32::MAX)?;"]
    ///
    /// let _ = max.strict_add(1);
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_strict_ops", issue = "164850")]
    #[rustc_const_unstable(feature = "const_nonzero_strict_ops", issue =
    "164850")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    #[track_caller]
    pub const fn strict_add(self, other: u32) -> Self {
        unsafe { Self::new_unchecked(self.get().strict_add(other)) }
    }
    /// Adds an unsigned integer to a non-zero value.
    #[doc = "Return [`NonZero::<u32>::MAX`] on overflow."]
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let one = NonZero::new(1u32)?;"]
    #[doc = "let two = NonZero::new(2u32)?;"]
    #[doc = "let max = NonZero::new(u32::MAX)?;"]
    ///
    /// assert_eq!(two, one.saturating_add(1));
    /// assert_eq!(max, max.saturating_add(1));
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const fn saturating_add(self, other: u32) -> Self {
        unsafe { Self::new_unchecked(self.get().saturating_add(other)) }
    }
    /// Adds an unsigned integer to a non-zero value,
    /// assuming overflow cannot occur.
    /// Overflow is unchecked, and it is undefined behavior to overflow
    /// *even if the result would wrap to a non-zero value*.
    ///
    /// # Safety
    ///
    /// This results in undefined behavior when overflow occurs, i.e. when
    /// [`checked_add`] would return `None`.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let one = NonZero::new(1u32)?;"]
    #[doc = "let two = NonZero::new(2u32)?;"]
    ///
    /// assert_eq!(two, unsafe { one.unchecked_add(1) });
    /// # Some(())
    /// # }
    /// ```
    ///
    /// [`checked_add`]: Self::checked_add
    #[stable(feature = "nonzero_ops", since = "CURRENT_RUSTC_VERSION")]
    #[rustc_const_stable(feature = "nonzero_ops", since =
    "CURRENT_RUSTC_VERSION")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const unsafe fn unchecked_add(self, other: u32) -> Self {
        unsafe { Self::new_unchecked(self.get().unchecked_add(other)) }
    }
    /// Calculates the quotient of `self` and `rhs`, rounding the result towards positive infinity.
    ///
    /// The result is guaranteed to be non-zero.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    #[doc = "let one = NonZero::new(1u32).unwrap();"]
    #[doc = "let max = NonZero::new(u32::MAX).unwrap();"]
    /// assert_eq!(one.div_ceil(max), one);
    ///
    #[doc = "let two = NonZero::new(2u32).unwrap();"]
    #[doc = "let three = NonZero::new(3u32).unwrap();"]
    /// assert_eq!(three.div_ceil(two), two);
    /// ```
    #[stable(feature = "unsigned_nonzero_div_ceil", since = "1.92.0")]
    #[rustc_const_stable(feature = "unsigned_nonzero_div_ceil", since =
    "1.92.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const fn div_ceil(self, rhs: Self) -> Self {
        let v = (self.get() - 1) / rhs.get() + 1;
        unsafe { Self::new_unchecked(v) }
    }
    /// Returns the smallest power of two greater than or equal to `self`.
    /// Checks for overflow and returns [`None`]
    /// if the next power of two is greater than the type’s maximum value.
    /// As a consequence, the result cannot wrap to zero.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let two = NonZero::new(2u32)?;"]
    #[doc = "let three = NonZero::new(3u32)?;"]
    #[doc = "let four = NonZero::new(4u32)?;"]
    #[doc = "let max = NonZero::new(u32::MAX)?;"]
    ///
    /// assert_eq!(Some(two), two.checked_next_power_of_two() );
    /// assert_eq!(Some(four), three.checked_next_power_of_two() );
    /// assert_eq!(None, max.checked_next_power_of_two() );
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const fn checked_next_power_of_two(self) -> Option<Self> {
        if let Some(nz) = self.get().checked_next_power_of_two() {
            Some(unsafe { Self::new_unchecked(nz) })
        } else { None }
    }
    /// Returns the base 2 logarithm of the number, rounded down.
    ///
    /// This is the same operation as
    #[doc = "[`u32::ilog2`],"]
    /// except that it has no failure cases to worry about
    /// since this value can never be zero.
    ///
    /// Note that this is equivalent to [`highest_one`](Self::highest_one).
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "assert_eq!(NonZero::new(7u32)?.ilog2(), 2);"]
    #[doc = "assert_eq!(NonZero::new(8u32)?.ilog2(), 3);"]
    #[doc = "assert_eq!(NonZero::new(9u32)?.ilog2(), 3);"]
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "int_log", since = "1.67.0")]
    #[rustc_const_stable(feature = "int_log", since = "1.67.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const fn ilog2(self) -> u32 { Self::BITS - 1 - self.leading_zeros() }
    /// Returns the base 10 logarithm of the number, rounded down.
    ///
    /// This is the same operation as
    #[doc = "[`u32::ilog10`],"]
    /// except that it has no failure cases to worry about
    /// since this value can never be zero.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "assert_eq!(NonZero::new(99u32)?.ilog10(), 1);"]
    #[doc = "assert_eq!(NonZero::new(100u32)?.ilog10(), 2);"]
    #[doc = "assert_eq!(NonZero::new(101u32)?.ilog10(), 2);"]
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "int_log", since = "1.67.0")]
    #[rustc_const_stable(feature = "int_log", since = "1.67.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const fn ilog10(self) -> u32 { imp::int_log10::u32(self) }
    /// Calculates the midpoint (average) between `self` and `rhs`.
    ///
    /// `midpoint(a, b)` is `(a + b) >> 1` as if it were performed in a
    /// sufficiently-large signed integral type. This implies that the result is
    /// always rounded towards negative infinity and that no overflow will ever occur.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let one = NonZero::new(1u32)?;"]
    #[doc = "let two = NonZero::new(2u32)?;"]
    #[doc = "let four = NonZero::new(4u32)?;"]
    ///
    /// assert_eq!(one.midpoint(four), two);
    /// assert_eq!(four.midpoint(one), two);
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "num_midpoint", since = "1.85.0")]
    #[rustc_const_stable(feature = "num_midpoint", since = "1.85.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[doc(alias = "average_floor")]
    #[doc(alias = "average")]
    #[inline]
    pub const fn midpoint(self, rhs: Self) -> Self {
        unsafe { Self::new_unchecked(self.get().midpoint(rhs.get())) }
    }
    /// Returns `true` if and only if `self == (1 << k)` for some `k`.
    ///
    /// On many architectures, this function can perform better than `is_power_of_two()`
    /// on the underlying integer type, as special handling of zero can be avoided.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let eight = NonZero::new(8u32)?;"]
    /// assert!(eight.is_power_of_two());
    #[doc = "let ten = NonZero::new(10u32)?;"]
    /// assert!(!ten.is_power_of_two());
    /// # Some(())
    /// # }
    /// ```
    #[must_use]
    #[stable(feature = "nonzero_is_power_of_two", since = "1.59.0")]
    #[rustc_const_stable(feature = "nonzero_is_power_of_two", since =
    "1.59.0")]
    #[inline]
    pub const fn is_power_of_two(self) -> bool {
        intrinsics::ctpop(self.get()) < 2
    }
    /// Returns the square root of the number, rounded down.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let ten = NonZero::new(10u32)?;"]
    #[doc = "let three = NonZero::new(3u32)?;"]
    ///
    /// assert_eq!(ten.isqrt(), three);
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "isqrt", since = "1.84.0")]
    #[rustc_const_stable(feature = "isqrt", since = "1.84.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const fn isqrt(self) -> Self {
        let result = self.get().isqrt();
        unsafe { Self::new_unchecked(result) }
    }
    /// Returns the bit pattern of `self` reinterpreted as a signed integer of the same size.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    ///
    #[doc = "let n = NonZero::<u32>::MAX;"]
    ///
    #[doc = "assert_eq!(n.cast_signed(), NonZero::new(-1i32).unwrap());"]
    /// ```
    #[stable(feature = "integer_sign_cast", since = "1.87.0")]
    #[rustc_const_stable(feature = "integer_sign_cast", since = "1.87.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline(always)]
    pub const fn cast_signed(self) -> NonZero<i32> {
        unsafe { NonZero::new_unchecked(self.get().cast_signed()) }
    }
    /// Returns the minimum number of bits required to represent `self`.
    ///
    /// # Examples
    ///
    /// ```
    /// # use core::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc =
    "assert_eq!(NonZero::<u32>::new(0b1)?.bit_width(), NonZero::new(1)?);"]
    #[doc =
    "assert_eq!(NonZero::<u32>::new(0b111)?.bit_width(), NonZero::new(3)?);"]
    #[doc =
    "assert_eq!(NonZero::<u32>::new(0b1110)?.bit_width(), NonZero::new(4)?);"]
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "uint_bit_width", since = "1.97.0")]
    #[rustc_const_stable(feature = "uint_bit_width", since = "1.97.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline(always)]
    pub const fn bit_width(self) -> NonZero<u32> {
        unsafe { NonZero::new_unchecked(Self::BITS - self.leading_zeros()) }
    }
    /// Multiplies two non-zero integers together.
    /// Checks for overflow and returns [`None`] on overflow.
    /// As a consequence, the result cannot wrap to zero.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let two = NonZero::new(2u32)?;"]
    #[doc = "let four = NonZero::new(4u32)?;"]
    #[doc = "let max = NonZero::new(u32::MAX)?;"]
    ///
    /// assert_eq!(Some(four), two.checked_mul(two));
    /// assert_eq!(None, max.checked_mul(two));
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const fn checked_mul(self, other: Self) -> Option<Self> {
        if let Some(result) = self.get().checked_mul(other.get()) {
            Some(unsafe { Self::new_unchecked(result) })
        } else { None }
    }
    /// Multiplies two non-zero integers together, panicking if
    /// overflow occurs.
    ///
    /// # Panics
    ///
    /// ## Overflow behavior
    ///
    /// This function always panics on overflow, regardless of whether
    /// overflow checks are enabled.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_strict_ops)]
    ///
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let three = NonZero::new(3u32)?;"]
    #[doc = "let nine = NonZero::new(9u32)?;"]
    ///
    /// assert_eq!(nine, three.strict_mul(three));
    /// # Some(())
    /// # }
    /// ```
    ///
    /// The following panics because of overflow:
    ///
    /// ```should_panic
    /// #![feature(nonzero_strict_ops)]
    ///
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let two = NonZero::new(2u32)?;"]
    #[doc = "let max = NonZero::new(u32::MAX)?;"]
    ///
    /// let _ = max.strict_mul(two);
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_strict_ops", issue = "164850")]
    #[rustc_const_unstable(feature = "const_nonzero_strict_ops", issue =
    "164850")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    #[track_caller]
    pub const fn strict_mul(self, other: Self) -> Self {
        unsafe { Self::new_unchecked(self.get().strict_mul(other.get())) }
    }
    /// Multiplies two non-zero integers together.
    #[doc = "Return [`NonZero::<u32>::MAX`] on overflow."]
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let two = NonZero::new(2u32)?;"]
    #[doc = "let four = NonZero::new(4u32)?;"]
    #[doc = "let max = NonZero::new(u32::MAX)?;"]
    ///
    /// assert_eq!(four, two.saturating_mul(two));
    /// assert_eq!(max, four.saturating_mul(max));
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const fn saturating_mul(self, other: Self) -> Self {
        unsafe { Self::new_unchecked(self.get().saturating_mul(other.get())) }
    }
    /// Multiplies two non-zero integers together,
    /// assuming overflow cannot occur.
    /// Overflow is unchecked, and it is undefined behavior to overflow
    /// *even if the result would wrap to a non-zero value*.
    ///
    /// # Safety
    ///
    /// This results in undefined behavior when overflow occurs, i.e.
    /// when [`checked_mul`] would return `None`.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let two = NonZero::new(2u32)?;"]
    #[doc = "let four = NonZero::new(4u32)?;"]
    ///
    /// assert_eq!(four, unsafe { two.unchecked_mul(two) });
    /// # Some(())
    /// # }
    /// ```
    ///
    /// [`checked_mul`]: Self::checked_mul
    #[stable(feature = "nonzero_ops", since = "CURRENT_RUSTC_VERSION")]
    #[rustc_const_stable(feature = "nonzero_ops", since =
    "CURRENT_RUSTC_VERSION")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const unsafe fn unchecked_mul(self, other: Self) -> Self {
        unsafe { Self::new_unchecked(self.get().unchecked_mul(other.get())) }
    }
    /// Raises non-zero value to an integer power.
    /// Checks for overflow and returns [`None`] on overflow.
    /// As a consequence, the result cannot wrap to zero.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let three = NonZero::new(3u32)?;"]
    #[doc = "let twenty_seven = NonZero::new(27u32)?;"]
    #[doc = "let half_max = NonZero::new(u32::MAX / 2)?;"]
    ///
    /// assert_eq!(Some(twenty_seven), three.checked_pow(3));
    /// assert_eq!(None, half_max.checked_pow(3));
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const fn checked_pow(self, other: u32) -> Option<Self> {
        if let Some(result) = self.get().checked_pow(other) {
            Some(unsafe { Self::new_unchecked(result) })
        } else { None }
    }
    /// Raises a non-zero value to an integer power, panicking if
    /// overflow occurs.
    ///
    /// # Panics
    ///
    /// ## Overflow behavior
    ///
    /// This function always panics on overflow, regardless of whether
    /// overflow checks are enabled.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_strict_ops)]
    ///
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let two = NonZero::new(2u32)?;"]
    #[doc = "let sixteen = NonZero::new(16u32)?;"]
    ///
    /// assert_eq!(sixteen, two.strict_pow(4));
    /// # Some(())
    /// # }
    /// ```
    ///
    /// The following panics because of overflow:
    ///
    /// ```should_panic
    /// #![feature(nonzero_strict_ops)]
    ///
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let half_max = NonZero::new(u32::MAX / 2)?;"]
    ///
    /// let _ = half_max.strict_pow(2);
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_strict_ops", issue = "164850")]
    #[rustc_const_unstable(feature = "const_nonzero_strict_ops", issue =
    "164850")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    #[track_caller]
    pub const fn strict_pow(self, exp: u32) -> Self {
        unsafe { Self::new_unchecked(self.get().strict_pow(exp)) }
    }
    /// Raise non-zero value to an integer power.
    #[doc = "Return [`NonZero::<u32>::MAX`] on overflow."]
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let three = NonZero::new(3u32)?;"]
    #[doc = "let twenty_seven = NonZero::new(27u32)?;"]
    #[doc = "let max = NonZero::new(u32::MAX)?;"]
    ///
    /// assert_eq!(twenty_seven, three.saturating_pow(3));
    /// assert_eq!(max, max.saturating_pow(3));
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const fn saturating_pow(self, other: u32) -> Self {
        unsafe { Self::new_unchecked(self.get().saturating_pow(other)) }
    }
    /// Parses a non-zero integer from an ASCII-byte slice with decimal digits.
    ///
    /// The characters are expected to be an optional
    #[doc = " `+` "]
    /// sign followed by only digits. Leading and trailing non-digit characters (including
    /// whitespace) represent an error. Underscores (which are accepted in Rust literals)
    /// also represent an error.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc =
    "assert_eq!(NonZero::<u32>::from_ascii_bytes(b\"+10\"), Ok(NonZero::new(10)?));"]
    /// # Some(())
    /// # }
    /// ```
    ///
    /// Trailing space returns error:
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    #[doc = "assert!(NonZero::<u32>::from_ascii_bytes(b\"1 \").is_err());"]
    /// ```
    #[stable(feature = "int_from_ascii", since = "CURRENT_RUSTC_VERSION")]
    #[rustc_const_unstable(feature = "const_convert", issue = "143773")]
    #[inline]
    pub const fn from_ascii_bytes<T>(src: T) -> Result<Self, ParseIntError>
        where T: [const] AsRef<[u8]> + [const] crate::marker::Destruct {
        Self::from_ascii_bytes_radix_impl(src.as_ref(), 10)
    }
    /// Parses a non-zero integer from an ASCII-byte slice with digits in a given base.
    ///
    /// The characters are expected to be an optional
    #[doc = " `+` "]
    /// sign followed by only digits. Leading and trailing non-digit characters (including
    /// whitespace) represent an error. Underscores (which are accepted in Rust literals)
    /// also represent an error.
    ///
    /// Digits are a subset of these characters, depending on `radix`:
    ///
    /// - `0-9`
    /// - `a-z`
    /// - `A-Z`
    ///
    /// # Panics
    ///
    /// This method panics if `radix` is not in the range from 2 to 36.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc =
    "assert_eq!(NonZero::<u32>::from_ascii_bytes_radix(b\"A\", 16), Ok(NonZero::new(10)?));"]
    /// # Some(())
    /// # }
    /// ```
    ///
    /// Trailing space returns error:
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    #[doc =
    "assert!(NonZero::<u32>::from_ascii_bytes_radix(b\"1 \", 10).is_err());"]
    /// ```
    #[stable(feature = "int_from_ascii", since = "CURRENT_RUSTC_VERSION")]
    #[rustc_const_unstable(feature = "const_convert", issue = "143773")]
    #[inline]
    pub const fn from_ascii_bytes_radix<T>(src: T, radix: u32)
        -> Result<Self, ParseIntError> where T: [const] AsRef<[u8]> + [const]
        crate::marker::Destruct {
        Self::from_ascii_bytes_radix_impl(src.as_ref(), radix)
    }
    #[inline]
    const fn from_ascii_bytes_radix_impl(src: &[u8], radix: u32)
        -> Result<Self, ParseIntError> {
        let n =
            match <u32>::from_ascii_bytes_radix_impl(src, radix) {
                Ok(n) => n,
                Err(err) => return Err(err),
            };
        if let Some(n) = Self::new(n) {
            Ok(n)
        } else { Err(ParseIntError { kind: IntErrorKind::Zero }) }
    }
    /// Parses a non-zero integer from a string slice with digits in a given base.
    ///
    /// The string is expected to be an optional
    #[doc = " `+` "]
    /// sign followed by only digits. Leading and trailing non-digit characters (including
    /// whitespace) represent an error. Underscores (which are accepted in Rust literals)
    /// also represent an error.
    ///
    /// Digits are a subset of these characters, depending on `radix`:
    ///
    /// - `0-9`
    /// - `a-z`
    /// - `A-Z`
    ///
    /// # Panics
    ///
    /// This method panics if `radix` is not in the range from 2 to 36.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc =
    "assert_eq!(NonZero::<u32>::from_str_radix(\"A\", 16), Ok(NonZero::new(10)?));"]
    /// # Some(())
    /// # }
    /// ```
    ///
    /// Trailing space returns error:
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    #[doc = "assert!(NonZero::<u32>::from_str_radix(\"1 \", 10).is_err());"]
    /// ```
    #[stable(feature = "nonzero_from_str_radix", since = "1.98.0")]
    #[rustc_const_stable(feature = "nonzero_from_str_radix", since =
    "1.98.0")]
    #[inline]
    pub const fn from_str_radix(src: &str, radix: u32)
        -> Result<Self, ParseIntError> {
        Self::from_ascii_bytes_radix_impl(src.as_bytes(), radix)
    }
}
#[stable(feature = "nonzero_parse", since = "1.35.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl FromStr for NonZero<u32> {
    type Err = ParseIntError;
    /// Parses a non-zero integer from a string slice with decimal digits.
    ///
    /// The characters are expected to be an optional
    #[doc = " `+` "]
    /// sign followed by only digits. Leading and trailing non-digit characters (including
    /// whitespace) represent an error. Underscores (which are accepted in Rust literals)
    /// also represent an error.
    ///
    /// # Examples
    ///
    /// ```
    /// use std::num::NonZero;
    /// use std::str::FromStr;
    ///
    #[doc =
    "assert_eq!(NonZero::<u32>::from_str(\"+10\"), Ok(NonZero::new(10).unwrap()));"]
    /// ```
    ///
    /// Trailing space returns error:
    ///
    /// ```
    /// use std::num::NonZero;
    /// use std::str::FromStr;
    ///
    #[doc = "assert!(NonZero::<u32>::from_str(\"1 \").is_err());"]
    /// ```
    #[inline]
    fn from_str(src: &str) -> Result<Self, Self::Err> {
        Self::from_str_radix(src, 10)
    }
}
#[stable(feature = "nonzero_div", since = "1.51.0")]
#[rustc_const_unstable(feature = "const_ops", issue = "143802")]
const impl Div<NonZero<u32>> for u32 {
    type Output = u32;
    /// Same as `self / other.get()`, but because `other` is a `NonZero<_>`,
    /// there's never a runtime check for division-by-zero.
    ///
    /// This operation rounds towards zero, truncating any fractional
    /// part of the exact result, and cannot panic.
    #[doc(alias = "unchecked_div")]
    #[inline]
    fn div(self, other: NonZero<u32>) -> u32 {
        unsafe { intrinsics::unchecked_div(self, other.get()) }
    }
}
#[stable(feature = "nonzero_div_assign", since = "1.79.0")]
#[rustc_const_unstable(feature = "const_ops", issue = "143802")]
const impl DivAssign<NonZero<u32>> for u32 {
    /// Same as `self /= other.get()`, but because `other` is a `NonZero<_>`,
    /// there's never a runtime check for division-by-zero.
    ///
    /// This operation rounds towards zero, truncating any fractional
    /// part of the exact result, and cannot panic.
    #[inline]
    fn div_assign(&mut self, other: NonZero<u32>) { *self = *self / other; }
}
#[stable(feature = "nonzero_div", since = "1.51.0")]
#[rustc_const_unstable(feature = "const_ops", issue = "143802")]
const impl Rem<NonZero<u32>> for u32 {
    type Output = u32;
    /// This operation satisfies `n % d == n - (n / d) * d`, and cannot panic.
    #[inline]
    fn rem(self, other: NonZero<u32>) -> u32 {
        unsafe { intrinsics::unchecked_rem(self, other.get()) }
    }
}
#[stable(feature = "nonzero_div_assign", since = "1.79.0")]
#[rustc_const_unstable(feature = "const_ops", issue = "143802")]
const impl RemAssign<NonZero<u32>> for u32 {
    /// This operation satisfies `n % d == n - (n / d) * d`, and cannot panic.
    #[inline]
    fn rem_assign(&mut self, other: NonZero<u32>) { *self = *self % other; }
}nonzero_integer! {
2918    Self = NonZeroU32,
2919    Primitive = unsigned u32,
2920    SignedPrimitive = i32,
2921    rot = 8,
2922    rot_op = "0x10000b3",
2923    rot_result = "0xb301",
2924    swap_op = "0x12345678",
2925    swapped = "0x78563412",
2926    reversed = "0x1e6a2c48",
2927}
2928
2929#[doc = "A [`u64`] that is known not to equal zero."]
///
/// This enables some memory layout optimization.
#[doc = "For example, `Option<NonZeroU64>` is the same size as `u64`:"]
///
/// ```rust
#[doc =
"assert_eq!(size_of::<Option<core::num::NonZeroU64>>(), size_of::<u64>());"]
/// ```
///
/// # Layout
///
#[doc =
"`NonZeroU64` is guaranteed to have the same layout and bit validity as `u64`"]
/// with the exception that `0` is not a valid instance.
#[doc = "`Option<NonZeroU64>` is guaranteed to be ABI-compatible with `u64`,"]
/// including in FFI.
///
/// Thanks to the [null pointer optimization],
#[doc = "`NonZeroU64` and `Option<NonZeroU64>`"]
/// are guaranteed to have the same size and alignment:
///
/// ```
#[doc = "use std::num::NonZeroU64;"]
///
#[doc =
"assert_eq!(size_of::<NonZeroU64>(), size_of::<Option<NonZeroU64>>());"]
#[doc =
"assert_eq!(align_of::<NonZeroU64>(), align_of::<Option<NonZeroU64>>());"]
/// ```
///
/// # Compile-time creation
///
/// Since both [`Option::unwrap()`] and [`Option::expect()`] are `const`, it is possible to
/// define a new
#[doc = "`NonZeroU64`"]
/// at compile time via:
/// ```
#[doc = "use std::num::NonZeroU64;"]
///
#[doc =
"const TEN: NonZeroU64 = NonZeroU64::new(10).expect(\"ten is non-zero\");"]
/// ```
///
/// [null pointer optimization]: crate::option#representation
#[stable(feature = "nonzero", since = "1.28.0")]
pub type NonZeroU64 = NonZero<u64>;
impl NonZero<u64> {
    /// The size of this non-zero integer type in bits.
    ///
    #[doc = "This value is equal to [`u64::BITS`]."]
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    #[doc = "assert_eq!(NonZero::<u64>::BITS, u64::BITS);"]
    /// ```
    #[stable(feature = "nonzero_bits", since = "1.67.0")]
    pub const BITS: u32 = <u64>::BITS;
    /// Returns the number of leading zeros in the binary representation of `self`.
    ///
    /// On many architectures, this function can perform better than `leading_zeros()` on the underlying integer type, as special handling of zero can be avoided.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::<u64>::new(u64::MAX)?;"]
    ///
    /// assert_eq!(n.leading_zeros(), 0);
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_leading_trailing_zeros", since = "1.53.0")]
    #[rustc_const_stable(feature = "nonzero_leading_trailing_zeros", since =
    "1.53.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const fn leading_zeros(self) -> u32 {
        unsafe { intrinsics::ctlz_nonzero(self.get() as u64) }
    }
    /// Returns the number of trailing zeros in the binary representation
    /// of `self`.
    ///
    /// On many architectures, this function can perform better than `trailing_zeros()` on the underlying integer type, as special handling of zero can be avoided.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::<u64>::new(0b0101000)?;"]
    ///
    /// assert_eq!(n.trailing_zeros(), 3);
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_leading_trailing_zeros", since = "1.53.0")]
    #[rustc_const_stable(feature = "nonzero_leading_trailing_zeros", since =
    "1.53.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const fn trailing_zeros(self) -> u32 {
        unsafe { intrinsics::cttz_nonzero(self.get() as u64) }
    }
    /// Returns `self` with only the most significant bit set.
    ///
    /// # Example
    ///
    /// ```
    /// # use core::num::NonZero;
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let a = NonZero::<u64>::new(0b_01100100)?;"]
    #[doc = "let b = NonZero::<u64>::new(0b_01000000)?;"]
    ///
    /// assert_eq!(a.isolate_highest_one(), b);
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "isolate_most_least_significant_one", since =
    "1.97.0")]
    #[rustc_const_stable(feature = "isolate_most_least_significant_one", since
    = "1.97.0")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn isolate_highest_one(self) -> Self {
        unsafe {
            let bit =
                (((1 as u64) <<
                                (<u64>::BITS - 1)).unchecked_shr(self.leading_zeros()));
            NonZero::new_unchecked(bit as u64)
        }
    }
    /// Returns `self` with only the least significant bit set.
    ///
    /// # Example
    ///
    /// ```
    /// # use core::num::NonZero;
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let a = NonZero::<u64>::new(0b_01100100)?;"]
    #[doc = "let b = NonZero::<u64>::new(0b_00000100)?;"]
    ///
    /// assert_eq!(a.isolate_lowest_one(), b);
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "isolate_most_least_significant_one", since =
    "1.97.0")]
    #[rustc_const_stable(feature = "isolate_most_least_significant_one", since
    = "1.97.0")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn isolate_lowest_one(self) -> Self {
        let n = self.get();
        let n = n & n.wrapping_neg();
        unsafe { NonZero::new_unchecked(n) }
    }
    /// Returns the index of the highest bit set to one in `self`.
    ///
    #[doc = "Note that this is equivalent to [`ilog2`](Self::ilog2)."]
    ///
    /// # Examples
    ///
    /// ```
    /// # use core::num::NonZero;
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "assert_eq!(NonZero::<u64>::new(0b1)?.highest_one(), 0);"]
    #[doc = "assert_eq!(NonZero::<u64>::new(0b1_0000)?.highest_one(), 4);"]
    #[doc = "assert_eq!(NonZero::<u64>::new(0b1_1111)?.highest_one(), 4);"]
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "int_lowest_highest_one", since = "1.97.0")]
    #[rustc_const_stable(feature = "int_lowest_highest_one", since =
    "1.97.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline(always)]
    pub const fn highest_one(self) -> u32 {
        Self::BITS - 1 - self.leading_zeros()
    }
    /// Returns the index of the lowest bit set to one in `self`.
    ///
    /// # Examples
    ///
    /// ```
    /// # use core::num::NonZero;
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "assert_eq!(NonZero::<u64>::new(0b1)?.lowest_one(), 0);"]
    #[doc = "assert_eq!(NonZero::<u64>::new(0b1_0000)?.lowest_one(), 4);"]
    #[doc = "assert_eq!(NonZero::<u64>::new(0b1_1111)?.lowest_one(), 0);"]
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "int_lowest_highest_one", since = "1.97.0")]
    #[rustc_const_stable(feature = "int_lowest_highest_one", since =
    "1.97.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline(always)]
    pub const fn lowest_one(self) -> u32 { self.trailing_zeros() }
    /// Returns the number of ones in the binary representation of `self`.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let a = NonZero::<u64>::new(0b100_0000)?;"]
    #[doc = "let b = NonZero::<u64>::new(0b100_0011)?;"]
    ///
    /// assert_eq!(a.count_ones(), NonZero::new(1)?);
    /// assert_eq!(b.count_ones(), NonZero::new(3)?);
    /// # Some(())
    /// # }
    /// ```
    ///
    #[stable(feature = "non_zero_count_ones", since = "1.86.0")]
    #[rustc_const_stable(feature = "non_zero_count_ones", since = "1.86.0")]
    #[doc(alias = "popcount")]
    #[doc(alias = "popcnt")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn count_ones(self) -> NonZero<u32> {
        unsafe { NonZero::new_unchecked(self.get().count_ones()) }
    }
    /// Shifts the bits to the left by a specified amount, `n`,
    /// wrapping the truncated bits to the end of the resulting integer.
    ///
    /// Please note this isn't the same operation as the `<<` shifting operator!
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0xaa00000000006e1u64)?;"]
    #[doc = "let m = NonZero::new(0x6e10aa)?;"]
    ///
    #[doc = "assert_eq!(n.rotate_left(12), m);"]
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn rotate_left(self, n: u32) -> Self {
        let result = self.get().rotate_left(n);
        unsafe { Self::new_unchecked(result) }
    }
    /// Shifts the bits to the right by a specified amount, `n`,
    /// wrapping the truncated bits to the beginning of the resulting
    /// integer.
    ///
    /// Please note this isn't the same operation as the `>>` shifting operator!
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x6e10aau64)?;"]
    #[doc = "let m = NonZero::new(0xaa00000000006e1)?;"]
    ///
    #[doc = "assert_eq!(n.rotate_right(12), m);"]
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn rotate_right(self, n: u32) -> Self {
        let result = self.get().rotate_right(n);
        unsafe { Self::new_unchecked(result) }
    }
    /// Reverses the byte order of the integer.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x1234567890123456u64)?;"]
    /// let m = n.swap_bytes();
    ///
    #[doc = "assert_eq!(m, NonZero::new(0x5634129078563412)?);"]
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn swap_bytes(self) -> Self {
        let result = self.get().swap_bytes();
        unsafe { Self::new_unchecked(result) }
    }
    /// Reverses the order of bits in the integer. The least significant bit becomes the most significant bit,
    /// second least-significant bit becomes second most-significant bit, etc.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x1234567890123456u64)?;"]
    /// let m = n.reverse_bits();
    ///
    #[doc = "assert_eq!(m, NonZero::new(0x6a2c48091e6a2c48)?);"]
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn reverse_bits(self) -> Self {
        let result = self.get().reverse_bits();
        unsafe { Self::new_unchecked(result) }
    }
    /// Converts an integer from big endian to the target's endianness.
    ///
    /// On big endian this is a no-op. On little endian the bytes are
    /// swapped.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    #[doc = "use std::num::NonZeroU64;"]
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x1Au64)?;"]
    ///
    /// if cfg!(target_endian = "big") {
    #[doc = "    assert_eq!(NonZeroU64::from_be(n), n)"]
    /// } else {
    #[doc = "    assert_eq!(NonZeroU64::from_be(n), n.swap_bytes())"]
    /// }
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use]
    #[inline(always)]
    pub const fn from_be(x: Self) -> Self {
        let result = u64::from_be(x.get());
        unsafe { Self::new_unchecked(result) }
    }
    /// Converts an integer from little endian to the target's endianness.
    ///
    /// On little endian this is a no-op. On big endian the bytes are
    /// swapped.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    #[doc = "use std::num::NonZeroU64;"]
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x1Au64)?;"]
    ///
    /// if cfg!(target_endian = "little") {
    #[doc = "    assert_eq!(NonZeroU64::from_le(n), n)"]
    /// } else {
    #[doc = "    assert_eq!(NonZeroU64::from_le(n), n.swap_bytes())"]
    /// }
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use]
    #[inline(always)]
    pub const fn from_le(x: Self) -> Self {
        let result = u64::from_le(x.get());
        unsafe { Self::new_unchecked(result) }
    }
    /// Converts `self` to big endian from the target's endianness.
    ///
    /// On big endian this is a no-op. On little endian the bytes are
    /// swapped.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x1Au64)?;"]
    ///
    /// if cfg!(target_endian = "big") {
    ///     assert_eq!(n.to_be(), n)
    /// } else {
    ///     assert_eq!(n.to_be(), n.swap_bytes())
    /// }
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn to_be(self) -> Self {
        let result = self.get().to_be();
        unsafe { Self::new_unchecked(result) }
    }
    /// Converts `self` to little endian from the target's endianness.
    ///
    /// On little endian this is a no-op. On big endian the bytes are
    /// swapped.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x1Au64)?;"]
    ///
    /// if cfg!(target_endian = "little") {
    ///     assert_eq!(n.to_le(), n)
    /// } else {
    ///     assert_eq!(n.to_le(), n.swap_bytes())
    /// }
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn to_le(self) -> Self {
        let result = self.get().to_le();
        unsafe { Self::new_unchecked(result) }
    }
    /// The smallest value that can be represented by this non-zero
    /// integer type, 1.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    #[doc = "assert_eq!(NonZero::<u64>::MIN.get(), 1u64);"]
    /// ```
    #[stable(feature = "nonzero_min_max", since = "1.70.0")]
    pub const MIN: Self = Self::new(1).unwrap();
    /// The largest value that can be represented by this non-zero
    /// integer type,
    #[doc = "equal to [`u64::MAX`]."]
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    #[doc = "assert_eq!(NonZero::<u64>::MAX.get(), u64::MAX);"]
    /// ```
    #[stable(feature = "nonzero_min_max", since = "1.70.0")]
    pub const MAX: Self = Self::new(<u64>::MAX).unwrap();
    /// Adds an unsigned integer to a non-zero value.
    /// Checks for overflow and returns [`None`] on overflow.
    /// As a consequence, the result cannot wrap to zero.
    ///
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let one = NonZero::new(1u64)?;"]
    #[doc = "let two = NonZero::new(2u64)?;"]
    #[doc = "let max = NonZero::new(u64::MAX)?;"]
    ///
    /// assert_eq!(Some(two), one.checked_add(1));
    /// assert_eq!(None, max.checked_add(1));
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const fn checked_add(self, other: u64) -> Option<Self> {
        if let Some(result) = self.get().checked_add(other) {
            Some(unsafe { Self::new_unchecked(result) })
        } else { None }
    }
    /// Adds an unsigned integer to a non-zero value, panicking
    /// if overflow occurs.
    ///
    /// # Panics
    ///
    /// ## Overflow behavior
    ///
    /// This function always panics on overflow, regardless of whether
    /// overflow checks are enabled.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_strict_ops)]
    ///
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let two = NonZero::new(2u64)?;"]
    #[doc = "let three = NonZero::new(3u64)?;"]
    ///
    /// assert_eq!(three, two.strict_add(1));
    /// # Some(())
    /// # }
    /// ```
    ///
    /// The following panics because of overflow:
    ///
    /// ```should_panic
    /// #![feature(nonzero_strict_ops)]
    ///
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let max = NonZero::new(u64::MAX)?;"]
    ///
    /// let _ = max.strict_add(1);
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_strict_ops", issue = "164850")]
    #[rustc_const_unstable(feature = "const_nonzero_strict_ops", issue =
    "164850")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    #[track_caller]
    pub const fn strict_add(self, other: u64) -> Self {
        unsafe { Self::new_unchecked(self.get().strict_add(other)) }
    }
    /// Adds an unsigned integer to a non-zero value.
    #[doc = "Return [`NonZero::<u64>::MAX`] on overflow."]
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let one = NonZero::new(1u64)?;"]
    #[doc = "let two = NonZero::new(2u64)?;"]
    #[doc = "let max = NonZero::new(u64::MAX)?;"]
    ///
    /// assert_eq!(two, one.saturating_add(1));
    /// assert_eq!(max, max.saturating_add(1));
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const fn saturating_add(self, other: u64) -> Self {
        unsafe { Self::new_unchecked(self.get().saturating_add(other)) }
    }
    /// Adds an unsigned integer to a non-zero value,
    /// assuming overflow cannot occur.
    /// Overflow is unchecked, and it is undefined behavior to overflow
    /// *even if the result would wrap to a non-zero value*.
    ///
    /// # Safety
    ///
    /// This results in undefined behavior when overflow occurs, i.e. when
    /// [`checked_add`] would return `None`.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let one = NonZero::new(1u64)?;"]
    #[doc = "let two = NonZero::new(2u64)?;"]
    ///
    /// assert_eq!(two, unsafe { one.unchecked_add(1) });
    /// # Some(())
    /// # }
    /// ```
    ///
    /// [`checked_add`]: Self::checked_add
    #[stable(feature = "nonzero_ops", since = "CURRENT_RUSTC_VERSION")]
    #[rustc_const_stable(feature = "nonzero_ops", since =
    "CURRENT_RUSTC_VERSION")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const unsafe fn unchecked_add(self, other: u64) -> Self {
        unsafe { Self::new_unchecked(self.get().unchecked_add(other)) }
    }
    /// Calculates the quotient of `self` and `rhs`, rounding the result towards positive infinity.
    ///
    /// The result is guaranteed to be non-zero.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    #[doc = "let one = NonZero::new(1u64).unwrap();"]
    #[doc = "let max = NonZero::new(u64::MAX).unwrap();"]
    /// assert_eq!(one.div_ceil(max), one);
    ///
    #[doc = "let two = NonZero::new(2u64).unwrap();"]
    #[doc = "let three = NonZero::new(3u64).unwrap();"]
    /// assert_eq!(three.div_ceil(two), two);
    /// ```
    #[stable(feature = "unsigned_nonzero_div_ceil", since = "1.92.0")]
    #[rustc_const_stable(feature = "unsigned_nonzero_div_ceil", since =
    "1.92.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const fn div_ceil(self, rhs: Self) -> Self {
        let v = (self.get() - 1) / rhs.get() + 1;
        unsafe { Self::new_unchecked(v) }
    }
    /// Returns the smallest power of two greater than or equal to `self`.
    /// Checks for overflow and returns [`None`]
    /// if the next power of two is greater than the type’s maximum value.
    /// As a consequence, the result cannot wrap to zero.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let two = NonZero::new(2u64)?;"]
    #[doc = "let three = NonZero::new(3u64)?;"]
    #[doc = "let four = NonZero::new(4u64)?;"]
    #[doc = "let max = NonZero::new(u64::MAX)?;"]
    ///
    /// assert_eq!(Some(two), two.checked_next_power_of_two() );
    /// assert_eq!(Some(four), three.checked_next_power_of_two() );
    /// assert_eq!(None, max.checked_next_power_of_two() );
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const fn checked_next_power_of_two(self) -> Option<Self> {
        if let Some(nz) = self.get().checked_next_power_of_two() {
            Some(unsafe { Self::new_unchecked(nz) })
        } else { None }
    }
    /// Returns the base 2 logarithm of the number, rounded down.
    ///
    /// This is the same operation as
    #[doc = "[`u64::ilog2`],"]
    /// except that it has no failure cases to worry about
    /// since this value can never be zero.
    ///
    /// Note that this is equivalent to [`highest_one`](Self::highest_one).
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "assert_eq!(NonZero::new(7u64)?.ilog2(), 2);"]
    #[doc = "assert_eq!(NonZero::new(8u64)?.ilog2(), 3);"]
    #[doc = "assert_eq!(NonZero::new(9u64)?.ilog2(), 3);"]
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "int_log", since = "1.67.0")]
    #[rustc_const_stable(feature = "int_log", since = "1.67.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const fn ilog2(self) -> u32 { Self::BITS - 1 - self.leading_zeros() }
    /// Returns the base 10 logarithm of the number, rounded down.
    ///
    /// This is the same operation as
    #[doc = "[`u64::ilog10`],"]
    /// except that it has no failure cases to worry about
    /// since this value can never be zero.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "assert_eq!(NonZero::new(99u64)?.ilog10(), 1);"]
    #[doc = "assert_eq!(NonZero::new(100u64)?.ilog10(), 2);"]
    #[doc = "assert_eq!(NonZero::new(101u64)?.ilog10(), 2);"]
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "int_log", since = "1.67.0")]
    #[rustc_const_stable(feature = "int_log", since = "1.67.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const fn ilog10(self) -> u32 { imp::int_log10::u64(self) }
    /// Calculates the midpoint (average) between `self` and `rhs`.
    ///
    /// `midpoint(a, b)` is `(a + b) >> 1` as if it were performed in a
    /// sufficiently-large signed integral type. This implies that the result is
    /// always rounded towards negative infinity and that no overflow will ever occur.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let one = NonZero::new(1u64)?;"]
    #[doc = "let two = NonZero::new(2u64)?;"]
    #[doc = "let four = NonZero::new(4u64)?;"]
    ///
    /// assert_eq!(one.midpoint(four), two);
    /// assert_eq!(four.midpoint(one), two);
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "num_midpoint", since = "1.85.0")]
    #[rustc_const_stable(feature = "num_midpoint", since = "1.85.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[doc(alias = "average_floor")]
    #[doc(alias = "average")]
    #[inline]
    pub const fn midpoint(self, rhs: Self) -> Self {
        unsafe { Self::new_unchecked(self.get().midpoint(rhs.get())) }
    }
    /// Returns `true` if and only if `self == (1 << k)` for some `k`.
    ///
    /// On many architectures, this function can perform better than `is_power_of_two()`
    /// on the underlying integer type, as special handling of zero can be avoided.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let eight = NonZero::new(8u64)?;"]
    /// assert!(eight.is_power_of_two());
    #[doc = "let ten = NonZero::new(10u64)?;"]
    /// assert!(!ten.is_power_of_two());
    /// # Some(())
    /// # }
    /// ```
    #[must_use]
    #[stable(feature = "nonzero_is_power_of_two", since = "1.59.0")]
    #[rustc_const_stable(feature = "nonzero_is_power_of_two", since =
    "1.59.0")]
    #[inline]
    pub const fn is_power_of_two(self) -> bool {
        intrinsics::ctpop(self.get()) < 2
    }
    /// Returns the square root of the number, rounded down.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let ten = NonZero::new(10u64)?;"]
    #[doc = "let three = NonZero::new(3u64)?;"]
    ///
    /// assert_eq!(ten.isqrt(), three);
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "isqrt", since = "1.84.0")]
    #[rustc_const_stable(feature = "isqrt", since = "1.84.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const fn isqrt(self) -> Self {
        let result = self.get().isqrt();
        unsafe { Self::new_unchecked(result) }
    }
    /// Returns the bit pattern of `self` reinterpreted as a signed integer of the same size.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    ///
    #[doc = "let n = NonZero::<u64>::MAX;"]
    ///
    #[doc = "assert_eq!(n.cast_signed(), NonZero::new(-1i64).unwrap());"]
    /// ```
    #[stable(feature = "integer_sign_cast", since = "1.87.0")]
    #[rustc_const_stable(feature = "integer_sign_cast", since = "1.87.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline(always)]
    pub const fn cast_signed(self) -> NonZero<i64> {
        unsafe { NonZero::new_unchecked(self.get().cast_signed()) }
    }
    /// Returns the minimum number of bits required to represent `self`.
    ///
    /// # Examples
    ///
    /// ```
    /// # use core::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc =
    "assert_eq!(NonZero::<u64>::new(0b1)?.bit_width(), NonZero::new(1)?);"]
    #[doc =
    "assert_eq!(NonZero::<u64>::new(0b111)?.bit_width(), NonZero::new(3)?);"]
    #[doc =
    "assert_eq!(NonZero::<u64>::new(0b1110)?.bit_width(), NonZero::new(4)?);"]
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "uint_bit_width", since = "1.97.0")]
    #[rustc_const_stable(feature = "uint_bit_width", since = "1.97.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline(always)]
    pub const fn bit_width(self) -> NonZero<u32> {
        unsafe { NonZero::new_unchecked(Self::BITS - self.leading_zeros()) }
    }
    /// Multiplies two non-zero integers together.
    /// Checks for overflow and returns [`None`] on overflow.
    /// As a consequence, the result cannot wrap to zero.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let two = NonZero::new(2u64)?;"]
    #[doc = "let four = NonZero::new(4u64)?;"]
    #[doc = "let max = NonZero::new(u64::MAX)?;"]
    ///
    /// assert_eq!(Some(four), two.checked_mul(two));
    /// assert_eq!(None, max.checked_mul(two));
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const fn checked_mul(self, other: Self) -> Option<Self> {
        if let Some(result) = self.get().checked_mul(other.get()) {
            Some(unsafe { Self::new_unchecked(result) })
        } else { None }
    }
    /// Multiplies two non-zero integers together, panicking if
    /// overflow occurs.
    ///
    /// # Panics
    ///
    /// ## Overflow behavior
    ///
    /// This function always panics on overflow, regardless of whether
    /// overflow checks are enabled.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_strict_ops)]
    ///
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let three = NonZero::new(3u64)?;"]
    #[doc = "let nine = NonZero::new(9u64)?;"]
    ///
    /// assert_eq!(nine, three.strict_mul(three));
    /// # Some(())
    /// # }
    /// ```
    ///
    /// The following panics because of overflow:
    ///
    /// ```should_panic
    /// #![feature(nonzero_strict_ops)]
    ///
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let two = NonZero::new(2u64)?;"]
    #[doc = "let max = NonZero::new(u64::MAX)?;"]
    ///
    /// let _ = max.strict_mul(two);
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_strict_ops", issue = "164850")]
    #[rustc_const_unstable(feature = "const_nonzero_strict_ops", issue =
    "164850")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    #[track_caller]
    pub const fn strict_mul(self, other: Self) -> Self {
        unsafe { Self::new_unchecked(self.get().strict_mul(other.get())) }
    }
    /// Multiplies two non-zero integers together.
    #[doc = "Return [`NonZero::<u64>::MAX`] on overflow."]
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let two = NonZero::new(2u64)?;"]
    #[doc = "let four = NonZero::new(4u64)?;"]
    #[doc = "let max = NonZero::new(u64::MAX)?;"]
    ///
    /// assert_eq!(four, two.saturating_mul(two));
    /// assert_eq!(max, four.saturating_mul(max));
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const fn saturating_mul(self, other: Self) -> Self {
        unsafe { Self::new_unchecked(self.get().saturating_mul(other.get())) }
    }
    /// Multiplies two non-zero integers together,
    /// assuming overflow cannot occur.
    /// Overflow is unchecked, and it is undefined behavior to overflow
    /// *even if the result would wrap to a non-zero value*.
    ///
    /// # Safety
    ///
    /// This results in undefined behavior when overflow occurs, i.e.
    /// when [`checked_mul`] would return `None`.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let two = NonZero::new(2u64)?;"]
    #[doc = "let four = NonZero::new(4u64)?;"]
    ///
    /// assert_eq!(four, unsafe { two.unchecked_mul(two) });
    /// # Some(())
    /// # }
    /// ```
    ///
    /// [`checked_mul`]: Self::checked_mul
    #[stable(feature = "nonzero_ops", since = "CURRENT_RUSTC_VERSION")]
    #[rustc_const_stable(feature = "nonzero_ops", since =
    "CURRENT_RUSTC_VERSION")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const unsafe fn unchecked_mul(self, other: Self) -> Self {
        unsafe { Self::new_unchecked(self.get().unchecked_mul(other.get())) }
    }
    /// Raises non-zero value to an integer power.
    /// Checks for overflow and returns [`None`] on overflow.
    /// As a consequence, the result cannot wrap to zero.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let three = NonZero::new(3u64)?;"]
    #[doc = "let twenty_seven = NonZero::new(27u64)?;"]
    #[doc = "let half_max = NonZero::new(u64::MAX / 2)?;"]
    ///
    /// assert_eq!(Some(twenty_seven), three.checked_pow(3));
    /// assert_eq!(None, half_max.checked_pow(3));
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const fn checked_pow(self, other: u32) -> Option<Self> {
        if let Some(result) = self.get().checked_pow(other) {
            Some(unsafe { Self::new_unchecked(result) })
        } else { None }
    }
    /// Raises a non-zero value to an integer power, panicking if
    /// overflow occurs.
    ///
    /// # Panics
    ///
    /// ## Overflow behavior
    ///
    /// This function always panics on overflow, regardless of whether
    /// overflow checks are enabled.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_strict_ops)]
    ///
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let two = NonZero::new(2u64)?;"]
    #[doc = "let sixteen = NonZero::new(16u64)?;"]
    ///
    /// assert_eq!(sixteen, two.strict_pow(4));
    /// # Some(())
    /// # }
    /// ```
    ///
    /// The following panics because of overflow:
    ///
    /// ```should_panic
    /// #![feature(nonzero_strict_ops)]
    ///
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let half_max = NonZero::new(u64::MAX / 2)?;"]
    ///
    /// let _ = half_max.strict_pow(2);
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_strict_ops", issue = "164850")]
    #[rustc_const_unstable(feature = "const_nonzero_strict_ops", issue =
    "164850")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    #[track_caller]
    pub const fn strict_pow(self, exp: u32) -> Self {
        unsafe { Self::new_unchecked(self.get().strict_pow(exp)) }
    }
    /// Raise non-zero value to an integer power.
    #[doc = "Return [`NonZero::<u64>::MAX`] on overflow."]
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let three = NonZero::new(3u64)?;"]
    #[doc = "let twenty_seven = NonZero::new(27u64)?;"]
    #[doc = "let max = NonZero::new(u64::MAX)?;"]
    ///
    /// assert_eq!(twenty_seven, three.saturating_pow(3));
    /// assert_eq!(max, max.saturating_pow(3));
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const fn saturating_pow(self, other: u32) -> Self {
        unsafe { Self::new_unchecked(self.get().saturating_pow(other)) }
    }
    /// Parses a non-zero integer from an ASCII-byte slice with decimal digits.
    ///
    /// The characters are expected to be an optional
    #[doc = " `+` "]
    /// sign followed by only digits. Leading and trailing non-digit characters (including
    /// whitespace) represent an error. Underscores (which are accepted in Rust literals)
    /// also represent an error.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc =
    "assert_eq!(NonZero::<u64>::from_ascii_bytes(b\"+10\"), Ok(NonZero::new(10)?));"]
    /// # Some(())
    /// # }
    /// ```
    ///
    /// Trailing space returns error:
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    #[doc = "assert!(NonZero::<u64>::from_ascii_bytes(b\"1 \").is_err());"]
    /// ```
    #[stable(feature = "int_from_ascii", since = "CURRENT_RUSTC_VERSION")]
    #[rustc_const_unstable(feature = "const_convert", issue = "143773")]
    #[inline]
    pub const fn from_ascii_bytes<T>(src: T) -> Result<Self, ParseIntError>
        where T: [const] AsRef<[u8]> + [const] crate::marker::Destruct {
        Self::from_ascii_bytes_radix_impl(src.as_ref(), 10)
    }
    /// Parses a non-zero integer from an ASCII-byte slice with digits in a given base.
    ///
    /// The characters are expected to be an optional
    #[doc = " `+` "]
    /// sign followed by only digits. Leading and trailing non-digit characters (including
    /// whitespace) represent an error. Underscores (which are accepted in Rust literals)
    /// also represent an error.
    ///
    /// Digits are a subset of these characters, depending on `radix`:
    ///
    /// - `0-9`
    /// - `a-z`
    /// - `A-Z`
    ///
    /// # Panics
    ///
    /// This method panics if `radix` is not in the range from 2 to 36.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc =
    "assert_eq!(NonZero::<u64>::from_ascii_bytes_radix(b\"A\", 16), Ok(NonZero::new(10)?));"]
    /// # Some(())
    /// # }
    /// ```
    ///
    /// Trailing space returns error:
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    #[doc =
    "assert!(NonZero::<u64>::from_ascii_bytes_radix(b\"1 \", 10).is_err());"]
    /// ```
    #[stable(feature = "int_from_ascii", since = "CURRENT_RUSTC_VERSION")]
    #[rustc_const_unstable(feature = "const_convert", issue = "143773")]
    #[inline]
    pub const fn from_ascii_bytes_radix<T>(src: T, radix: u32)
        -> Result<Self, ParseIntError> where T: [const] AsRef<[u8]> + [const]
        crate::marker::Destruct {
        Self::from_ascii_bytes_radix_impl(src.as_ref(), radix)
    }
    #[inline]
    const fn from_ascii_bytes_radix_impl(src: &[u8], radix: u32)
        -> Result<Self, ParseIntError> {
        let n =
            match <u64>::from_ascii_bytes_radix_impl(src, radix) {
                Ok(n) => n,
                Err(err) => return Err(err),
            };
        if let Some(n) = Self::new(n) {
            Ok(n)
        } else { Err(ParseIntError { kind: IntErrorKind::Zero }) }
    }
    /// Parses a non-zero integer from a string slice with digits in a given base.
    ///
    /// The string is expected to be an optional
    #[doc = " `+` "]
    /// sign followed by only digits. Leading and trailing non-digit characters (including
    /// whitespace) represent an error. Underscores (which are accepted in Rust literals)
    /// also represent an error.
    ///
    /// Digits are a subset of these characters, depending on `radix`:
    ///
    /// - `0-9`
    /// - `a-z`
    /// - `A-Z`
    ///
    /// # Panics
    ///
    /// This method panics if `radix` is not in the range from 2 to 36.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc =
    "assert_eq!(NonZero::<u64>::from_str_radix(\"A\", 16), Ok(NonZero::new(10)?));"]
    /// # Some(())
    /// # }
    /// ```
    ///
    /// Trailing space returns error:
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    #[doc = "assert!(NonZero::<u64>::from_str_radix(\"1 \", 10).is_err());"]
    /// ```
    #[stable(feature = "nonzero_from_str_radix", since = "1.98.0")]
    #[rustc_const_stable(feature = "nonzero_from_str_radix", since =
    "1.98.0")]
    #[inline]
    pub const fn from_str_radix(src: &str, radix: u32)
        -> Result<Self, ParseIntError> {
        Self::from_ascii_bytes_radix_impl(src.as_bytes(), radix)
    }
}
#[stable(feature = "nonzero_parse", since = "1.35.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl FromStr for NonZero<u64> {
    type Err = ParseIntError;
    /// Parses a non-zero integer from a string slice with decimal digits.
    ///
    /// The characters are expected to be an optional
    #[doc = " `+` "]
    /// sign followed by only digits. Leading and trailing non-digit characters (including
    /// whitespace) represent an error. Underscores (which are accepted in Rust literals)
    /// also represent an error.
    ///
    /// # Examples
    ///
    /// ```
    /// use std::num::NonZero;
    /// use std::str::FromStr;
    ///
    #[doc =
    "assert_eq!(NonZero::<u64>::from_str(\"+10\"), Ok(NonZero::new(10).unwrap()));"]
    /// ```
    ///
    /// Trailing space returns error:
    ///
    /// ```
    /// use std::num::NonZero;
    /// use std::str::FromStr;
    ///
    #[doc = "assert!(NonZero::<u64>::from_str(\"1 \").is_err());"]
    /// ```
    #[inline]
    fn from_str(src: &str) -> Result<Self, Self::Err> {
        Self::from_str_radix(src, 10)
    }
}
#[stable(feature = "nonzero_div", since = "1.51.0")]
#[rustc_const_unstable(feature = "const_ops", issue = "143802")]
const impl Div<NonZero<u64>> for u64 {
    type Output = u64;
    /// Same as `self / other.get()`, but because `other` is a `NonZero<_>`,
    /// there's never a runtime check for division-by-zero.
    ///
    /// This operation rounds towards zero, truncating any fractional
    /// part of the exact result, and cannot panic.
    #[doc(alias = "unchecked_div")]
    #[inline]
    fn div(self, other: NonZero<u64>) -> u64 {
        unsafe { intrinsics::unchecked_div(self, other.get()) }
    }
}
#[stable(feature = "nonzero_div_assign", since = "1.79.0")]
#[rustc_const_unstable(feature = "const_ops", issue = "143802")]
const impl DivAssign<NonZero<u64>> for u64 {
    /// Same as `self /= other.get()`, but because `other` is a `NonZero<_>`,
    /// there's never a runtime check for division-by-zero.
    ///
    /// This operation rounds towards zero, truncating any fractional
    /// part of the exact result, and cannot panic.
    #[inline]
    fn div_assign(&mut self, other: NonZero<u64>) { *self = *self / other; }
}
#[stable(feature = "nonzero_div", since = "1.51.0")]
#[rustc_const_unstable(feature = "const_ops", issue = "143802")]
const impl Rem<NonZero<u64>> for u64 {
    type Output = u64;
    /// This operation satisfies `n % d == n - (n / d) * d`, and cannot panic.
    #[inline]
    fn rem(self, other: NonZero<u64>) -> u64 {
        unsafe { intrinsics::unchecked_rem(self, other.get()) }
    }
}
#[stable(feature = "nonzero_div_assign", since = "1.79.0")]
#[rustc_const_unstable(feature = "const_ops", issue = "143802")]
const impl RemAssign<NonZero<u64>> for u64 {
    /// This operation satisfies `n % d == n - (n / d) * d`, and cannot panic.
    #[inline]
    fn rem_assign(&mut self, other: NonZero<u64>) { *self = *self % other; }
}nonzero_integer! {
2930    Self = NonZeroU64,
2931    Primitive = unsigned u64,
2932    SignedPrimitive = i64,
2933    rot = 12,
2934    rot_op = "0xaa00000000006e1",
2935    rot_result = "0x6e10aa",
2936    swap_op = "0x1234567890123456",
2937    swapped = "0x5634129078563412",
2938    reversed = "0x6a2c48091e6a2c48",
2939}
2940
2941#[doc = "A [`u128`] that is known not to equal zero."]
///
/// This enables some memory layout optimization.
#[doc = "For example, `Option<NonZeroU128>` is the same size as `u128`:"]
///
/// ```rust
#[doc =
"assert_eq!(size_of::<Option<core::num::NonZeroU128>>(), size_of::<u128>());"]
/// ```
///
/// # Layout
///
#[doc =
"`NonZeroU128` is guaranteed to have the same layout and bit validity as `u128`"]
/// with the exception that `0` is not a valid instance.
#[doc =
"`Option<NonZeroU128>` is guaranteed to be ABI-compatible with `u128`,"]
/// including in FFI.
///
/// Thanks to the [null pointer optimization],
#[doc = "`NonZeroU128` and `Option<NonZeroU128>`"]
/// are guaranteed to have the same size and alignment:
///
/// ```
#[doc = "use std::num::NonZeroU128;"]
///
#[doc =
"assert_eq!(size_of::<NonZeroU128>(), size_of::<Option<NonZeroU128>>());"]
#[doc =
"assert_eq!(align_of::<NonZeroU128>(), align_of::<Option<NonZeroU128>>());"]
/// ```
///
/// # Compile-time creation
///
/// Since both [`Option::unwrap()`] and [`Option::expect()`] are `const`, it is possible to
/// define a new
#[doc = "`NonZeroU128`"]
/// at compile time via:
/// ```
#[doc = "use std::num::NonZeroU128;"]
///
#[doc =
"const TEN: NonZeroU128 = NonZeroU128::new(10).expect(\"ten is non-zero\");"]
/// ```
///
/// [null pointer optimization]: crate::option#representation
#[stable(feature = "nonzero", since = "1.28.0")]
pub type NonZeroU128 = NonZero<u128>;
impl NonZero<u128> {
    /// The size of this non-zero integer type in bits.
    ///
    #[doc = "This value is equal to [`u128::BITS`]."]
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    #[doc = "assert_eq!(NonZero::<u128>::BITS, u128::BITS);"]
    /// ```
    #[stable(feature = "nonzero_bits", since = "1.67.0")]
    pub const BITS: u32 = <u128>::BITS;
    /// Returns the number of leading zeros in the binary representation of `self`.
    ///
    /// On many architectures, this function can perform better than `leading_zeros()` on the underlying integer type, as special handling of zero can be avoided.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::<u128>::new(u128::MAX)?;"]
    ///
    /// assert_eq!(n.leading_zeros(), 0);
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_leading_trailing_zeros", since = "1.53.0")]
    #[rustc_const_stable(feature = "nonzero_leading_trailing_zeros", since =
    "1.53.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const fn leading_zeros(self) -> u32 {
        unsafe { intrinsics::ctlz_nonzero(self.get() as u128) }
    }
    /// Returns the number of trailing zeros in the binary representation
    /// of `self`.
    ///
    /// On many architectures, this function can perform better than `trailing_zeros()` on the underlying integer type, as special handling of zero can be avoided.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::<u128>::new(0b0101000)?;"]
    ///
    /// assert_eq!(n.trailing_zeros(), 3);
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_leading_trailing_zeros", since = "1.53.0")]
    #[rustc_const_stable(feature = "nonzero_leading_trailing_zeros", since =
    "1.53.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const fn trailing_zeros(self) -> u32 {
        unsafe { intrinsics::cttz_nonzero(self.get() as u128) }
    }
    /// Returns `self` with only the most significant bit set.
    ///
    /// # Example
    ///
    /// ```
    /// # use core::num::NonZero;
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let a = NonZero::<u128>::new(0b_01100100)?;"]
    #[doc = "let b = NonZero::<u128>::new(0b_01000000)?;"]
    ///
    /// assert_eq!(a.isolate_highest_one(), b);
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "isolate_most_least_significant_one", since =
    "1.97.0")]
    #[rustc_const_stable(feature = "isolate_most_least_significant_one", since
    = "1.97.0")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn isolate_highest_one(self) -> Self {
        unsafe {
            let bit =
                (((1 as u128) <<
                                (<u128>::BITS - 1)).unchecked_shr(self.leading_zeros()));
            NonZero::new_unchecked(bit as u128)
        }
    }
    /// Returns `self` with only the least significant bit set.
    ///
    /// # Example
    ///
    /// ```
    /// # use core::num::NonZero;
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let a = NonZero::<u128>::new(0b_01100100)?;"]
    #[doc = "let b = NonZero::<u128>::new(0b_00000100)?;"]
    ///
    /// assert_eq!(a.isolate_lowest_one(), b);
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "isolate_most_least_significant_one", since =
    "1.97.0")]
    #[rustc_const_stable(feature = "isolate_most_least_significant_one", since
    = "1.97.0")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn isolate_lowest_one(self) -> Self {
        let n = self.get();
        let n = n & n.wrapping_neg();
        unsafe { NonZero::new_unchecked(n) }
    }
    /// Returns the index of the highest bit set to one in `self`.
    ///
    #[doc = "Note that this is equivalent to [`ilog2`](Self::ilog2)."]
    ///
    /// # Examples
    ///
    /// ```
    /// # use core::num::NonZero;
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "assert_eq!(NonZero::<u128>::new(0b1)?.highest_one(), 0);"]
    #[doc = "assert_eq!(NonZero::<u128>::new(0b1_0000)?.highest_one(), 4);"]
    #[doc = "assert_eq!(NonZero::<u128>::new(0b1_1111)?.highest_one(), 4);"]
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "int_lowest_highest_one", since = "1.97.0")]
    #[rustc_const_stable(feature = "int_lowest_highest_one", since =
    "1.97.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline(always)]
    pub const fn highest_one(self) -> u32 {
        Self::BITS - 1 - self.leading_zeros()
    }
    /// Returns the index of the lowest bit set to one in `self`.
    ///
    /// # Examples
    ///
    /// ```
    /// # use core::num::NonZero;
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "assert_eq!(NonZero::<u128>::new(0b1)?.lowest_one(), 0);"]
    #[doc = "assert_eq!(NonZero::<u128>::new(0b1_0000)?.lowest_one(), 4);"]
    #[doc = "assert_eq!(NonZero::<u128>::new(0b1_1111)?.lowest_one(), 0);"]
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "int_lowest_highest_one", since = "1.97.0")]
    #[rustc_const_stable(feature = "int_lowest_highest_one", since =
    "1.97.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline(always)]
    pub const fn lowest_one(self) -> u32 { self.trailing_zeros() }
    /// Returns the number of ones in the binary representation of `self`.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let a = NonZero::<u128>::new(0b100_0000)?;"]
    #[doc = "let b = NonZero::<u128>::new(0b100_0011)?;"]
    ///
    /// assert_eq!(a.count_ones(), NonZero::new(1)?);
    /// assert_eq!(b.count_ones(), NonZero::new(3)?);
    /// # Some(())
    /// # }
    /// ```
    ///
    #[stable(feature = "non_zero_count_ones", since = "1.86.0")]
    #[rustc_const_stable(feature = "non_zero_count_ones", since = "1.86.0")]
    #[doc(alias = "popcount")]
    #[doc(alias = "popcnt")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn count_ones(self) -> NonZero<u32> {
        unsafe { NonZero::new_unchecked(self.get().count_ones()) }
    }
    /// Shifts the bits to the left by a specified amount, `n`,
    /// wrapping the truncated bits to the end of the resulting integer.
    ///
    /// Please note this isn't the same operation as the `<<` shifting operator!
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x13f40000000000000000000000004f76u128)?;"]
    #[doc = "let m = NonZero::new(0x4f7613f4)?;"]
    ///
    #[doc = "assert_eq!(n.rotate_left(16), m);"]
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn rotate_left(self, n: u32) -> Self {
        let result = self.get().rotate_left(n);
        unsafe { Self::new_unchecked(result) }
    }
    /// Shifts the bits to the right by a specified amount, `n`,
    /// wrapping the truncated bits to the beginning of the resulting
    /// integer.
    ///
    /// Please note this isn't the same operation as the `>>` shifting operator!
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x4f7613f4u128)?;"]
    #[doc = "let m = NonZero::new(0x13f40000000000000000000000004f76)?;"]
    ///
    #[doc = "assert_eq!(n.rotate_right(16), m);"]
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn rotate_right(self, n: u32) -> Self {
        let result = self.get().rotate_right(n);
        unsafe { Self::new_unchecked(result) }
    }
    /// Reverses the byte order of the integer.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x12345678901234567890123456789012u128)?;"]
    /// let m = n.swap_bytes();
    ///
    #[doc =
    "assert_eq!(m, NonZero::new(0x12907856341290785634129078563412)?);"]
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn swap_bytes(self) -> Self {
        let result = self.get().swap_bytes();
        unsafe { Self::new_unchecked(result) }
    }
    /// Reverses the order of bits in the integer. The least significant bit becomes the most significant bit,
    /// second least-significant bit becomes second most-significant bit, etc.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x12345678901234567890123456789012u128)?;"]
    /// let m = n.reverse_bits();
    ///
    #[doc =
    "assert_eq!(m, NonZero::new(0x48091e6a2c48091e6a2c48091e6a2c48)?);"]
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn reverse_bits(self) -> Self {
        let result = self.get().reverse_bits();
        unsafe { Self::new_unchecked(result) }
    }
    /// Converts an integer from big endian to the target's endianness.
    ///
    /// On big endian this is a no-op. On little endian the bytes are
    /// swapped.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    #[doc = "use std::num::NonZeroU128;"]
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x1Au128)?;"]
    ///
    /// if cfg!(target_endian = "big") {
    #[doc = "    assert_eq!(NonZeroU128::from_be(n), n)"]
    /// } else {
    #[doc = "    assert_eq!(NonZeroU128::from_be(n), n.swap_bytes())"]
    /// }
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use]
    #[inline(always)]
    pub const fn from_be(x: Self) -> Self {
        let result = u128::from_be(x.get());
        unsafe { Self::new_unchecked(result) }
    }
    /// Converts an integer from little endian to the target's endianness.
    ///
    /// On little endian this is a no-op. On big endian the bytes are
    /// swapped.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    #[doc = "use std::num::NonZeroU128;"]
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x1Au128)?;"]
    ///
    /// if cfg!(target_endian = "little") {
    #[doc = "    assert_eq!(NonZeroU128::from_le(n), n)"]
    /// } else {
    #[doc = "    assert_eq!(NonZeroU128::from_le(n), n.swap_bytes())"]
    /// }
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use]
    #[inline(always)]
    pub const fn from_le(x: Self) -> Self {
        let result = u128::from_le(x.get());
        unsafe { Self::new_unchecked(result) }
    }
    /// Converts `self` to big endian from the target's endianness.
    ///
    /// On big endian this is a no-op. On little endian the bytes are
    /// swapped.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x1Au128)?;"]
    ///
    /// if cfg!(target_endian = "big") {
    ///     assert_eq!(n.to_be(), n)
    /// } else {
    ///     assert_eq!(n.to_be(), n.swap_bytes())
    /// }
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn to_be(self) -> Self {
        let result = self.get().to_be();
        unsafe { Self::new_unchecked(result) }
    }
    /// Converts `self` to little endian from the target's endianness.
    ///
    /// On little endian this is a no-op. On big endian the bytes are
    /// swapped.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x1Au128)?;"]
    ///
    /// if cfg!(target_endian = "little") {
    ///     assert_eq!(n.to_le(), n)
    /// } else {
    ///     assert_eq!(n.to_le(), n.swap_bytes())
    /// }
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn to_le(self) -> Self {
        let result = self.get().to_le();
        unsafe { Self::new_unchecked(result) }
    }
    /// The smallest value that can be represented by this non-zero
    /// integer type, 1.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    #[doc = "assert_eq!(NonZero::<u128>::MIN.get(), 1u128);"]
    /// ```
    #[stable(feature = "nonzero_min_max", since = "1.70.0")]
    pub const MIN: Self = Self::new(1).unwrap();
    /// The largest value that can be represented by this non-zero
    /// integer type,
    #[doc = "equal to [`u128::MAX`]."]
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    #[doc = "assert_eq!(NonZero::<u128>::MAX.get(), u128::MAX);"]
    /// ```
    #[stable(feature = "nonzero_min_max", since = "1.70.0")]
    pub const MAX: Self = Self::new(<u128>::MAX).unwrap();
    /// Adds an unsigned integer to a non-zero value.
    /// Checks for overflow and returns [`None`] on overflow.
    /// As a consequence, the result cannot wrap to zero.
    ///
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let one = NonZero::new(1u128)?;"]
    #[doc = "let two = NonZero::new(2u128)?;"]
    #[doc = "let max = NonZero::new(u128::MAX)?;"]
    ///
    /// assert_eq!(Some(two), one.checked_add(1));
    /// assert_eq!(None, max.checked_add(1));
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const fn checked_add(self, other: u128) -> Option<Self> {
        if let Some(result) = self.get().checked_add(other) {
            Some(unsafe { Self::new_unchecked(result) })
        } else { None }
    }
    /// Adds an unsigned integer to a non-zero value, panicking
    /// if overflow occurs.
    ///
    /// # Panics
    ///
    /// ## Overflow behavior
    ///
    /// This function always panics on overflow, regardless of whether
    /// overflow checks are enabled.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_strict_ops)]
    ///
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let two = NonZero::new(2u128)?;"]
    #[doc = "let three = NonZero::new(3u128)?;"]
    ///
    /// assert_eq!(three, two.strict_add(1));
    /// # Some(())
    /// # }
    /// ```
    ///
    /// The following panics because of overflow:
    ///
    /// ```should_panic
    /// #![feature(nonzero_strict_ops)]
    ///
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let max = NonZero::new(u128::MAX)?;"]
    ///
    /// let _ = max.strict_add(1);
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_strict_ops", issue = "164850")]
    #[rustc_const_unstable(feature = "const_nonzero_strict_ops", issue =
    "164850")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    #[track_caller]
    pub const fn strict_add(self, other: u128) -> Self {
        unsafe { Self::new_unchecked(self.get().strict_add(other)) }
    }
    /// Adds an unsigned integer to a non-zero value.
    #[doc = "Return [`NonZero::<u128>::MAX`] on overflow."]
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let one = NonZero::new(1u128)?;"]
    #[doc = "let two = NonZero::new(2u128)?;"]
    #[doc = "let max = NonZero::new(u128::MAX)?;"]
    ///
    /// assert_eq!(two, one.saturating_add(1));
    /// assert_eq!(max, max.saturating_add(1));
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const fn saturating_add(self, other: u128) -> Self {
        unsafe { Self::new_unchecked(self.get().saturating_add(other)) }
    }
    /// Adds an unsigned integer to a non-zero value,
    /// assuming overflow cannot occur.
    /// Overflow is unchecked, and it is undefined behavior to overflow
    /// *even if the result would wrap to a non-zero value*.
    ///
    /// # Safety
    ///
    /// This results in undefined behavior when overflow occurs, i.e. when
    /// [`checked_add`] would return `None`.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let one = NonZero::new(1u128)?;"]
    #[doc = "let two = NonZero::new(2u128)?;"]
    ///
    /// assert_eq!(two, unsafe { one.unchecked_add(1) });
    /// # Some(())
    /// # }
    /// ```
    ///
    /// [`checked_add`]: Self::checked_add
    #[stable(feature = "nonzero_ops", since = "CURRENT_RUSTC_VERSION")]
    #[rustc_const_stable(feature = "nonzero_ops", since =
    "CURRENT_RUSTC_VERSION")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const unsafe fn unchecked_add(self, other: u128) -> Self {
        unsafe { Self::new_unchecked(self.get().unchecked_add(other)) }
    }
    /// Calculates the quotient of `self` and `rhs`, rounding the result towards positive infinity.
    ///
    /// The result is guaranteed to be non-zero.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    #[doc = "let one = NonZero::new(1u128).unwrap();"]
    #[doc = "let max = NonZero::new(u128::MAX).unwrap();"]
    /// assert_eq!(one.div_ceil(max), one);
    ///
    #[doc = "let two = NonZero::new(2u128).unwrap();"]
    #[doc = "let three = NonZero::new(3u128).unwrap();"]
    /// assert_eq!(three.div_ceil(two), two);
    /// ```
    #[stable(feature = "unsigned_nonzero_div_ceil", since = "1.92.0")]
    #[rustc_const_stable(feature = "unsigned_nonzero_div_ceil", since =
    "1.92.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const fn div_ceil(self, rhs: Self) -> Self {
        let v = (self.get() - 1) / rhs.get() + 1;
        unsafe { Self::new_unchecked(v) }
    }
    /// Returns the smallest power of two greater than or equal to `self`.
    /// Checks for overflow and returns [`None`]
    /// if the next power of two is greater than the type’s maximum value.
    /// As a consequence, the result cannot wrap to zero.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let two = NonZero::new(2u128)?;"]
    #[doc = "let three = NonZero::new(3u128)?;"]
    #[doc = "let four = NonZero::new(4u128)?;"]
    #[doc = "let max = NonZero::new(u128::MAX)?;"]
    ///
    /// assert_eq!(Some(two), two.checked_next_power_of_two() );
    /// assert_eq!(Some(four), three.checked_next_power_of_two() );
    /// assert_eq!(None, max.checked_next_power_of_two() );
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const fn checked_next_power_of_two(self) -> Option<Self> {
        if let Some(nz) = self.get().checked_next_power_of_two() {
            Some(unsafe { Self::new_unchecked(nz) })
        } else { None }
    }
    /// Returns the base 2 logarithm of the number, rounded down.
    ///
    /// This is the same operation as
    #[doc = "[`u128::ilog2`],"]
    /// except that it has no failure cases to worry about
    /// since this value can never be zero.
    ///
    /// Note that this is equivalent to [`highest_one`](Self::highest_one).
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "assert_eq!(NonZero::new(7u128)?.ilog2(), 2);"]
    #[doc = "assert_eq!(NonZero::new(8u128)?.ilog2(), 3);"]
    #[doc = "assert_eq!(NonZero::new(9u128)?.ilog2(), 3);"]
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "int_log", since = "1.67.0")]
    #[rustc_const_stable(feature = "int_log", since = "1.67.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const fn ilog2(self) -> u32 { Self::BITS - 1 - self.leading_zeros() }
    /// Returns the base 10 logarithm of the number, rounded down.
    ///
    /// This is the same operation as
    #[doc = "[`u128::ilog10`],"]
    /// except that it has no failure cases to worry about
    /// since this value can never be zero.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "assert_eq!(NonZero::new(99u128)?.ilog10(), 1);"]
    #[doc = "assert_eq!(NonZero::new(100u128)?.ilog10(), 2);"]
    #[doc = "assert_eq!(NonZero::new(101u128)?.ilog10(), 2);"]
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "int_log", since = "1.67.0")]
    #[rustc_const_stable(feature = "int_log", since = "1.67.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const fn ilog10(self) -> u32 { imp::int_log10::u128(self) }
    /// Calculates the midpoint (average) between `self` and `rhs`.
    ///
    /// `midpoint(a, b)` is `(a + b) >> 1` as if it were performed in a
    /// sufficiently-large signed integral type. This implies that the result is
    /// always rounded towards negative infinity and that no overflow will ever occur.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let one = NonZero::new(1u128)?;"]
    #[doc = "let two = NonZero::new(2u128)?;"]
    #[doc = "let four = NonZero::new(4u128)?;"]
    ///
    /// assert_eq!(one.midpoint(four), two);
    /// assert_eq!(four.midpoint(one), two);
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "num_midpoint", since = "1.85.0")]
    #[rustc_const_stable(feature = "num_midpoint", since = "1.85.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[doc(alias = "average_floor")]
    #[doc(alias = "average")]
    #[inline]
    pub const fn midpoint(self, rhs: Self) -> Self {
        unsafe { Self::new_unchecked(self.get().midpoint(rhs.get())) }
    }
    /// Returns `true` if and only if `self == (1 << k)` for some `k`.
    ///
    /// On many architectures, this function can perform better than `is_power_of_two()`
    /// on the underlying integer type, as special handling of zero can be avoided.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let eight = NonZero::new(8u128)?;"]
    /// assert!(eight.is_power_of_two());
    #[doc = "let ten = NonZero::new(10u128)?;"]
    /// assert!(!ten.is_power_of_two());
    /// # Some(())
    /// # }
    /// ```
    #[must_use]
    #[stable(feature = "nonzero_is_power_of_two", since = "1.59.0")]
    #[rustc_const_stable(feature = "nonzero_is_power_of_two", since =
    "1.59.0")]
    #[inline]
    pub const fn is_power_of_two(self) -> bool {
        intrinsics::ctpop(self.get()) < 2
    }
    /// Returns the square root of the number, rounded down.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let ten = NonZero::new(10u128)?;"]
    #[doc = "let three = NonZero::new(3u128)?;"]
    ///
    /// assert_eq!(ten.isqrt(), three);
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "isqrt", since = "1.84.0")]
    #[rustc_const_stable(feature = "isqrt", since = "1.84.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const fn isqrt(self) -> Self {
        let result = self.get().isqrt();
        unsafe { Self::new_unchecked(result) }
    }
    /// Returns the bit pattern of `self` reinterpreted as a signed integer of the same size.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    ///
    #[doc = "let n = NonZero::<u128>::MAX;"]
    ///
    #[doc = "assert_eq!(n.cast_signed(), NonZero::new(-1i128).unwrap());"]
    /// ```
    #[stable(feature = "integer_sign_cast", since = "1.87.0")]
    #[rustc_const_stable(feature = "integer_sign_cast", since = "1.87.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline(always)]
    pub const fn cast_signed(self) -> NonZero<i128> {
        unsafe { NonZero::new_unchecked(self.get().cast_signed()) }
    }
    /// Returns the minimum number of bits required to represent `self`.
    ///
    /// # Examples
    ///
    /// ```
    /// # use core::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc =
    "assert_eq!(NonZero::<u128>::new(0b1)?.bit_width(), NonZero::new(1)?);"]
    #[doc =
    "assert_eq!(NonZero::<u128>::new(0b111)?.bit_width(), NonZero::new(3)?);"]
    #[doc =
    "assert_eq!(NonZero::<u128>::new(0b1110)?.bit_width(), NonZero::new(4)?);"]
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "uint_bit_width", since = "1.97.0")]
    #[rustc_const_stable(feature = "uint_bit_width", since = "1.97.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline(always)]
    pub const fn bit_width(self) -> NonZero<u32> {
        unsafe { NonZero::new_unchecked(Self::BITS - self.leading_zeros()) }
    }
    /// Multiplies two non-zero integers together.
    /// Checks for overflow and returns [`None`] on overflow.
    /// As a consequence, the result cannot wrap to zero.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let two = NonZero::new(2u128)?;"]
    #[doc = "let four = NonZero::new(4u128)?;"]
    #[doc = "let max = NonZero::new(u128::MAX)?;"]
    ///
    /// assert_eq!(Some(four), two.checked_mul(two));
    /// assert_eq!(None, max.checked_mul(two));
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const fn checked_mul(self, other: Self) -> Option<Self> {
        if let Some(result) = self.get().checked_mul(other.get()) {
            Some(unsafe { Self::new_unchecked(result) })
        } else { None }
    }
    /// Multiplies two non-zero integers together, panicking if
    /// overflow occurs.
    ///
    /// # Panics
    ///
    /// ## Overflow behavior
    ///
    /// This function always panics on overflow, regardless of whether
    /// overflow checks are enabled.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_strict_ops)]
    ///
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let three = NonZero::new(3u128)?;"]
    #[doc = "let nine = NonZero::new(9u128)?;"]
    ///
    /// assert_eq!(nine, three.strict_mul(three));
    /// # Some(())
    /// # }
    /// ```
    ///
    /// The following panics because of overflow:
    ///
    /// ```should_panic
    /// #![feature(nonzero_strict_ops)]
    ///
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let two = NonZero::new(2u128)?;"]
    #[doc = "let max = NonZero::new(u128::MAX)?;"]
    ///
    /// let _ = max.strict_mul(two);
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_strict_ops", issue = "164850")]
    #[rustc_const_unstable(feature = "const_nonzero_strict_ops", issue =
    "164850")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    #[track_caller]
    pub const fn strict_mul(self, other: Self) -> Self {
        unsafe { Self::new_unchecked(self.get().strict_mul(other.get())) }
    }
    /// Multiplies two non-zero integers together.
    #[doc = "Return [`NonZero::<u128>::MAX`] on overflow."]
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let two = NonZero::new(2u128)?;"]
    #[doc = "let four = NonZero::new(4u128)?;"]
    #[doc = "let max = NonZero::new(u128::MAX)?;"]
    ///
    /// assert_eq!(four, two.saturating_mul(two));
    /// assert_eq!(max, four.saturating_mul(max));
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const fn saturating_mul(self, other: Self) -> Self {
        unsafe { Self::new_unchecked(self.get().saturating_mul(other.get())) }
    }
    /// Multiplies two non-zero integers together,
    /// assuming overflow cannot occur.
    /// Overflow is unchecked, and it is undefined behavior to overflow
    /// *even if the result would wrap to a non-zero value*.
    ///
    /// # Safety
    ///
    /// This results in undefined behavior when overflow occurs, i.e.
    /// when [`checked_mul`] would return `None`.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let two = NonZero::new(2u128)?;"]
    #[doc = "let four = NonZero::new(4u128)?;"]
    ///
    /// assert_eq!(four, unsafe { two.unchecked_mul(two) });
    /// # Some(())
    /// # }
    /// ```
    ///
    /// [`checked_mul`]: Self::checked_mul
    #[stable(feature = "nonzero_ops", since = "CURRENT_RUSTC_VERSION")]
    #[rustc_const_stable(feature = "nonzero_ops", since =
    "CURRENT_RUSTC_VERSION")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const unsafe fn unchecked_mul(self, other: Self) -> Self {
        unsafe { Self::new_unchecked(self.get().unchecked_mul(other.get())) }
    }
    /// Raises non-zero value to an integer power.
    /// Checks for overflow and returns [`None`] on overflow.
    /// As a consequence, the result cannot wrap to zero.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let three = NonZero::new(3u128)?;"]
    #[doc = "let twenty_seven = NonZero::new(27u128)?;"]
    #[doc = "let half_max = NonZero::new(u128::MAX / 2)?;"]
    ///
    /// assert_eq!(Some(twenty_seven), three.checked_pow(3));
    /// assert_eq!(None, half_max.checked_pow(3));
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const fn checked_pow(self, other: u32) -> Option<Self> {
        if let Some(result) = self.get().checked_pow(other) {
            Some(unsafe { Self::new_unchecked(result) })
        } else { None }
    }
    /// Raises a non-zero value to an integer power, panicking if
    /// overflow occurs.
    ///
    /// # Panics
    ///
    /// ## Overflow behavior
    ///
    /// This function always panics on overflow, regardless of whether
    /// overflow checks are enabled.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_strict_ops)]
    ///
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let two = NonZero::new(2u128)?;"]
    #[doc = "let sixteen = NonZero::new(16u128)?;"]
    ///
    /// assert_eq!(sixteen, two.strict_pow(4));
    /// # Some(())
    /// # }
    /// ```
    ///
    /// The following panics because of overflow:
    ///
    /// ```should_panic
    /// #![feature(nonzero_strict_ops)]
    ///
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let half_max = NonZero::new(u128::MAX / 2)?;"]
    ///
    /// let _ = half_max.strict_pow(2);
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_strict_ops", issue = "164850")]
    #[rustc_const_unstable(feature = "const_nonzero_strict_ops", issue =
    "164850")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    #[track_caller]
    pub const fn strict_pow(self, exp: u32) -> Self {
        unsafe { Self::new_unchecked(self.get().strict_pow(exp)) }
    }
    /// Raise non-zero value to an integer power.
    #[doc = "Return [`NonZero::<u128>::MAX`] on overflow."]
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let three = NonZero::new(3u128)?;"]
    #[doc = "let twenty_seven = NonZero::new(27u128)?;"]
    #[doc = "let max = NonZero::new(u128::MAX)?;"]
    ///
    /// assert_eq!(twenty_seven, three.saturating_pow(3));
    /// assert_eq!(max, max.saturating_pow(3));
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const fn saturating_pow(self, other: u32) -> Self {
        unsafe { Self::new_unchecked(self.get().saturating_pow(other)) }
    }
    /// Parses a non-zero integer from an ASCII-byte slice with decimal digits.
    ///
    /// The characters are expected to be an optional
    #[doc = " `+` "]
    /// sign followed by only digits. Leading and trailing non-digit characters (including
    /// whitespace) represent an error. Underscores (which are accepted in Rust literals)
    /// also represent an error.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc =
    "assert_eq!(NonZero::<u128>::from_ascii_bytes(b\"+10\"), Ok(NonZero::new(10)?));"]
    /// # Some(())
    /// # }
    /// ```
    ///
    /// Trailing space returns error:
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    #[doc = "assert!(NonZero::<u128>::from_ascii_bytes(b\"1 \").is_err());"]
    /// ```
    #[stable(feature = "int_from_ascii", since = "CURRENT_RUSTC_VERSION")]
    #[rustc_const_unstable(feature = "const_convert", issue = "143773")]
    #[inline]
    pub const fn from_ascii_bytes<T>(src: T) -> Result<Self, ParseIntError>
        where T: [const] AsRef<[u8]> + [const] crate::marker::Destruct {
        Self::from_ascii_bytes_radix_impl(src.as_ref(), 10)
    }
    /// Parses a non-zero integer from an ASCII-byte slice with digits in a given base.
    ///
    /// The characters are expected to be an optional
    #[doc = " `+` "]
    /// sign followed by only digits. Leading and trailing non-digit characters (including
    /// whitespace) represent an error. Underscores (which are accepted in Rust literals)
    /// also represent an error.
    ///
    /// Digits are a subset of these characters, depending on `radix`:
    ///
    /// - `0-9`
    /// - `a-z`
    /// - `A-Z`
    ///
    /// # Panics
    ///
    /// This method panics if `radix` is not in the range from 2 to 36.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc =
    "assert_eq!(NonZero::<u128>::from_ascii_bytes_radix(b\"A\", 16), Ok(NonZero::new(10)?));"]
    /// # Some(())
    /// # }
    /// ```
    ///
    /// Trailing space returns error:
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    #[doc =
    "assert!(NonZero::<u128>::from_ascii_bytes_radix(b\"1 \", 10).is_err());"]
    /// ```
    #[stable(feature = "int_from_ascii", since = "CURRENT_RUSTC_VERSION")]
    #[rustc_const_unstable(feature = "const_convert", issue = "143773")]
    #[inline]
    pub const fn from_ascii_bytes_radix<T>(src: T, radix: u32)
        -> Result<Self, ParseIntError> where T: [const] AsRef<[u8]> + [const]
        crate::marker::Destruct {
        Self::from_ascii_bytes_radix_impl(src.as_ref(), radix)
    }
    #[inline]
    const fn from_ascii_bytes_radix_impl(src: &[u8], radix: u32)
        -> Result<Self, ParseIntError> {
        let n =
            match <u128>::from_ascii_bytes_radix_impl(src, radix) {
                Ok(n) => n,
                Err(err) => return Err(err),
            };
        if let Some(n) = Self::new(n) {
            Ok(n)
        } else { Err(ParseIntError { kind: IntErrorKind::Zero }) }
    }
    /// Parses a non-zero integer from a string slice with digits in a given base.
    ///
    /// The string is expected to be an optional
    #[doc = " `+` "]
    /// sign followed by only digits. Leading and trailing non-digit characters (including
    /// whitespace) represent an error. Underscores (which are accepted in Rust literals)
    /// also represent an error.
    ///
    /// Digits are a subset of these characters, depending on `radix`:
    ///
    /// - `0-9`
    /// - `a-z`
    /// - `A-Z`
    ///
    /// # Panics
    ///
    /// This method panics if `radix` is not in the range from 2 to 36.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc =
    "assert_eq!(NonZero::<u128>::from_str_radix(\"A\", 16), Ok(NonZero::new(10)?));"]
    /// # Some(())
    /// # }
    /// ```
    ///
    /// Trailing space returns error:
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    #[doc = "assert!(NonZero::<u128>::from_str_radix(\"1 \", 10).is_err());"]
    /// ```
    #[stable(feature = "nonzero_from_str_radix", since = "1.98.0")]
    #[rustc_const_stable(feature = "nonzero_from_str_radix", since =
    "1.98.0")]
    #[inline]
    pub const fn from_str_radix(src: &str, radix: u32)
        -> Result<Self, ParseIntError> {
        Self::from_ascii_bytes_radix_impl(src.as_bytes(), radix)
    }
}
#[stable(feature = "nonzero_parse", since = "1.35.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl FromStr for NonZero<u128> {
    type Err = ParseIntError;
    /// Parses a non-zero integer from a string slice with decimal digits.
    ///
    /// The characters are expected to be an optional
    #[doc = " `+` "]
    /// sign followed by only digits. Leading and trailing non-digit characters (including
    /// whitespace) represent an error. Underscores (which are accepted in Rust literals)
    /// also represent an error.
    ///
    /// # Examples
    ///
    /// ```
    /// use std::num::NonZero;
    /// use std::str::FromStr;
    ///
    #[doc =
    "assert_eq!(NonZero::<u128>::from_str(\"+10\"), Ok(NonZero::new(10).unwrap()));"]
    /// ```
    ///
    /// Trailing space returns error:
    ///
    /// ```
    /// use std::num::NonZero;
    /// use std::str::FromStr;
    ///
    #[doc = "assert!(NonZero::<u128>::from_str(\"1 \").is_err());"]
    /// ```
    #[inline]
    fn from_str(src: &str) -> Result<Self, Self::Err> {
        Self::from_str_radix(src, 10)
    }
}
#[stable(feature = "nonzero_div", since = "1.51.0")]
#[rustc_const_unstable(feature = "const_ops", issue = "143802")]
const impl Div<NonZero<u128>> for u128 {
    type Output = u128;
    /// Same as `self / other.get()`, but because `other` is a `NonZero<_>`,
    /// there's never a runtime check for division-by-zero.
    ///
    /// This operation rounds towards zero, truncating any fractional
    /// part of the exact result, and cannot panic.
    #[doc(alias = "unchecked_div")]
    #[inline]
    fn div(self, other: NonZero<u128>) -> u128 {
        unsafe { intrinsics::unchecked_div(self, other.get()) }
    }
}
#[stable(feature = "nonzero_div_assign", since = "1.79.0")]
#[rustc_const_unstable(feature = "const_ops", issue = "143802")]
const impl DivAssign<NonZero<u128>> for u128 {
    /// Same as `self /= other.get()`, but because `other` is a `NonZero<_>`,
    /// there's never a runtime check for division-by-zero.
    ///
    /// This operation rounds towards zero, truncating any fractional
    /// part of the exact result, and cannot panic.
    #[inline]
    fn div_assign(&mut self, other: NonZero<u128>) { *self = *self / other; }
}
#[stable(feature = "nonzero_div", since = "1.51.0")]
#[rustc_const_unstable(feature = "const_ops", issue = "143802")]
const impl Rem<NonZero<u128>> for u128 {
    type Output = u128;
    /// This operation satisfies `n % d == n - (n / d) * d`, and cannot panic.
    #[inline]
    fn rem(self, other: NonZero<u128>) -> u128 {
        unsafe { intrinsics::unchecked_rem(self, other.get()) }
    }
}
#[stable(feature = "nonzero_div_assign", since = "1.79.0")]
#[rustc_const_unstable(feature = "const_ops", issue = "143802")]
const impl RemAssign<NonZero<u128>> for u128 {
    /// This operation satisfies `n % d == n - (n / d) * d`, and cannot panic.
    #[inline]
    fn rem_assign(&mut self, other: NonZero<u128>) { *self = *self % other; }
}nonzero_integer! {
2942    Self = NonZeroU128,
2943    Primitive = unsigned u128,
2944    SignedPrimitive = i128,
2945    rot = 16,
2946    rot_op = "0x13f40000000000000000000000004f76",
2947    rot_result = "0x4f7613f4",
2948    swap_op = "0x12345678901234567890123456789012",
2949    swapped = "0x12907856341290785634129078563412",
2950    reversed = "0x48091e6a2c48091e6a2c48091e6a2c48",
2951}
2952
2953#[cfg(target_pointer_width = "16")]
2954nonzero_integer! {
2955    Self = NonZeroUsize,
2956    Primitive = unsigned usize,
2957    SignedPrimitive = isize,
2958    rot = 4,
2959    rot_op = "0xa003",
2960    rot_result = "0x3a",
2961    swap_op = "0x1234",
2962    swapped = "0x3412",
2963    reversed = "0x2c48",
2964}
2965
2966#[cfg(target_pointer_width = "32")]
2967nonzero_integer! {
2968    Self = NonZeroUsize,
2969    Primitive = unsigned usize,
2970    SignedPrimitive = isize,
2971    rot = 8,
2972    rot_op = "0x10000b3",
2973    rot_result = "0xb301",
2974    swap_op = "0x12345678",
2975    swapped = "0x78563412",
2976    reversed = "0x1e6a2c48",
2977}
2978
2979#[cfg(target_pointer_width = "64")]
2980#[doc = "A [`usize`] that is known not to equal zero."]
///
/// This enables some memory layout optimization.
#[doc = "For example, `Option<NonZeroUsize>` is the same size as `usize`:"]
///
/// ```rust
#[doc =
"assert_eq!(size_of::<Option<core::num::NonZeroUsize>>(), size_of::<usize>());"]
/// ```
///
/// # Layout
///
#[doc =
"`NonZeroUsize` is guaranteed to have the same layout and bit validity as `usize`"]
/// with the exception that `0` is not a valid instance.
#[doc =
"`Option<NonZeroUsize>` is guaranteed to be ABI-compatible with `usize`,"]
/// including in FFI.
///
/// Thanks to the [null pointer optimization],
#[doc = "`NonZeroUsize` and `Option<NonZeroUsize>`"]
/// are guaranteed to have the same size and alignment:
///
/// ```
#[doc = "use std::num::NonZeroUsize;"]
///
#[doc =
"assert_eq!(size_of::<NonZeroUsize>(), size_of::<Option<NonZeroUsize>>());"]
#[doc =
"assert_eq!(align_of::<NonZeroUsize>(), align_of::<Option<NonZeroUsize>>());"]
/// ```
///
/// # Compile-time creation
///
/// Since both [`Option::unwrap()`] and [`Option::expect()`] are `const`, it is possible to
/// define a new
#[doc = "`NonZeroUsize`"]
/// at compile time via:
/// ```
#[doc = "use std::num::NonZeroUsize;"]
///
#[doc =
"const TEN: NonZeroUsize = NonZeroUsize::new(10).expect(\"ten is non-zero\");"]
/// ```
///
/// [null pointer optimization]: crate::option#representation
#[stable(feature = "nonzero", since = "1.28.0")]
pub type NonZeroUsize = NonZero<usize>;
impl NonZero<usize> {
    /// The size of this non-zero integer type in bits.
    ///
    #[doc = "This value is equal to [`usize::BITS`]."]
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    #[doc = "assert_eq!(NonZero::<usize>::BITS, usize::BITS);"]
    /// ```
    #[stable(feature = "nonzero_bits", since = "1.67.0")]
    pub const BITS: u32 = <usize>::BITS;
    /// Returns the number of leading zeros in the binary representation of `self`.
    ///
    /// On many architectures, this function can perform better than `leading_zeros()` on the underlying integer type, as special handling of zero can be avoided.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::<usize>::new(usize::MAX)?;"]
    ///
    /// assert_eq!(n.leading_zeros(), 0);
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_leading_trailing_zeros", since = "1.53.0")]
    #[rustc_const_stable(feature = "nonzero_leading_trailing_zeros", since =
    "1.53.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const fn leading_zeros(self) -> u32 {
        unsafe { intrinsics::ctlz_nonzero(self.get() as usize) }
    }
    /// Returns the number of trailing zeros in the binary representation
    /// of `self`.
    ///
    /// On many architectures, this function can perform better than `trailing_zeros()` on the underlying integer type, as special handling of zero can be avoided.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::<usize>::new(0b0101000)?;"]
    ///
    /// assert_eq!(n.trailing_zeros(), 3);
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_leading_trailing_zeros", since = "1.53.0")]
    #[rustc_const_stable(feature = "nonzero_leading_trailing_zeros", since =
    "1.53.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const fn trailing_zeros(self) -> u32 {
        unsafe { intrinsics::cttz_nonzero(self.get() as usize) }
    }
    /// Returns `self` with only the most significant bit set.
    ///
    /// # Example
    ///
    /// ```
    /// # use core::num::NonZero;
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let a = NonZero::<usize>::new(0b_01100100)?;"]
    #[doc = "let b = NonZero::<usize>::new(0b_01000000)?;"]
    ///
    /// assert_eq!(a.isolate_highest_one(), b);
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "isolate_most_least_significant_one", since =
    "1.97.0")]
    #[rustc_const_stable(feature = "isolate_most_least_significant_one", since
    = "1.97.0")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn isolate_highest_one(self) -> Self {
        unsafe {
            let bit =
                (((1 as usize) <<
                                (<usize>::BITS - 1)).unchecked_shr(self.leading_zeros()));
            NonZero::new_unchecked(bit as usize)
        }
    }
    /// Returns `self` with only the least significant bit set.
    ///
    /// # Example
    ///
    /// ```
    /// # use core::num::NonZero;
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let a = NonZero::<usize>::new(0b_01100100)?;"]
    #[doc = "let b = NonZero::<usize>::new(0b_00000100)?;"]
    ///
    /// assert_eq!(a.isolate_lowest_one(), b);
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "isolate_most_least_significant_one", since =
    "1.97.0")]
    #[rustc_const_stable(feature = "isolate_most_least_significant_one", since
    = "1.97.0")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn isolate_lowest_one(self) -> Self {
        let n = self.get();
        let n = n & n.wrapping_neg();
        unsafe { NonZero::new_unchecked(n) }
    }
    /// Returns the index of the highest bit set to one in `self`.
    ///
    #[doc = "Note that this is equivalent to [`ilog2`](Self::ilog2)."]
    ///
    /// # Examples
    ///
    /// ```
    /// # use core::num::NonZero;
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "assert_eq!(NonZero::<usize>::new(0b1)?.highest_one(), 0);"]
    #[doc = "assert_eq!(NonZero::<usize>::new(0b1_0000)?.highest_one(), 4);"]
    #[doc = "assert_eq!(NonZero::<usize>::new(0b1_1111)?.highest_one(), 4);"]
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "int_lowest_highest_one", since = "1.97.0")]
    #[rustc_const_stable(feature = "int_lowest_highest_one", since =
    "1.97.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline(always)]
    pub const fn highest_one(self) -> u32 {
        Self::BITS - 1 - self.leading_zeros()
    }
    /// Returns the index of the lowest bit set to one in `self`.
    ///
    /// # Examples
    ///
    /// ```
    /// # use core::num::NonZero;
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "assert_eq!(NonZero::<usize>::new(0b1)?.lowest_one(), 0);"]
    #[doc = "assert_eq!(NonZero::<usize>::new(0b1_0000)?.lowest_one(), 4);"]
    #[doc = "assert_eq!(NonZero::<usize>::new(0b1_1111)?.lowest_one(), 0);"]
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "int_lowest_highest_one", since = "1.97.0")]
    #[rustc_const_stable(feature = "int_lowest_highest_one", since =
    "1.97.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline(always)]
    pub const fn lowest_one(self) -> u32 { self.trailing_zeros() }
    /// Returns the number of ones in the binary representation of `self`.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let a = NonZero::<usize>::new(0b100_0000)?;"]
    #[doc = "let b = NonZero::<usize>::new(0b100_0011)?;"]
    ///
    /// assert_eq!(a.count_ones(), NonZero::new(1)?);
    /// assert_eq!(b.count_ones(), NonZero::new(3)?);
    /// # Some(())
    /// # }
    /// ```
    ///
    #[stable(feature = "non_zero_count_ones", since = "1.86.0")]
    #[rustc_const_stable(feature = "non_zero_count_ones", since = "1.86.0")]
    #[doc(alias = "popcount")]
    #[doc(alias = "popcnt")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn count_ones(self) -> NonZero<u32> {
        unsafe { NonZero::new_unchecked(self.get().count_ones()) }
    }
    /// Shifts the bits to the left by a specified amount, `n`,
    /// wrapping the truncated bits to the end of the resulting integer.
    ///
    /// Please note this isn't the same operation as the `<<` shifting operator!
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0xaa00000000006e1usize)?;"]
    #[doc = "let m = NonZero::new(0x6e10aa)?;"]
    ///
    #[doc = "assert_eq!(n.rotate_left(12), m);"]
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn rotate_left(self, n: u32) -> Self {
        let result = self.get().rotate_left(n);
        unsafe { Self::new_unchecked(result) }
    }
    /// Shifts the bits to the right by a specified amount, `n`,
    /// wrapping the truncated bits to the beginning of the resulting
    /// integer.
    ///
    /// Please note this isn't the same operation as the `>>` shifting operator!
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x6e10aausize)?;"]
    #[doc = "let m = NonZero::new(0xaa00000000006e1)?;"]
    ///
    #[doc = "assert_eq!(n.rotate_right(12), m);"]
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn rotate_right(self, n: u32) -> Self {
        let result = self.get().rotate_right(n);
        unsafe { Self::new_unchecked(result) }
    }
    /// Reverses the byte order of the integer.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x1234567890123456usize)?;"]
    /// let m = n.swap_bytes();
    ///
    #[doc = "assert_eq!(m, NonZero::new(0x5634129078563412)?);"]
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn swap_bytes(self) -> Self {
        let result = self.get().swap_bytes();
        unsafe { Self::new_unchecked(result) }
    }
    /// Reverses the order of bits in the integer. The least significant bit becomes the most significant bit,
    /// second least-significant bit becomes second most-significant bit, etc.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x1234567890123456usize)?;"]
    /// let m = n.reverse_bits();
    ///
    #[doc = "assert_eq!(m, NonZero::new(0x6a2c48091e6a2c48)?);"]
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn reverse_bits(self) -> Self {
        let result = self.get().reverse_bits();
        unsafe { Self::new_unchecked(result) }
    }
    /// Converts an integer from big endian to the target's endianness.
    ///
    /// On big endian this is a no-op. On little endian the bytes are
    /// swapped.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    #[doc = "use std::num::NonZeroUsize;"]
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x1Ausize)?;"]
    ///
    /// if cfg!(target_endian = "big") {
    #[doc = "    assert_eq!(NonZeroUsize::from_be(n), n)"]
    /// } else {
    #[doc = "    assert_eq!(NonZeroUsize::from_be(n), n.swap_bytes())"]
    /// }
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use]
    #[inline(always)]
    pub const fn from_be(x: Self) -> Self {
        let result = usize::from_be(x.get());
        unsafe { Self::new_unchecked(result) }
    }
    /// Converts an integer from little endian to the target's endianness.
    ///
    /// On little endian this is a no-op. On big endian the bytes are
    /// swapped.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    #[doc = "use std::num::NonZeroUsize;"]
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x1Ausize)?;"]
    ///
    /// if cfg!(target_endian = "little") {
    #[doc = "    assert_eq!(NonZeroUsize::from_le(n), n)"]
    /// } else {
    #[doc = "    assert_eq!(NonZeroUsize::from_le(n), n.swap_bytes())"]
    /// }
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use]
    #[inline(always)]
    pub const fn from_le(x: Self) -> Self {
        let result = usize::from_le(x.get());
        unsafe { Self::new_unchecked(result) }
    }
    /// Converts `self` to big endian from the target's endianness.
    ///
    /// On big endian this is a no-op. On little endian the bytes are
    /// swapped.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x1Ausize)?;"]
    ///
    /// if cfg!(target_endian = "big") {
    ///     assert_eq!(n.to_be(), n)
    /// } else {
    ///     assert_eq!(n.to_be(), n.swap_bytes())
    /// }
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn to_be(self) -> Self {
        let result = self.get().to_be();
        unsafe { Self::new_unchecked(result) }
    }
    /// Converts `self` to little endian from the target's endianness.
    ///
    /// On little endian this is a no-op. On big endian the bytes are
    /// swapped.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x1Ausize)?;"]
    ///
    /// if cfg!(target_endian = "little") {
    ///     assert_eq!(n.to_le(), n)
    /// } else {
    ///     assert_eq!(n.to_le(), n.swap_bytes())
    /// }
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn to_le(self) -> Self {
        let result = self.get().to_le();
        unsafe { Self::new_unchecked(result) }
    }
    /// The smallest value that can be represented by this non-zero
    /// integer type, 1.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    #[doc = "assert_eq!(NonZero::<usize>::MIN.get(), 1usize);"]
    /// ```
    #[stable(feature = "nonzero_min_max", since = "1.70.0")]
    pub const MIN: Self = Self::new(1).unwrap();
    /// The largest value that can be represented by this non-zero
    /// integer type,
    #[doc = "equal to [`usize::MAX`]."]
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    #[doc = "assert_eq!(NonZero::<usize>::MAX.get(), usize::MAX);"]
    /// ```
    #[stable(feature = "nonzero_min_max", since = "1.70.0")]
    pub const MAX: Self = Self::new(<usize>::MAX).unwrap();
    /// Adds an unsigned integer to a non-zero value.
    /// Checks for overflow and returns [`None`] on overflow.
    /// As a consequence, the result cannot wrap to zero.
    ///
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let one = NonZero::new(1usize)?;"]
    #[doc = "let two = NonZero::new(2usize)?;"]
    #[doc = "let max = NonZero::new(usize::MAX)?;"]
    ///
    /// assert_eq!(Some(two), one.checked_add(1));
    /// assert_eq!(None, max.checked_add(1));
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const fn checked_add(self, other: usize) -> Option<Self> {
        if let Some(result) = self.get().checked_add(other) {
            Some(unsafe { Self::new_unchecked(result) })
        } else { None }
    }
    /// Adds an unsigned integer to a non-zero value, panicking
    /// if overflow occurs.
    ///
    /// # Panics
    ///
    /// ## Overflow behavior
    ///
    /// This function always panics on overflow, regardless of whether
    /// overflow checks are enabled.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_strict_ops)]
    ///
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let two = NonZero::new(2usize)?;"]
    #[doc = "let three = NonZero::new(3usize)?;"]
    ///
    /// assert_eq!(three, two.strict_add(1));
    /// # Some(())
    /// # }
    /// ```
    ///
    /// The following panics because of overflow:
    ///
    /// ```should_panic
    /// #![feature(nonzero_strict_ops)]
    ///
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let max = NonZero::new(usize::MAX)?;"]
    ///
    /// let _ = max.strict_add(1);
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_strict_ops", issue = "164850")]
    #[rustc_const_unstable(feature = "const_nonzero_strict_ops", issue =
    "164850")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    #[track_caller]
    pub const fn strict_add(self, other: usize) -> Self {
        unsafe { Self::new_unchecked(self.get().strict_add(other)) }
    }
    /// Adds an unsigned integer to a non-zero value.
    #[doc = "Return [`NonZero::<usize>::MAX`] on overflow."]
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let one = NonZero::new(1usize)?;"]
    #[doc = "let two = NonZero::new(2usize)?;"]
    #[doc = "let max = NonZero::new(usize::MAX)?;"]
    ///
    /// assert_eq!(two, one.saturating_add(1));
    /// assert_eq!(max, max.saturating_add(1));
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const fn saturating_add(self, other: usize) -> Self {
        unsafe { Self::new_unchecked(self.get().saturating_add(other)) }
    }
    /// Adds an unsigned integer to a non-zero value,
    /// assuming overflow cannot occur.
    /// Overflow is unchecked, and it is undefined behavior to overflow
    /// *even if the result would wrap to a non-zero value*.
    ///
    /// # Safety
    ///
    /// This results in undefined behavior when overflow occurs, i.e. when
    /// [`checked_add`] would return `None`.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let one = NonZero::new(1usize)?;"]
    #[doc = "let two = NonZero::new(2usize)?;"]
    ///
    /// assert_eq!(two, unsafe { one.unchecked_add(1) });
    /// # Some(())
    /// # }
    /// ```
    ///
    /// [`checked_add`]: Self::checked_add
    #[stable(feature = "nonzero_ops", since = "CURRENT_RUSTC_VERSION")]
    #[rustc_const_stable(feature = "nonzero_ops", since =
    "CURRENT_RUSTC_VERSION")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const unsafe fn unchecked_add(self, other: usize) -> Self {
        unsafe { Self::new_unchecked(self.get().unchecked_add(other)) }
    }
    /// Calculates the quotient of `self` and `rhs`, rounding the result towards positive infinity.
    ///
    /// The result is guaranteed to be non-zero.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    #[doc = "let one = NonZero::new(1usize).unwrap();"]
    #[doc = "let max = NonZero::new(usize::MAX).unwrap();"]
    /// assert_eq!(one.div_ceil(max), one);
    ///
    #[doc = "let two = NonZero::new(2usize).unwrap();"]
    #[doc = "let three = NonZero::new(3usize).unwrap();"]
    /// assert_eq!(three.div_ceil(two), two);
    /// ```
    #[stable(feature = "unsigned_nonzero_div_ceil", since = "1.92.0")]
    #[rustc_const_stable(feature = "unsigned_nonzero_div_ceil", since =
    "1.92.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const fn div_ceil(self, rhs: Self) -> Self {
        let v = (self.get() - 1) / rhs.get() + 1;
        unsafe { Self::new_unchecked(v) }
    }
    /// Returns the smallest power of two greater than or equal to `self`.
    /// Checks for overflow and returns [`None`]
    /// if the next power of two is greater than the type’s maximum value.
    /// As a consequence, the result cannot wrap to zero.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let two = NonZero::new(2usize)?;"]
    #[doc = "let three = NonZero::new(3usize)?;"]
    #[doc = "let four = NonZero::new(4usize)?;"]
    #[doc = "let max = NonZero::new(usize::MAX)?;"]
    ///
    /// assert_eq!(Some(two), two.checked_next_power_of_two() );
    /// assert_eq!(Some(four), three.checked_next_power_of_two() );
    /// assert_eq!(None, max.checked_next_power_of_two() );
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const fn checked_next_power_of_two(self) -> Option<Self> {
        if let Some(nz) = self.get().checked_next_power_of_two() {
            Some(unsafe { Self::new_unchecked(nz) })
        } else { None }
    }
    /// Returns the base 2 logarithm of the number, rounded down.
    ///
    /// This is the same operation as
    #[doc = "[`usize::ilog2`],"]
    /// except that it has no failure cases to worry about
    /// since this value can never be zero.
    ///
    /// Note that this is equivalent to [`highest_one`](Self::highest_one).
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "assert_eq!(NonZero::new(7usize)?.ilog2(), 2);"]
    #[doc = "assert_eq!(NonZero::new(8usize)?.ilog2(), 3);"]
    #[doc = "assert_eq!(NonZero::new(9usize)?.ilog2(), 3);"]
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "int_log", since = "1.67.0")]
    #[rustc_const_stable(feature = "int_log", since = "1.67.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const fn ilog2(self) -> u32 { Self::BITS - 1 - self.leading_zeros() }
    /// Returns the base 10 logarithm of the number, rounded down.
    ///
    /// This is the same operation as
    #[doc = "[`usize::ilog10`],"]
    /// except that it has no failure cases to worry about
    /// since this value can never be zero.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "assert_eq!(NonZero::new(99usize)?.ilog10(), 1);"]
    #[doc = "assert_eq!(NonZero::new(100usize)?.ilog10(), 2);"]
    #[doc = "assert_eq!(NonZero::new(101usize)?.ilog10(), 2);"]
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "int_log", since = "1.67.0")]
    #[rustc_const_stable(feature = "int_log", since = "1.67.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const fn ilog10(self) -> u32 { imp::int_log10::usize(self) }
    /// Calculates the midpoint (average) between `self` and `rhs`.
    ///
    /// `midpoint(a, b)` is `(a + b) >> 1` as if it were performed in a
    /// sufficiently-large signed integral type. This implies that the result is
    /// always rounded towards negative infinity and that no overflow will ever occur.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let one = NonZero::new(1usize)?;"]
    #[doc = "let two = NonZero::new(2usize)?;"]
    #[doc = "let four = NonZero::new(4usize)?;"]
    ///
    /// assert_eq!(one.midpoint(four), two);
    /// assert_eq!(four.midpoint(one), two);
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "num_midpoint", since = "1.85.0")]
    #[rustc_const_stable(feature = "num_midpoint", since = "1.85.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[doc(alias = "average_floor")]
    #[doc(alias = "average")]
    #[inline]
    pub const fn midpoint(self, rhs: Self) -> Self {
        unsafe { Self::new_unchecked(self.get().midpoint(rhs.get())) }
    }
    /// Returns `true` if and only if `self == (1 << k)` for some `k`.
    ///
    /// On many architectures, this function can perform better than `is_power_of_two()`
    /// on the underlying integer type, as special handling of zero can be avoided.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let eight = NonZero::new(8usize)?;"]
    /// assert!(eight.is_power_of_two());
    #[doc = "let ten = NonZero::new(10usize)?;"]
    /// assert!(!ten.is_power_of_two());
    /// # Some(())
    /// # }
    /// ```
    #[must_use]
    #[stable(feature = "nonzero_is_power_of_two", since = "1.59.0")]
    #[rustc_const_stable(feature = "nonzero_is_power_of_two", since =
    "1.59.0")]
    #[inline]
    pub const fn is_power_of_two(self) -> bool {
        intrinsics::ctpop(self.get()) < 2
    }
    /// Returns the square root of the number, rounded down.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let ten = NonZero::new(10usize)?;"]
    #[doc = "let three = NonZero::new(3usize)?;"]
    ///
    /// assert_eq!(ten.isqrt(), three);
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "isqrt", since = "1.84.0")]
    #[rustc_const_stable(feature = "isqrt", since = "1.84.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const fn isqrt(self) -> Self {
        let result = self.get().isqrt();
        unsafe { Self::new_unchecked(result) }
    }
    /// Returns the bit pattern of `self` reinterpreted as a signed integer of the same size.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    ///
    #[doc = "let n = NonZero::<usize>::MAX;"]
    ///
    #[doc = "assert_eq!(n.cast_signed(), NonZero::new(-1isize).unwrap());"]
    /// ```
    #[stable(feature = "integer_sign_cast", since = "1.87.0")]
    #[rustc_const_stable(feature = "integer_sign_cast", since = "1.87.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline(always)]
    pub const fn cast_signed(self) -> NonZero<isize> {
        unsafe { NonZero::new_unchecked(self.get().cast_signed()) }
    }
    /// Returns the minimum number of bits required to represent `self`.
    ///
    /// # Examples
    ///
    /// ```
    /// # use core::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc =
    "assert_eq!(NonZero::<usize>::new(0b1)?.bit_width(), NonZero::new(1)?);"]
    #[doc =
    "assert_eq!(NonZero::<usize>::new(0b111)?.bit_width(), NonZero::new(3)?);"]
    #[doc =
    "assert_eq!(NonZero::<usize>::new(0b1110)?.bit_width(), NonZero::new(4)?);"]
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "uint_bit_width", since = "1.97.0")]
    #[rustc_const_stable(feature = "uint_bit_width", since = "1.97.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline(always)]
    pub const fn bit_width(self) -> NonZero<u32> {
        unsafe { NonZero::new_unchecked(Self::BITS - self.leading_zeros()) }
    }
    /// Multiplies two non-zero integers together.
    /// Checks for overflow and returns [`None`] on overflow.
    /// As a consequence, the result cannot wrap to zero.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let two = NonZero::new(2usize)?;"]
    #[doc = "let four = NonZero::new(4usize)?;"]
    #[doc = "let max = NonZero::new(usize::MAX)?;"]
    ///
    /// assert_eq!(Some(four), two.checked_mul(two));
    /// assert_eq!(None, max.checked_mul(two));
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const fn checked_mul(self, other: Self) -> Option<Self> {
        if let Some(result) = self.get().checked_mul(other.get()) {
            Some(unsafe { Self::new_unchecked(result) })
        } else { None }
    }
    /// Multiplies two non-zero integers together, panicking if
    /// overflow occurs.
    ///
    /// # Panics
    ///
    /// ## Overflow behavior
    ///
    /// This function always panics on overflow, regardless of whether
    /// overflow checks are enabled.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_strict_ops)]
    ///
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let three = NonZero::new(3usize)?;"]
    #[doc = "let nine = NonZero::new(9usize)?;"]
    ///
    /// assert_eq!(nine, three.strict_mul(three));
    /// # Some(())
    /// # }
    /// ```
    ///
    /// The following panics because of overflow:
    ///
    /// ```should_panic
    /// #![feature(nonzero_strict_ops)]
    ///
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let two = NonZero::new(2usize)?;"]
    #[doc = "let max = NonZero::new(usize::MAX)?;"]
    ///
    /// let _ = max.strict_mul(two);
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_strict_ops", issue = "164850")]
    #[rustc_const_unstable(feature = "const_nonzero_strict_ops", issue =
    "164850")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    #[track_caller]
    pub const fn strict_mul(self, other: Self) -> Self {
        unsafe { Self::new_unchecked(self.get().strict_mul(other.get())) }
    }
    /// Multiplies two non-zero integers together.
    #[doc = "Return [`NonZero::<usize>::MAX`] on overflow."]
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let two = NonZero::new(2usize)?;"]
    #[doc = "let four = NonZero::new(4usize)?;"]
    #[doc = "let max = NonZero::new(usize::MAX)?;"]
    ///
    /// assert_eq!(four, two.saturating_mul(two));
    /// assert_eq!(max, four.saturating_mul(max));
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const fn saturating_mul(self, other: Self) -> Self {
        unsafe { Self::new_unchecked(self.get().saturating_mul(other.get())) }
    }
    /// Multiplies two non-zero integers together,
    /// assuming overflow cannot occur.
    /// Overflow is unchecked, and it is undefined behavior to overflow
    /// *even if the result would wrap to a non-zero value*.
    ///
    /// # Safety
    ///
    /// This results in undefined behavior when overflow occurs, i.e.
    /// when [`checked_mul`] would return `None`.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let two = NonZero::new(2usize)?;"]
    #[doc = "let four = NonZero::new(4usize)?;"]
    ///
    /// assert_eq!(four, unsafe { two.unchecked_mul(two) });
    /// # Some(())
    /// # }
    /// ```
    ///
    /// [`checked_mul`]: Self::checked_mul
    #[stable(feature = "nonzero_ops", since = "CURRENT_RUSTC_VERSION")]
    #[rustc_const_stable(feature = "nonzero_ops", since =
    "CURRENT_RUSTC_VERSION")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const unsafe fn unchecked_mul(self, other: Self) -> Self {
        unsafe { Self::new_unchecked(self.get().unchecked_mul(other.get())) }
    }
    /// Raises non-zero value to an integer power.
    /// Checks for overflow and returns [`None`] on overflow.
    /// As a consequence, the result cannot wrap to zero.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let three = NonZero::new(3usize)?;"]
    #[doc = "let twenty_seven = NonZero::new(27usize)?;"]
    #[doc = "let half_max = NonZero::new(usize::MAX / 2)?;"]
    ///
    /// assert_eq!(Some(twenty_seven), three.checked_pow(3));
    /// assert_eq!(None, half_max.checked_pow(3));
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const fn checked_pow(self, other: u32) -> Option<Self> {
        if let Some(result) = self.get().checked_pow(other) {
            Some(unsafe { Self::new_unchecked(result) })
        } else { None }
    }
    /// Raises a non-zero value to an integer power, panicking if
    /// overflow occurs.
    ///
    /// # Panics
    ///
    /// ## Overflow behavior
    ///
    /// This function always panics on overflow, regardless of whether
    /// overflow checks are enabled.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_strict_ops)]
    ///
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let two = NonZero::new(2usize)?;"]
    #[doc = "let sixteen = NonZero::new(16usize)?;"]
    ///
    /// assert_eq!(sixteen, two.strict_pow(4));
    /// # Some(())
    /// # }
    /// ```
    ///
    /// The following panics because of overflow:
    ///
    /// ```should_panic
    /// #![feature(nonzero_strict_ops)]
    ///
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let half_max = NonZero::new(usize::MAX / 2)?;"]
    ///
    /// let _ = half_max.strict_pow(2);
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_strict_ops", issue = "164850")]
    #[rustc_const_unstable(feature = "const_nonzero_strict_ops", issue =
    "164850")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    #[track_caller]
    pub const fn strict_pow(self, exp: u32) -> Self {
        unsafe { Self::new_unchecked(self.get().strict_pow(exp)) }
    }
    /// Raise non-zero value to an integer power.
    #[doc = "Return [`NonZero::<usize>::MAX`] on overflow."]
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let three = NonZero::new(3usize)?;"]
    #[doc = "let twenty_seven = NonZero::new(27usize)?;"]
    #[doc = "let max = NonZero::new(usize::MAX)?;"]
    ///
    /// assert_eq!(twenty_seven, three.saturating_pow(3));
    /// assert_eq!(max, max.saturating_pow(3));
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const fn saturating_pow(self, other: u32) -> Self {
        unsafe { Self::new_unchecked(self.get().saturating_pow(other)) }
    }
    /// Parses a non-zero integer from an ASCII-byte slice with decimal digits.
    ///
    /// The characters are expected to be an optional
    #[doc = " `+` "]
    /// sign followed by only digits. Leading and trailing non-digit characters (including
    /// whitespace) represent an error. Underscores (which are accepted in Rust literals)
    /// also represent an error.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc =
    "assert_eq!(NonZero::<usize>::from_ascii_bytes(b\"+10\"), Ok(NonZero::new(10)?));"]
    /// # Some(())
    /// # }
    /// ```
    ///
    /// Trailing space returns error:
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    #[doc = "assert!(NonZero::<usize>::from_ascii_bytes(b\"1 \").is_err());"]
    /// ```
    #[stable(feature = "int_from_ascii", since = "CURRENT_RUSTC_VERSION")]
    #[rustc_const_unstable(feature = "const_convert", issue = "143773")]
    #[inline]
    pub const fn from_ascii_bytes<T>(src: T) -> Result<Self, ParseIntError>
        where T: [const] AsRef<[u8]> + [const] crate::marker::Destruct {
        Self::from_ascii_bytes_radix_impl(src.as_ref(), 10)
    }
    /// Parses a non-zero integer from an ASCII-byte slice with digits in a given base.
    ///
    /// The characters are expected to be an optional
    #[doc = " `+` "]
    /// sign followed by only digits. Leading and trailing non-digit characters (including
    /// whitespace) represent an error. Underscores (which are accepted in Rust literals)
    /// also represent an error.
    ///
    /// Digits are a subset of these characters, depending on `radix`:
    ///
    /// - `0-9`
    /// - `a-z`
    /// - `A-Z`
    ///
    /// # Panics
    ///
    /// This method panics if `radix` is not in the range from 2 to 36.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc =
    "assert_eq!(NonZero::<usize>::from_ascii_bytes_radix(b\"A\", 16), Ok(NonZero::new(10)?));"]
    /// # Some(())
    /// # }
    /// ```
    ///
    /// Trailing space returns error:
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    #[doc =
    "assert!(NonZero::<usize>::from_ascii_bytes_radix(b\"1 \", 10).is_err());"]
    /// ```
    #[stable(feature = "int_from_ascii", since = "CURRENT_RUSTC_VERSION")]
    #[rustc_const_unstable(feature = "const_convert", issue = "143773")]
    #[inline]
    pub const fn from_ascii_bytes_radix<T>(src: T, radix: u32)
        -> Result<Self, ParseIntError> where T: [const] AsRef<[u8]> + [const]
        crate::marker::Destruct {
        Self::from_ascii_bytes_radix_impl(src.as_ref(), radix)
    }
    #[inline]
    const fn from_ascii_bytes_radix_impl(src: &[u8], radix: u32)
        -> Result<Self, ParseIntError> {
        let n =
            match <usize>::from_ascii_bytes_radix_impl(src, radix) {
                Ok(n) => n,
                Err(err) => return Err(err),
            };
        if let Some(n) = Self::new(n) {
            Ok(n)
        } else { Err(ParseIntError { kind: IntErrorKind::Zero }) }
    }
    /// Parses a non-zero integer from a string slice with digits in a given base.
    ///
    /// The string is expected to be an optional
    #[doc = " `+` "]
    /// sign followed by only digits. Leading and trailing non-digit characters (including
    /// whitespace) represent an error. Underscores (which are accepted in Rust literals)
    /// also represent an error.
    ///
    /// Digits are a subset of these characters, depending on `radix`:
    ///
    /// - `0-9`
    /// - `a-z`
    /// - `A-Z`
    ///
    /// # Panics
    ///
    /// This method panics if `radix` is not in the range from 2 to 36.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc =
    "assert_eq!(NonZero::<usize>::from_str_radix(\"A\", 16), Ok(NonZero::new(10)?));"]
    /// # Some(())
    /// # }
    /// ```
    ///
    /// Trailing space returns error:
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    #[doc = "assert!(NonZero::<usize>::from_str_radix(\"1 \", 10).is_err());"]
    /// ```
    #[stable(feature = "nonzero_from_str_radix", since = "1.98.0")]
    #[rustc_const_stable(feature = "nonzero_from_str_radix", since =
    "1.98.0")]
    #[inline]
    pub const fn from_str_radix(src: &str, radix: u32)
        -> Result<Self, ParseIntError> {
        Self::from_ascii_bytes_radix_impl(src.as_bytes(), radix)
    }
}
#[stable(feature = "nonzero_parse", since = "1.35.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl FromStr for NonZero<usize> {
    type Err = ParseIntError;
    /// Parses a non-zero integer from a string slice with decimal digits.
    ///
    /// The characters are expected to be an optional
    #[doc = " `+` "]
    /// sign followed by only digits. Leading and trailing non-digit characters (including
    /// whitespace) represent an error. Underscores (which are accepted in Rust literals)
    /// also represent an error.
    ///
    /// # Examples
    ///
    /// ```
    /// use std::num::NonZero;
    /// use std::str::FromStr;
    ///
    #[doc =
    "assert_eq!(NonZero::<usize>::from_str(\"+10\"), Ok(NonZero::new(10).unwrap()));"]
    /// ```
    ///
    /// Trailing space returns error:
    ///
    /// ```
    /// use std::num::NonZero;
    /// use std::str::FromStr;
    ///
    #[doc = "assert!(NonZero::<usize>::from_str(\"1 \").is_err());"]
    /// ```
    #[inline]
    fn from_str(src: &str) -> Result<Self, Self::Err> {
        Self::from_str_radix(src, 10)
    }
}
#[stable(feature = "nonzero_div", since = "1.51.0")]
#[rustc_const_unstable(feature = "const_ops", issue = "143802")]
const impl Div<NonZero<usize>> for usize {
    type Output = usize;
    /// Same as `self / other.get()`, but because `other` is a `NonZero<_>`,
    /// there's never a runtime check for division-by-zero.
    ///
    /// This operation rounds towards zero, truncating any fractional
    /// part of the exact result, and cannot panic.
    #[doc(alias = "unchecked_div")]
    #[inline]
    fn div(self, other: NonZero<usize>) -> usize {
        unsafe { intrinsics::unchecked_div(self, other.get()) }
    }
}
#[stable(feature = "nonzero_div_assign", since = "1.79.0")]
#[rustc_const_unstable(feature = "const_ops", issue = "143802")]
const impl DivAssign<NonZero<usize>> for usize {
    /// Same as `self /= other.get()`, but because `other` is a `NonZero<_>`,
    /// there's never a runtime check for division-by-zero.
    ///
    /// This operation rounds towards zero, truncating any fractional
    /// part of the exact result, and cannot panic.
    #[inline]
    fn div_assign(&mut self, other: NonZero<usize>) { *self = *self / other; }
}
#[stable(feature = "nonzero_div", since = "1.51.0")]
#[rustc_const_unstable(feature = "const_ops", issue = "143802")]
const impl Rem<NonZero<usize>> for usize {
    type Output = usize;
    /// This operation satisfies `n % d == n - (n / d) * d`, and cannot panic.
    #[inline]
    fn rem(self, other: NonZero<usize>) -> usize {
        unsafe { intrinsics::unchecked_rem(self, other.get()) }
    }
}
#[stable(feature = "nonzero_div_assign", since = "1.79.0")]
#[rustc_const_unstable(feature = "const_ops", issue = "143802")]
const impl RemAssign<NonZero<usize>> for usize {
    /// This operation satisfies `n % d == n - (n / d) * d`, and cannot panic.
    #[inline]
    fn rem_assign(&mut self, other: NonZero<usize>) { *self = *self % other; }
}nonzero_integer! {
2981    Self = NonZeroUsize,
2982    Primitive = unsigned usize,
2983    SignedPrimitive = isize,
2984    rot = 12,
2985    rot_op = "0xaa00000000006e1",
2986    rot_result = "0x6e10aa",
2987    swap_op = "0x1234567890123456",
2988    swapped = "0x5634129078563412",
2989    reversed = "0x6a2c48091e6a2c48",
2990}
2991
2992#[doc = "An [`i8`] that is known not to equal zero."]
///
/// This enables some memory layout optimization.
#[doc = "For example, `Option<NonZeroI8>` is the same size as `i8`:"]
///
/// ```rust
#[doc =
"assert_eq!(size_of::<Option<core::num::NonZeroI8>>(), size_of::<i8>());"]
/// ```
///
/// # Layout
///
#[doc =
"`NonZeroI8` is guaranteed to have the same layout and bit validity as `i8`"]
/// with the exception that `0` is not a valid instance.
#[doc = "`Option<NonZeroI8>` is guaranteed to be ABI-compatible with `i8`,"]
/// including in FFI.
///
/// Thanks to the [null pointer optimization],
#[doc = "`NonZeroI8` and `Option<NonZeroI8>`"]
/// are guaranteed to have the same size and alignment:
///
/// ```
#[doc = "use std::num::NonZeroI8;"]
///
#[doc = "assert_eq!(size_of::<NonZeroI8>(), size_of::<Option<NonZeroI8>>());"]
#[doc =
"assert_eq!(align_of::<NonZeroI8>(), align_of::<Option<NonZeroI8>>());"]
/// ```
///
/// # Compile-time creation
///
/// Since both [`Option::unwrap()`] and [`Option::expect()`] are `const`, it is possible to
/// define a new
#[doc = "`NonZeroI8`"]
/// at compile time via:
/// ```
#[doc = "use std::num::NonZeroI8;"]
///
#[doc =
"const TEN: NonZeroI8 = NonZeroI8::new(10).expect(\"ten is non-zero\");"]
/// ```
///
/// [null pointer optimization]: crate::option#representation
#[stable(feature = "signed_nonzero", since = "1.34.0")]
pub type NonZeroI8 = NonZero<i8>;
impl NonZero<i8> {
    /// The size of this non-zero integer type in bits.
    ///
    #[doc = "This value is equal to [`i8::BITS`]."]
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    #[doc = "assert_eq!(NonZero::<i8>::BITS, i8::BITS);"]
    /// ```
    #[stable(feature = "nonzero_bits", since = "1.67.0")]
    pub const BITS: u32 = <i8>::BITS;
    /// Returns the number of leading zeros in the binary representation of `self`.
    ///
    /// On many architectures, this function can perform better than `leading_zeros()` on the underlying integer type, as special handling of zero can be avoided.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::<i8>::new(-1i8)?;"]
    ///
    /// assert_eq!(n.leading_zeros(), 0);
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_leading_trailing_zeros", since = "1.53.0")]
    #[rustc_const_stable(feature = "nonzero_leading_trailing_zeros", since =
    "1.53.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const fn leading_zeros(self) -> u32 {
        unsafe { intrinsics::ctlz_nonzero(self.get() as u8) }
    }
    /// Returns the number of trailing zeros in the binary representation
    /// of `self`.
    ///
    /// On many architectures, this function can perform better than `trailing_zeros()` on the underlying integer type, as special handling of zero can be avoided.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::<i8>::new(0b0101000)?;"]
    ///
    /// assert_eq!(n.trailing_zeros(), 3);
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_leading_trailing_zeros", since = "1.53.0")]
    #[rustc_const_stable(feature = "nonzero_leading_trailing_zeros", since =
    "1.53.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const fn trailing_zeros(self) -> u32 {
        unsafe { intrinsics::cttz_nonzero(self.get() as u8) }
    }
    /// Returns `self` with only the most significant bit set.
    ///
    /// # Example
    ///
    /// ```
    /// # use core::num::NonZero;
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let a = NonZero::<i8>::new(0b_01100100)?;"]
    #[doc = "let b = NonZero::<i8>::new(0b_01000000)?;"]
    ///
    /// assert_eq!(a.isolate_highest_one(), b);
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "isolate_most_least_significant_one", since =
    "1.97.0")]
    #[rustc_const_stable(feature = "isolate_most_least_significant_one", since
    = "1.97.0")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn isolate_highest_one(self) -> Self {
        unsafe {
            let bit =
                (((1 as u8) <<
                                (<u8>::BITS - 1)).unchecked_shr(self.leading_zeros()));
            NonZero::new_unchecked(bit as i8)
        }
    }
    /// Returns `self` with only the least significant bit set.
    ///
    /// # Example
    ///
    /// ```
    /// # use core::num::NonZero;
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let a = NonZero::<i8>::new(0b_01100100)?;"]
    #[doc = "let b = NonZero::<i8>::new(0b_00000100)?;"]
    ///
    /// assert_eq!(a.isolate_lowest_one(), b);
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "isolate_most_least_significant_one", since =
    "1.97.0")]
    #[rustc_const_stable(feature = "isolate_most_least_significant_one", since
    = "1.97.0")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn isolate_lowest_one(self) -> Self {
        let n = self.get();
        let n = n & n.wrapping_neg();
        unsafe { NonZero::new_unchecked(n) }
    }
    /// Returns the index of the highest bit set to one in `self`.
    ///
    #[doc = ""]
    ///
    /// # Examples
    ///
    /// ```
    /// # use core::num::NonZero;
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "assert_eq!(NonZero::<i8>::new(0b1)?.highest_one(), 0);"]
    #[doc = "assert_eq!(NonZero::<i8>::new(0b1_0000)?.highest_one(), 4);"]
    #[doc = "assert_eq!(NonZero::<i8>::new(0b1_1111)?.highest_one(), 4);"]
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "int_lowest_highest_one", since = "1.97.0")]
    #[rustc_const_stable(feature = "int_lowest_highest_one", since =
    "1.97.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline(always)]
    pub const fn highest_one(self) -> u32 {
        Self::BITS - 1 - self.leading_zeros()
    }
    /// Returns the index of the lowest bit set to one in `self`.
    ///
    /// # Examples
    ///
    /// ```
    /// # use core::num::NonZero;
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "assert_eq!(NonZero::<i8>::new(0b1)?.lowest_one(), 0);"]
    #[doc = "assert_eq!(NonZero::<i8>::new(0b1_0000)?.lowest_one(), 4);"]
    #[doc = "assert_eq!(NonZero::<i8>::new(0b1_1111)?.lowest_one(), 0);"]
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "int_lowest_highest_one", since = "1.97.0")]
    #[rustc_const_stable(feature = "int_lowest_highest_one", since =
    "1.97.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline(always)]
    pub const fn lowest_one(self) -> u32 { self.trailing_zeros() }
    /// Returns the number of ones in the binary representation of `self`.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let a = NonZero::<i8>::new(0b100_0000)?;"]
    #[doc = "let b = NonZero::<i8>::new(0b100_0011)?;"]
    ///
    /// assert_eq!(a.count_ones(), NonZero::new(1)?);
    /// assert_eq!(b.count_ones(), NonZero::new(3)?);
    /// # Some(())
    /// # }
    /// ```
    ///
    #[stable(feature = "non_zero_count_ones", since = "1.86.0")]
    #[rustc_const_stable(feature = "non_zero_count_ones", since = "1.86.0")]
    #[doc(alias = "popcount")]
    #[doc(alias = "popcnt")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn count_ones(self) -> NonZero<u32> {
        unsafe { NonZero::new_unchecked(self.get().count_ones()) }
    }
    /// Shifts the bits to the left by a specified amount, `n`,
    /// wrapping the truncated bits to the end of the resulting integer.
    ///
    /// Please note this isn't the same operation as the `<<` shifting operator!
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(-0x7ei8)?;"]
    #[doc = "let m = NonZero::new(0xa)?;"]
    ///
    #[doc = "assert_eq!(n.rotate_left(2), m);"]
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn rotate_left(self, n: u32) -> Self {
        let result = self.get().rotate_left(n);
        unsafe { Self::new_unchecked(result) }
    }
    /// Shifts the bits to the right by a specified amount, `n`,
    /// wrapping the truncated bits to the beginning of the resulting
    /// integer.
    ///
    /// Please note this isn't the same operation as the `>>` shifting operator!
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0xai8)?;"]
    #[doc = "let m = NonZero::new(-0x7e)?;"]
    ///
    #[doc = "assert_eq!(n.rotate_right(2), m);"]
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn rotate_right(self, n: u32) -> Self {
        let result = self.get().rotate_right(n);
        unsafe { Self::new_unchecked(result) }
    }
    /// Reverses the byte order of the integer.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x12i8)?;"]
    /// let m = n.swap_bytes();
    ///
    #[doc = "assert_eq!(m, NonZero::new(0x12)?);"]
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn swap_bytes(self) -> Self {
        let result = self.get().swap_bytes();
        unsafe { Self::new_unchecked(result) }
    }
    /// Reverses the order of bits in the integer. The least significant bit becomes the most significant bit,
    /// second least-significant bit becomes second most-significant bit, etc.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x12i8)?;"]
    /// let m = n.reverse_bits();
    ///
    #[doc = "assert_eq!(m, NonZero::new(0x48)?);"]
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn reverse_bits(self) -> Self {
        let result = self.get().reverse_bits();
        unsafe { Self::new_unchecked(result) }
    }
    /// Converts an integer from big endian to the target's endianness.
    ///
    /// On big endian this is a no-op. On little endian the bytes are
    /// swapped.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    #[doc = "use std::num::NonZeroI8;"]
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x1Ai8)?;"]
    ///
    /// if cfg!(target_endian = "big") {
    #[doc = "    assert_eq!(NonZeroI8::from_be(n), n)"]
    /// } else {
    #[doc = "    assert_eq!(NonZeroI8::from_be(n), n.swap_bytes())"]
    /// }
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use]
    #[inline(always)]
    pub const fn from_be(x: Self) -> Self {
        let result = i8::from_be(x.get());
        unsafe { Self::new_unchecked(result) }
    }
    /// Converts an integer from little endian to the target's endianness.
    ///
    /// On little endian this is a no-op. On big endian the bytes are
    /// swapped.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    #[doc = "use std::num::NonZeroI8;"]
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x1Ai8)?;"]
    ///
    /// if cfg!(target_endian = "little") {
    #[doc = "    assert_eq!(NonZeroI8::from_le(n), n)"]
    /// } else {
    #[doc = "    assert_eq!(NonZeroI8::from_le(n), n.swap_bytes())"]
    /// }
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use]
    #[inline(always)]
    pub const fn from_le(x: Self) -> Self {
        let result = i8::from_le(x.get());
        unsafe { Self::new_unchecked(result) }
    }
    /// Converts `self` to big endian from the target's endianness.
    ///
    /// On big endian this is a no-op. On little endian the bytes are
    /// swapped.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x1Ai8)?;"]
    ///
    /// if cfg!(target_endian = "big") {
    ///     assert_eq!(n.to_be(), n)
    /// } else {
    ///     assert_eq!(n.to_be(), n.swap_bytes())
    /// }
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn to_be(self) -> Self {
        let result = self.get().to_be();
        unsafe { Self::new_unchecked(result) }
    }
    /// Converts `self` to little endian from the target's endianness.
    ///
    /// On little endian this is a no-op. On big endian the bytes are
    /// swapped.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x1Ai8)?;"]
    ///
    /// if cfg!(target_endian = "little") {
    ///     assert_eq!(n.to_le(), n)
    /// } else {
    ///     assert_eq!(n.to_le(), n.swap_bytes())
    /// }
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn to_le(self) -> Self {
        let result = self.get().to_le();
        unsafe { Self::new_unchecked(result) }
    }
    /// The smallest value that can be represented by this non-zero
    /// integer type,
    #[doc = "equal to [`i8::MIN`]."]
    ///
    /// Note: While most integer types are defined for every whole
    /// number between `MIN` and `MAX`, signed non-zero integers are
    /// a special case. They have a "gap" at 0.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    #[doc = "assert_eq!(NonZero::<i8>::MIN.get(), i8::MIN);"]
    /// ```
    #[stable(feature = "nonzero_min_max", since = "1.70.0")]
    pub const MIN: Self = Self::new(<i8>::MIN).unwrap();
    /// The largest value that can be represented by this non-zero
    /// integer type,
    #[doc = "equal to [`i8::MAX`]."]
    ///
    /// Note: While most integer types are defined for every whole
    /// number between `MIN` and `MAX`, signed non-zero integers are
    /// a special case. They have a "gap" at 0.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    #[doc = "assert_eq!(NonZero::<i8>::MAX.get(), i8::MAX);"]
    /// ```
    #[stable(feature = "nonzero_min_max", since = "1.70.0")]
    pub const MAX: Self = Self::new(<i8>::MAX).unwrap();
    /// Computes the absolute value of self.
    #[doc = "See [`i8::abs`]"]
    /// for documentation on overflow behavior.
    ///
    /// # Example
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let pos = NonZero::new(1i8)?;"]
    #[doc = "let neg = NonZero::new(-1i8)?;"]
    ///
    /// assert_eq!(pos, pos.abs());
    /// assert_eq!(pos, neg.abs());
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const fn abs(self) -> Self {
        unsafe { Self::new_unchecked(self.get().abs()) }
    }
    /// Checked absolute value.
    /// Checks for overflow and returns [`None`] if
    #[doc = "`self == NonZero::<i8>::MIN`."]
    /// The result cannot be zero.
    ///
    /// # Example
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let pos = NonZero::new(1i8)?;"]
    #[doc = "let neg = NonZero::new(-1i8)?;"]
    #[doc = "let min = NonZero::new(i8::MIN)?;"]
    ///
    /// assert_eq!(Some(pos), neg.checked_abs());
    /// assert_eq!(None, min.checked_abs());
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const fn checked_abs(self) -> Option<Self> {
        if let Some(nz) = self.get().checked_abs() {
            Some(unsafe { Self::new_unchecked(nz) })
        } else { None }
    }
    /// Computes the absolute value of self,
    /// with overflow information, see
    #[doc = "[`i8::overflowing_abs`]."]
    ///
    /// # Example
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let pos = NonZero::new(1i8)?;"]
    #[doc = "let neg = NonZero::new(-1i8)?;"]
    #[doc = "let min = NonZero::new(i8::MIN)?;"]
    ///
    /// assert_eq!((pos, false), pos.overflowing_abs());
    /// assert_eq!((pos, false), neg.overflowing_abs());
    /// assert_eq!((min, true), min.overflowing_abs());
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const fn overflowing_abs(self) -> (Self, bool) {
        let (nz, flag) = self.get().overflowing_abs();
        (unsafe { Self::new_unchecked(nz) }, flag)
    }
    /// Saturating absolute value, see
    #[doc = "[`i8::saturating_abs`]."]
    ///
    /// # Example
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let pos = NonZero::new(1i8)?;"]
    #[doc = "let neg = NonZero::new(-1i8)?;"]
    #[doc = "let min = NonZero::new(i8::MIN)?;"]
    #[doc = "let min_plus = NonZero::new(i8::MIN + 1)?;"]
    #[doc = "let max = NonZero::new(i8::MAX)?;"]
    ///
    /// assert_eq!(pos, pos.saturating_abs());
    /// assert_eq!(pos, neg.saturating_abs());
    /// assert_eq!(max, min.saturating_abs());
    /// assert_eq!(max, min_plus.saturating_abs());
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const fn saturating_abs(self) -> Self {
        unsafe { Self::new_unchecked(self.get().saturating_abs()) }
    }
    /// Wrapping absolute value, see
    #[doc = "[`i8::wrapping_abs`]."]
    ///
    /// # Example
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let pos = NonZero::new(1i8)?;"]
    #[doc = "let neg = NonZero::new(-1i8)?;"]
    #[doc = "let min = NonZero::new(i8::MIN)?;"]
    #[doc = "# let max = NonZero::new(i8::MAX)?;"]
    ///
    /// assert_eq!(pos, pos.wrapping_abs());
    /// assert_eq!(pos, neg.wrapping_abs());
    /// assert_eq!(min, min.wrapping_abs());
    /// assert_eq!(max, (-max).wrapping_abs());
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const fn wrapping_abs(self) -> Self {
        unsafe { Self::new_unchecked(self.get().wrapping_abs()) }
    }
    /// Computes the absolute value of self
    /// without any wrapping or panicking.
    ///
    /// # Example
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let u_pos = NonZero::new(1u8)?;"]
    #[doc = "let i_pos = NonZero::new(1i8)?;"]
    #[doc = "let i_neg = NonZero::new(-1i8)?;"]
    #[doc = "let i_min = NonZero::new(i8::MIN)?;"]
    #[doc = "let u_max = NonZero::new(u8::MAX / 2 + 1)?;"]
    ///
    /// assert_eq!(u_pos, i_pos.unsigned_abs());
    /// assert_eq!(u_pos, i_neg.unsigned_abs());
    /// assert_eq!(u_max, i_min.unsigned_abs());
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const fn unsigned_abs(self) -> NonZero<u8> {
        unsafe { NonZero::new_unchecked(self.get().unsigned_abs()) }
    }
    /// Returns `true` if `self` is positive and `false` if the
    /// number is negative.
    ///
    /// # Example
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let pos_five = NonZero::new(5i8)?;"]
    #[doc = "let neg_five = NonZero::new(-5i8)?;"]
    ///
    /// assert!(pos_five.is_positive());
    /// assert!(!neg_five.is_positive());
    /// # Some(())
    /// # }
    /// ```
    #[must_use]
    #[inline]
    #[stable(feature = "nonzero_negation_ops", since = "1.71.0")]
    #[rustc_const_stable(feature = "nonzero_negation_ops", since = "1.71.0")]
    pub const fn is_positive(self) -> bool { self.get().is_positive() }
    /// Returns `true` if `self` is negative and `false` if the
    /// number is positive.
    ///
    /// # Example
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let pos_five = NonZero::new(5i8)?;"]
    #[doc = "let neg_five = NonZero::new(-5i8)?;"]
    ///
    /// assert!(neg_five.is_negative());
    /// assert!(!pos_five.is_negative());
    /// # Some(())
    /// # }
    /// ```
    #[must_use]
    #[inline]
    #[stable(feature = "nonzero_negation_ops", since = "1.71.0")]
    #[rustc_const_stable(feature = "nonzero_negation_ops", since = "1.71.0")]
    pub const fn is_negative(self) -> bool { self.get().is_negative() }
    /// Checked negation. Computes `-self`,
    #[doc = "returning `None` if `self == NonZero::<i8>::MIN`."]
    ///
    /// # Example
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let pos_five = NonZero::new(5i8)?;"]
    #[doc = "let neg_five = NonZero::new(-5i8)?;"]
    #[doc = "let min = NonZero::new(i8::MIN)?;"]
    ///
    /// assert_eq!(pos_five.checked_neg(), Some(neg_five));
    /// assert_eq!(min.checked_neg(), None);
    /// # Some(())
    /// # }
    /// ```
    #[inline]
    #[stable(feature = "nonzero_negation_ops", since = "1.71.0")]
    #[rustc_const_stable(feature = "nonzero_negation_ops", since = "1.71.0")]
    pub const fn checked_neg(self) -> Option<Self> {
        if let Some(result) = self.get().checked_neg() {
            return Some(unsafe { Self::new_unchecked(result) });
        }
        None
    }
    /// Checked negation. Computes `-self`, panicking if `self == MIN`.
    ///
    /// # Panics
    ///
    /// ## Overflow behavior
    ///
    /// This function always panics on overflow, regardless of whether
    /// overflow checks are enabled.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_strict_ops)]
    ///
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let pos_six = NonZero::new(6i8)?;"]
    #[doc = "let neg_six = NonZero::new(-6i8)?;"]
    ///
    /// assert_eq!(pos_six.strict_neg(), neg_six);
    /// # Some(())
    /// # }
    /// ```
    ///
    /// The following panics because of overflow:
    ///
    /// ```should_panic
    /// #![feature(nonzero_strict_ops)]
    ///
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let min = NonZero::new(i8::MIN)?;"]
    ///
    /// let _ = min.strict_neg();
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_strict_ops", issue = "164850")]
    #[rustc_const_unstable(feature = "const_nonzero_strict_ops", issue =
    "164850")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    #[track_caller]
    pub const fn strict_neg(self) -> Self {
        unsafe { Self::new_unchecked(self.get().strict_neg()) }
    }
    /// Negates self, overflowing if this is equal to the minimum value.
    ///
    #[doc = "See [`i8::overflowing_neg`]"]
    /// for documentation on overflow behavior.
    ///
    /// # Example
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let pos_five = NonZero::new(5i8)?;"]
    #[doc = "let neg_five = NonZero::new(-5i8)?;"]
    #[doc = "let min = NonZero::new(i8::MIN)?;"]
    ///
    /// assert_eq!(pos_five.overflowing_neg(), (neg_five, false));
    /// assert_eq!(min.overflowing_neg(), (min, true));
    /// # Some(())
    /// # }
    /// ```
    #[inline]
    #[stable(feature = "nonzero_negation_ops", since = "1.71.0")]
    #[rustc_const_stable(feature = "nonzero_negation_ops", since = "1.71.0")]
    pub const fn overflowing_neg(self) -> (Self, bool) {
        let (result, overflow) = self.get().overflowing_neg();
        ((unsafe { Self::new_unchecked(result) }), overflow)
    }
    /// Saturating negation. Computes `-self`,
    #[doc = "returning [`NonZero::<i8>::MAX`]"]
    #[doc = "if `self == NonZero::<i8>::MIN`"]
    /// instead of overflowing.
    ///
    /// # Example
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let pos_five = NonZero::new(5i8)?;"]
    #[doc = "let neg_five = NonZero::new(-5i8)?;"]
    #[doc = "let min = NonZero::new(i8::MIN)?;"]
    #[doc = "let min_plus_one = NonZero::new(i8::MIN + 1)?;"]
    #[doc = "let max = NonZero::new(i8::MAX)?;"]
    ///
    /// assert_eq!(pos_five.saturating_neg(), neg_five);
    /// assert_eq!(min.saturating_neg(), max);
    /// assert_eq!(max.saturating_neg(), min_plus_one);
    /// # Some(())
    /// # }
    /// ```
    #[inline]
    #[stable(feature = "nonzero_negation_ops", since = "1.71.0")]
    #[rustc_const_stable(feature = "nonzero_negation_ops", since = "1.71.0")]
    pub const fn saturating_neg(self) -> Self {
        if let Some(result) = self.checked_neg() { return result; }
        Self::MAX
    }
    /// Wrapping (modular) negation. Computes `-self`, wrapping around at the boundary
    /// of the type.
    ///
    #[doc = "See [`i8::wrapping_neg`]"]
    /// for documentation on overflow behavior.
    ///
    /// # Example
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let pos_five = NonZero::new(5i8)?;"]
    #[doc = "let neg_five = NonZero::new(-5i8)?;"]
    #[doc = "let min = NonZero::new(i8::MIN)?;"]
    ///
    /// assert_eq!(pos_five.wrapping_neg(), neg_five);
    /// assert_eq!(min.wrapping_neg(), min);
    /// # Some(())
    /// # }
    /// ```
    #[inline]
    #[stable(feature = "nonzero_negation_ops", since = "1.71.0")]
    #[rustc_const_stable(feature = "nonzero_negation_ops", since = "1.71.0")]
    pub const fn wrapping_neg(self) -> Self {
        let result = self.get().wrapping_neg();
        unsafe { Self::new_unchecked(result) }
    }
    /// Returns the bit pattern of `self` reinterpreted as an unsigned integer of the same size.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    ///
    #[doc = "let n = NonZero::new(-1i8).unwrap();"]
    ///
    #[doc = "assert_eq!(n.cast_unsigned(), NonZero::<u8>::MAX);"]
    /// ```
    #[stable(feature = "integer_sign_cast", since = "1.87.0")]
    #[rustc_const_stable(feature = "integer_sign_cast", since = "1.87.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline(always)]
    pub const fn cast_unsigned(self) -> NonZero<u8> {
        unsafe { NonZero::new_unchecked(self.get().cast_unsigned()) }
    }
    /// Clamps this number to a symmetric range centred around zero.
    ///
    /// The method clamps the number's magnitude (absolute value) to be at most `limit`.
    ///
    /// This is functionally equivalent to `self.clamp(-limit, limit)`, but is more
    /// explicit about the intent.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(clamp_magnitude)]
    /// # use std::num::NonZero;
    /// #
    #[doc = "let limit = NonZero::<u8>::new(100).unwrap();"]
    ///
    /// assert_eq!(
    #[doc = "    NonZero::<i8>::new(120).unwrap().clamp_magnitude(limit),"]
    #[doc = "    NonZero::<i8>::new(100).unwrap(),"]
    /// );
    ///
    /// assert_eq!(
    #[doc = "    NonZero::<i8>::new(-120).unwrap().clamp_magnitude(limit),"]
    #[doc = "    NonZero::<i8>::new(-100).unwrap(),"]
    /// );
    ///
    /// assert_eq!(
    #[doc = "    NonZero::<i8>::new(80).unwrap().clamp_magnitude(limit),"]
    #[doc = "    NonZero::<i8>::new(80).unwrap(),"]
    /// );
    ///
    /// assert_eq!(
    #[doc = "    NonZero::<i8>::new(-80).unwrap().clamp_magnitude(limit),"]
    #[doc = "    NonZero::<i8>::new(-80).unwrap(),"]
    /// );
    /// ```
    #[inline]
    #[must_use =
    "method returns a new number and does not mutate the original value"]
    #[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
    #[unstable(feature = "clamp_magnitude", issue = "148519")]
    pub const fn clamp_magnitude(self, limit: NonZero<u8>) -> Self {
        unsafe {
            Self::new_unchecked(self.get().clamp_magnitude(limit.get()))
        }
    }
    /// Multiplies two non-zero integers together.
    /// Checks for overflow and returns [`None`] on overflow.
    /// As a consequence, the result cannot wrap to zero.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let two = NonZero::new(2i8)?;"]
    #[doc = "let four = NonZero::new(4i8)?;"]
    #[doc = "let max = NonZero::new(i8::MAX)?;"]
    ///
    /// assert_eq!(Some(four), two.checked_mul(two));
    /// assert_eq!(None, max.checked_mul(two));
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const fn checked_mul(self, other: Self) -> Option<Self> {
        if let Some(result) = self.get().checked_mul(other.get()) {
            Some(unsafe { Self::new_unchecked(result) })
        } else { None }
    }
    /// Multiplies two non-zero integers together, panicking if
    /// overflow occurs.
    ///
    /// # Panics
    ///
    /// ## Overflow behavior
    ///
    /// This function always panics on overflow, regardless of whether
    /// overflow checks are enabled.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_strict_ops)]
    ///
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let three = NonZero::new(3i8)?;"]
    #[doc = "let nine = NonZero::new(9i8)?;"]
    ///
    /// assert_eq!(nine, three.strict_mul(three));
    /// # Some(())
    /// # }
    /// ```
    ///
    /// The following panics because of overflow:
    ///
    /// ```should_panic
    /// #![feature(nonzero_strict_ops)]
    ///
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let two = NonZero::new(2i8)?;"]
    #[doc = "let max = NonZero::new(i8::MAX)?;"]
    ///
    /// let _ = max.strict_mul(two);
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_strict_ops", issue = "164850")]
    #[rustc_const_unstable(feature = "const_nonzero_strict_ops", issue =
    "164850")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    #[track_caller]
    pub const fn strict_mul(self, other: Self) -> Self {
        unsafe { Self::new_unchecked(self.get().strict_mul(other.get())) }
    }
    /// Multiplies two non-zero integers together.
    #[doc = "Return [`NonZero::<i8>::MAX`] on overflow."]
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let two = NonZero::new(2i8)?;"]
    #[doc = "let four = NonZero::new(4i8)?;"]
    #[doc = "let max = NonZero::new(i8::MAX)?;"]
    ///
    /// assert_eq!(four, two.saturating_mul(two));
    /// assert_eq!(max, four.saturating_mul(max));
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const fn saturating_mul(self, other: Self) -> Self {
        unsafe { Self::new_unchecked(self.get().saturating_mul(other.get())) }
    }
    /// Multiplies two non-zero integers together,
    /// assuming overflow cannot occur.
    /// Overflow is unchecked, and it is undefined behavior to overflow
    /// *even if the result would wrap to a non-zero value*.
    ///
    /// # Safety
    ///
    /// This results in undefined behavior when overflow occurs, i.e.
    /// when [`checked_mul`] would return `None`.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let two = NonZero::new(2i8)?;"]
    #[doc = "let four = NonZero::new(4i8)?;"]
    ///
    /// assert_eq!(four, unsafe { two.unchecked_mul(two) });
    /// # Some(())
    /// # }
    /// ```
    ///
    /// [`checked_mul`]: Self::checked_mul
    #[stable(feature = "nonzero_ops", since = "CURRENT_RUSTC_VERSION")]
    #[rustc_const_stable(feature = "nonzero_ops", since =
    "CURRENT_RUSTC_VERSION")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const unsafe fn unchecked_mul(self, other: Self) -> Self {
        unsafe { Self::new_unchecked(self.get().unchecked_mul(other.get())) }
    }
    /// Raises non-zero value to an integer power.
    /// Checks for overflow and returns [`None`] on overflow.
    /// As a consequence, the result cannot wrap to zero.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let three = NonZero::new(3i8)?;"]
    #[doc = "let twenty_seven = NonZero::new(27i8)?;"]
    #[doc = "let half_max = NonZero::new(i8::MAX / 2)?;"]
    ///
    /// assert_eq!(Some(twenty_seven), three.checked_pow(3));
    /// assert_eq!(None, half_max.checked_pow(3));
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const fn checked_pow(self, other: u32) -> Option<Self> {
        if let Some(result) = self.get().checked_pow(other) {
            Some(unsafe { Self::new_unchecked(result) })
        } else { None }
    }
    /// Raises a non-zero value to an integer power, panicking if
    /// overflow occurs.
    ///
    /// # Panics
    ///
    /// ## Overflow behavior
    ///
    /// This function always panics on overflow, regardless of whether
    /// overflow checks are enabled.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_strict_ops)]
    ///
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let two = NonZero::new(2i8)?;"]
    #[doc = "let sixteen = NonZero::new(16i8)?;"]
    ///
    /// assert_eq!(sixteen, two.strict_pow(4));
    /// # Some(())
    /// # }
    /// ```
    ///
    /// The following panics because of overflow:
    ///
    /// ```should_panic
    /// #![feature(nonzero_strict_ops)]
    ///
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let half_max = NonZero::new(i8::MAX / 2)?;"]
    ///
    /// let _ = half_max.strict_pow(2);
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_strict_ops", issue = "164850")]
    #[rustc_const_unstable(feature = "const_nonzero_strict_ops", issue =
    "164850")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    #[track_caller]
    pub const fn strict_pow(self, exp: u32) -> Self {
        unsafe { Self::new_unchecked(self.get().strict_pow(exp)) }
    }
    /// Raise non-zero value to an integer power.
    #[doc =
    "Return [`NonZero::<i8>::MIN`] or [`NonZero::<i8>::MAX`] on overflow."]
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let three = NonZero::new(3i8)?;"]
    #[doc = "let twenty_seven = NonZero::new(27i8)?;"]
    #[doc = "let max = NonZero::new(i8::MAX)?;"]
    ///
    /// assert_eq!(twenty_seven, three.saturating_pow(3));
    /// assert_eq!(max, max.saturating_pow(3));
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const fn saturating_pow(self, other: u32) -> Self {
        unsafe { Self::new_unchecked(self.get().saturating_pow(other)) }
    }
    /// Parses a non-zero integer from an ASCII-byte slice with decimal digits.
    ///
    /// The characters are expected to be an optional
    #[doc = " `+` or `-` "]
    /// sign followed by only digits. Leading and trailing non-digit characters (including
    /// whitespace) represent an error. Underscores (which are accepted in Rust literals)
    /// also represent an error.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc =
    "assert_eq!(NonZero::<i8>::from_ascii_bytes(b\"+10\"), Ok(NonZero::new(10)?));"]
    /// # Some(())
    /// # }
    /// ```
    ///
    /// Trailing space returns error:
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    #[doc = "assert!(NonZero::<i8>::from_ascii_bytes(b\"1 \").is_err());"]
    /// ```
    #[stable(feature = "int_from_ascii", since = "CURRENT_RUSTC_VERSION")]
    #[rustc_const_unstable(feature = "const_convert", issue = "143773")]
    #[inline]
    pub const fn from_ascii_bytes<T>(src: T) -> Result<Self, ParseIntError>
        where T: [const] AsRef<[u8]> + [const] crate::marker::Destruct {
        Self::from_ascii_bytes_radix_impl(src.as_ref(), 10)
    }
    /// Parses a non-zero integer from an ASCII-byte slice with digits in a given base.
    ///
    /// The characters are expected to be an optional
    #[doc = " `+` or `-` "]
    /// sign followed by only digits. Leading and trailing non-digit characters (including
    /// whitespace) represent an error. Underscores (which are accepted in Rust literals)
    /// also represent an error.
    ///
    /// Digits are a subset of these characters, depending on `radix`:
    ///
    /// - `0-9`
    /// - `a-z`
    /// - `A-Z`
    ///
    /// # Panics
    ///
    /// This method panics if `radix` is not in the range from 2 to 36.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc =
    "assert_eq!(NonZero::<i8>::from_ascii_bytes_radix(b\"A\", 16), Ok(NonZero::new(10)?));"]
    /// # Some(())
    /// # }
    /// ```
    ///
    /// Trailing space returns error:
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    #[doc =
    "assert!(NonZero::<i8>::from_ascii_bytes_radix(b\"1 \", 10).is_err());"]
    /// ```
    #[stable(feature = "int_from_ascii", since = "CURRENT_RUSTC_VERSION")]
    #[rustc_const_unstable(feature = "const_convert", issue = "143773")]
    #[inline]
    pub const fn from_ascii_bytes_radix<T>(src: T, radix: u32)
        -> Result<Self, ParseIntError> where T: [const] AsRef<[u8]> + [const]
        crate::marker::Destruct {
        Self::from_ascii_bytes_radix_impl(src.as_ref(), radix)
    }
    #[inline]
    const fn from_ascii_bytes_radix_impl(src: &[u8], radix: u32)
        -> Result<Self, ParseIntError> {
        let n =
            match <i8>::from_ascii_bytes_radix_impl(src, radix) {
                Ok(n) => n,
                Err(err) => return Err(err),
            };
        if let Some(n) = Self::new(n) {
            Ok(n)
        } else { Err(ParseIntError { kind: IntErrorKind::Zero }) }
    }
    /// Parses a non-zero integer from a string slice with digits in a given base.
    ///
    /// The string is expected to be an optional
    #[doc = " `+` or `-` "]
    /// sign followed by only digits. Leading and trailing non-digit characters (including
    /// whitespace) represent an error. Underscores (which are accepted in Rust literals)
    /// also represent an error.
    ///
    /// Digits are a subset of these characters, depending on `radix`:
    ///
    /// - `0-9`
    /// - `a-z`
    /// - `A-Z`
    ///
    /// # Panics
    ///
    /// This method panics if `radix` is not in the range from 2 to 36.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc =
    "assert_eq!(NonZero::<i8>::from_str_radix(\"A\", 16), Ok(NonZero::new(10)?));"]
    /// # Some(())
    /// # }
    /// ```
    ///
    /// Trailing space returns error:
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    #[doc = "assert!(NonZero::<i8>::from_str_radix(\"1 \", 10).is_err());"]
    /// ```
    #[stable(feature = "nonzero_from_str_radix", since = "1.98.0")]
    #[rustc_const_stable(feature = "nonzero_from_str_radix", since =
    "1.98.0")]
    #[inline]
    pub const fn from_str_radix(src: &str, radix: u32)
        -> Result<Self, ParseIntError> {
        Self::from_ascii_bytes_radix_impl(src.as_bytes(), radix)
    }
}
#[stable(feature = "nonzero_parse", since = "1.35.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl FromStr for NonZero<i8> {
    type Err = ParseIntError;
    /// Parses a non-zero integer from a string slice with decimal digits.
    ///
    /// The characters are expected to be an optional
    #[doc = " `+` or `-` "]
    /// sign followed by only digits. Leading and trailing non-digit characters (including
    /// whitespace) represent an error. Underscores (which are accepted in Rust literals)
    /// also represent an error.
    ///
    /// # Examples
    ///
    /// ```
    /// use std::num::NonZero;
    /// use std::str::FromStr;
    ///
    #[doc =
    "assert_eq!(NonZero::<i8>::from_str(\"+10\"), Ok(NonZero::new(10).unwrap()));"]
    /// ```
    ///
    /// Trailing space returns error:
    ///
    /// ```
    /// use std::num::NonZero;
    /// use std::str::FromStr;
    ///
    #[doc = "assert!(NonZero::<i8>::from_str(\"1 \").is_err());"]
    /// ```
    #[inline]
    fn from_str(src: &str) -> Result<Self, Self::Err> {
        Self::from_str_radix(src, 10)
    }
}
#[stable(feature = "signed_nonzero_neg", since = "1.71.0")]
#[rustc_const_unstable(feature = "const_ops", issue = "143802")]
const impl Neg for NonZero<i8> {
    type Output = Self;
    #[inline]
    fn neg(self) -> Self { unsafe { Self::new_unchecked(self.get().neg()) } }
}
#[stable(feature = "signed_nonzero_neg", since = "1.71.0")]
#[rustc_const_unstable(feature = "const_ops", issue = "143802")]
const impl Neg for &NonZero<i8> {
    type Output = <NonZero<i8> as Neg>::Output;
    #[inline]
    fn neg(self) -> <NonZero<i8> as Neg>::Output { Neg::neg(*self) }
}nonzero_integer! {
2993    Self = NonZeroI8,
2994    Primitive = signed i8,
2995    UnsignedPrimitive = u8,
2996    rot = 2,
2997    rot_op = "-0x7e",
2998    rot_result = "0xa",
2999    swap_op = "0x12",
3000    swapped = "0x12",
3001    reversed = "0x48",
3002}
3003
3004#[doc = "An [`i16`] that is known not to equal zero."]
///
/// This enables some memory layout optimization.
#[doc = "For example, `Option<NonZeroI16>` is the same size as `i16`:"]
///
/// ```rust
#[doc =
"assert_eq!(size_of::<Option<core::num::NonZeroI16>>(), size_of::<i16>());"]
/// ```
///
/// # Layout
///
#[doc =
"`NonZeroI16` is guaranteed to have the same layout and bit validity as `i16`"]
/// with the exception that `0` is not a valid instance.
#[doc = "`Option<NonZeroI16>` is guaranteed to be ABI-compatible with `i16`,"]
/// including in FFI.
///
/// Thanks to the [null pointer optimization],
#[doc = "`NonZeroI16` and `Option<NonZeroI16>`"]
/// are guaranteed to have the same size and alignment:
///
/// ```
#[doc = "use std::num::NonZeroI16;"]
///
#[doc =
"assert_eq!(size_of::<NonZeroI16>(), size_of::<Option<NonZeroI16>>());"]
#[doc =
"assert_eq!(align_of::<NonZeroI16>(), align_of::<Option<NonZeroI16>>());"]
/// ```
///
/// # Compile-time creation
///
/// Since both [`Option::unwrap()`] and [`Option::expect()`] are `const`, it is possible to
/// define a new
#[doc = "`NonZeroI16`"]
/// at compile time via:
/// ```
#[doc = "use std::num::NonZeroI16;"]
///
#[doc =
"const TEN: NonZeroI16 = NonZeroI16::new(10).expect(\"ten is non-zero\");"]
/// ```
///
/// [null pointer optimization]: crate::option#representation
#[stable(feature = "signed_nonzero", since = "1.34.0")]
pub type NonZeroI16 = NonZero<i16>;
impl NonZero<i16> {
    /// The size of this non-zero integer type in bits.
    ///
    #[doc = "This value is equal to [`i16::BITS`]."]
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    #[doc = "assert_eq!(NonZero::<i16>::BITS, i16::BITS);"]
    /// ```
    #[stable(feature = "nonzero_bits", since = "1.67.0")]
    pub const BITS: u32 = <i16>::BITS;
    /// Returns the number of leading zeros in the binary representation of `self`.
    ///
    /// On many architectures, this function can perform better than `leading_zeros()` on the underlying integer type, as special handling of zero can be avoided.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::<i16>::new(-1i16)?;"]
    ///
    /// assert_eq!(n.leading_zeros(), 0);
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_leading_trailing_zeros", since = "1.53.0")]
    #[rustc_const_stable(feature = "nonzero_leading_trailing_zeros", since =
    "1.53.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const fn leading_zeros(self) -> u32 {
        unsafe { intrinsics::ctlz_nonzero(self.get() as u16) }
    }
    /// Returns the number of trailing zeros in the binary representation
    /// of `self`.
    ///
    /// On many architectures, this function can perform better than `trailing_zeros()` on the underlying integer type, as special handling of zero can be avoided.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::<i16>::new(0b0101000)?;"]
    ///
    /// assert_eq!(n.trailing_zeros(), 3);
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_leading_trailing_zeros", since = "1.53.0")]
    #[rustc_const_stable(feature = "nonzero_leading_trailing_zeros", since =
    "1.53.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const fn trailing_zeros(self) -> u32 {
        unsafe { intrinsics::cttz_nonzero(self.get() as u16) }
    }
    /// Returns `self` with only the most significant bit set.
    ///
    /// # Example
    ///
    /// ```
    /// # use core::num::NonZero;
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let a = NonZero::<i16>::new(0b_01100100)?;"]
    #[doc = "let b = NonZero::<i16>::new(0b_01000000)?;"]
    ///
    /// assert_eq!(a.isolate_highest_one(), b);
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "isolate_most_least_significant_one", since =
    "1.97.0")]
    #[rustc_const_stable(feature = "isolate_most_least_significant_one", since
    = "1.97.0")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn isolate_highest_one(self) -> Self {
        unsafe {
            let bit =
                (((1 as u16) <<
                                (<u16>::BITS - 1)).unchecked_shr(self.leading_zeros()));
            NonZero::new_unchecked(bit as i16)
        }
    }
    /// Returns `self` with only the least significant bit set.
    ///
    /// # Example
    ///
    /// ```
    /// # use core::num::NonZero;
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let a = NonZero::<i16>::new(0b_01100100)?;"]
    #[doc = "let b = NonZero::<i16>::new(0b_00000100)?;"]
    ///
    /// assert_eq!(a.isolate_lowest_one(), b);
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "isolate_most_least_significant_one", since =
    "1.97.0")]
    #[rustc_const_stable(feature = "isolate_most_least_significant_one", since
    = "1.97.0")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn isolate_lowest_one(self) -> Self {
        let n = self.get();
        let n = n & n.wrapping_neg();
        unsafe { NonZero::new_unchecked(n) }
    }
    /// Returns the index of the highest bit set to one in `self`.
    ///
    #[doc = ""]
    ///
    /// # Examples
    ///
    /// ```
    /// # use core::num::NonZero;
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "assert_eq!(NonZero::<i16>::new(0b1)?.highest_one(), 0);"]
    #[doc = "assert_eq!(NonZero::<i16>::new(0b1_0000)?.highest_one(), 4);"]
    #[doc = "assert_eq!(NonZero::<i16>::new(0b1_1111)?.highest_one(), 4);"]
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "int_lowest_highest_one", since = "1.97.0")]
    #[rustc_const_stable(feature = "int_lowest_highest_one", since =
    "1.97.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline(always)]
    pub const fn highest_one(self) -> u32 {
        Self::BITS - 1 - self.leading_zeros()
    }
    /// Returns the index of the lowest bit set to one in `self`.
    ///
    /// # Examples
    ///
    /// ```
    /// # use core::num::NonZero;
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "assert_eq!(NonZero::<i16>::new(0b1)?.lowest_one(), 0);"]
    #[doc = "assert_eq!(NonZero::<i16>::new(0b1_0000)?.lowest_one(), 4);"]
    #[doc = "assert_eq!(NonZero::<i16>::new(0b1_1111)?.lowest_one(), 0);"]
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "int_lowest_highest_one", since = "1.97.0")]
    #[rustc_const_stable(feature = "int_lowest_highest_one", since =
    "1.97.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline(always)]
    pub const fn lowest_one(self) -> u32 { self.trailing_zeros() }
    /// Returns the number of ones in the binary representation of `self`.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let a = NonZero::<i16>::new(0b100_0000)?;"]
    #[doc = "let b = NonZero::<i16>::new(0b100_0011)?;"]
    ///
    /// assert_eq!(a.count_ones(), NonZero::new(1)?);
    /// assert_eq!(b.count_ones(), NonZero::new(3)?);
    /// # Some(())
    /// # }
    /// ```
    ///
    #[stable(feature = "non_zero_count_ones", since = "1.86.0")]
    #[rustc_const_stable(feature = "non_zero_count_ones", since = "1.86.0")]
    #[doc(alias = "popcount")]
    #[doc(alias = "popcnt")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn count_ones(self) -> NonZero<u32> {
        unsafe { NonZero::new_unchecked(self.get().count_ones()) }
    }
    /// Shifts the bits to the left by a specified amount, `n`,
    /// wrapping the truncated bits to the end of the resulting integer.
    ///
    /// Please note this isn't the same operation as the `<<` shifting operator!
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(-0x5ffdi16)?;"]
    #[doc = "let m = NonZero::new(0x3a)?;"]
    ///
    #[doc = "assert_eq!(n.rotate_left(4), m);"]
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn rotate_left(self, n: u32) -> Self {
        let result = self.get().rotate_left(n);
        unsafe { Self::new_unchecked(result) }
    }
    /// Shifts the bits to the right by a specified amount, `n`,
    /// wrapping the truncated bits to the beginning of the resulting
    /// integer.
    ///
    /// Please note this isn't the same operation as the `>>` shifting operator!
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x3ai16)?;"]
    #[doc = "let m = NonZero::new(-0x5ffd)?;"]
    ///
    #[doc = "assert_eq!(n.rotate_right(4), m);"]
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn rotate_right(self, n: u32) -> Self {
        let result = self.get().rotate_right(n);
        unsafe { Self::new_unchecked(result) }
    }
    /// Reverses the byte order of the integer.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x1234i16)?;"]
    /// let m = n.swap_bytes();
    ///
    #[doc = "assert_eq!(m, NonZero::new(0x3412)?);"]
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn swap_bytes(self) -> Self {
        let result = self.get().swap_bytes();
        unsafe { Self::new_unchecked(result) }
    }
    /// Reverses the order of bits in the integer. The least significant bit becomes the most significant bit,
    /// second least-significant bit becomes second most-significant bit, etc.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x1234i16)?;"]
    /// let m = n.reverse_bits();
    ///
    #[doc = "assert_eq!(m, NonZero::new(0x2c48)?);"]
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn reverse_bits(self) -> Self {
        let result = self.get().reverse_bits();
        unsafe { Self::new_unchecked(result) }
    }
    /// Converts an integer from big endian to the target's endianness.
    ///
    /// On big endian this is a no-op. On little endian the bytes are
    /// swapped.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    #[doc = "use std::num::NonZeroI16;"]
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x1Ai16)?;"]
    ///
    /// if cfg!(target_endian = "big") {
    #[doc = "    assert_eq!(NonZeroI16::from_be(n), n)"]
    /// } else {
    #[doc = "    assert_eq!(NonZeroI16::from_be(n), n.swap_bytes())"]
    /// }
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use]
    #[inline(always)]
    pub const fn from_be(x: Self) -> Self {
        let result = i16::from_be(x.get());
        unsafe { Self::new_unchecked(result) }
    }
    /// Converts an integer from little endian to the target's endianness.
    ///
    /// On little endian this is a no-op. On big endian the bytes are
    /// swapped.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    #[doc = "use std::num::NonZeroI16;"]
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x1Ai16)?;"]
    ///
    /// if cfg!(target_endian = "little") {
    #[doc = "    assert_eq!(NonZeroI16::from_le(n), n)"]
    /// } else {
    #[doc = "    assert_eq!(NonZeroI16::from_le(n), n.swap_bytes())"]
    /// }
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use]
    #[inline(always)]
    pub const fn from_le(x: Self) -> Self {
        let result = i16::from_le(x.get());
        unsafe { Self::new_unchecked(result) }
    }
    /// Converts `self` to big endian from the target's endianness.
    ///
    /// On big endian this is a no-op. On little endian the bytes are
    /// swapped.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x1Ai16)?;"]
    ///
    /// if cfg!(target_endian = "big") {
    ///     assert_eq!(n.to_be(), n)
    /// } else {
    ///     assert_eq!(n.to_be(), n.swap_bytes())
    /// }
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn to_be(self) -> Self {
        let result = self.get().to_be();
        unsafe { Self::new_unchecked(result) }
    }
    /// Converts `self` to little endian from the target's endianness.
    ///
    /// On little endian this is a no-op. On big endian the bytes are
    /// swapped.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x1Ai16)?;"]
    ///
    /// if cfg!(target_endian = "little") {
    ///     assert_eq!(n.to_le(), n)
    /// } else {
    ///     assert_eq!(n.to_le(), n.swap_bytes())
    /// }
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn to_le(self) -> Self {
        let result = self.get().to_le();
        unsafe { Self::new_unchecked(result) }
    }
    /// The smallest value that can be represented by this non-zero
    /// integer type,
    #[doc = "equal to [`i16::MIN`]."]
    ///
    /// Note: While most integer types are defined for every whole
    /// number between `MIN` and `MAX`, signed non-zero integers are
    /// a special case. They have a "gap" at 0.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    #[doc = "assert_eq!(NonZero::<i16>::MIN.get(), i16::MIN);"]
    /// ```
    #[stable(feature = "nonzero_min_max", since = "1.70.0")]
    pub const MIN: Self = Self::new(<i16>::MIN).unwrap();
    /// The largest value that can be represented by this non-zero
    /// integer type,
    #[doc = "equal to [`i16::MAX`]."]
    ///
    /// Note: While most integer types are defined for every whole
    /// number between `MIN` and `MAX`, signed non-zero integers are
    /// a special case. They have a "gap" at 0.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    #[doc = "assert_eq!(NonZero::<i16>::MAX.get(), i16::MAX);"]
    /// ```
    #[stable(feature = "nonzero_min_max", since = "1.70.0")]
    pub const MAX: Self = Self::new(<i16>::MAX).unwrap();
    /// Computes the absolute value of self.
    #[doc = "See [`i16::abs`]"]
    /// for documentation on overflow behavior.
    ///
    /// # Example
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let pos = NonZero::new(1i16)?;"]
    #[doc = "let neg = NonZero::new(-1i16)?;"]
    ///
    /// assert_eq!(pos, pos.abs());
    /// assert_eq!(pos, neg.abs());
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const fn abs(self) -> Self {
        unsafe { Self::new_unchecked(self.get().abs()) }
    }
    /// Checked absolute value.
    /// Checks for overflow and returns [`None`] if
    #[doc = "`self == NonZero::<i16>::MIN`."]
    /// The result cannot be zero.
    ///
    /// # Example
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let pos = NonZero::new(1i16)?;"]
    #[doc = "let neg = NonZero::new(-1i16)?;"]
    #[doc = "let min = NonZero::new(i16::MIN)?;"]
    ///
    /// assert_eq!(Some(pos), neg.checked_abs());
    /// assert_eq!(None, min.checked_abs());
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const fn checked_abs(self) -> Option<Self> {
        if let Some(nz) = self.get().checked_abs() {
            Some(unsafe { Self::new_unchecked(nz) })
        } else { None }
    }
    /// Computes the absolute value of self,
    /// with overflow information, see
    #[doc = "[`i16::overflowing_abs`]."]
    ///
    /// # Example
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let pos = NonZero::new(1i16)?;"]
    #[doc = "let neg = NonZero::new(-1i16)?;"]
    #[doc = "let min = NonZero::new(i16::MIN)?;"]
    ///
    /// assert_eq!((pos, false), pos.overflowing_abs());
    /// assert_eq!((pos, false), neg.overflowing_abs());
    /// assert_eq!((min, true), min.overflowing_abs());
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const fn overflowing_abs(self) -> (Self, bool) {
        let (nz, flag) = self.get().overflowing_abs();
        (unsafe { Self::new_unchecked(nz) }, flag)
    }
    /// Saturating absolute value, see
    #[doc = "[`i16::saturating_abs`]."]
    ///
    /// # Example
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let pos = NonZero::new(1i16)?;"]
    #[doc = "let neg = NonZero::new(-1i16)?;"]
    #[doc = "let min = NonZero::new(i16::MIN)?;"]
    #[doc = "let min_plus = NonZero::new(i16::MIN + 1)?;"]
    #[doc = "let max = NonZero::new(i16::MAX)?;"]
    ///
    /// assert_eq!(pos, pos.saturating_abs());
    /// assert_eq!(pos, neg.saturating_abs());
    /// assert_eq!(max, min.saturating_abs());
    /// assert_eq!(max, min_plus.saturating_abs());
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const fn saturating_abs(self) -> Self {
        unsafe { Self::new_unchecked(self.get().saturating_abs()) }
    }
    /// Wrapping absolute value, see
    #[doc = "[`i16::wrapping_abs`]."]
    ///
    /// # Example
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let pos = NonZero::new(1i16)?;"]
    #[doc = "let neg = NonZero::new(-1i16)?;"]
    #[doc = "let min = NonZero::new(i16::MIN)?;"]
    #[doc = "# let max = NonZero::new(i16::MAX)?;"]
    ///
    /// assert_eq!(pos, pos.wrapping_abs());
    /// assert_eq!(pos, neg.wrapping_abs());
    /// assert_eq!(min, min.wrapping_abs());
    /// assert_eq!(max, (-max).wrapping_abs());
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const fn wrapping_abs(self) -> Self {
        unsafe { Self::new_unchecked(self.get().wrapping_abs()) }
    }
    /// Computes the absolute value of self
    /// without any wrapping or panicking.
    ///
    /// # Example
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let u_pos = NonZero::new(1u16)?;"]
    #[doc = "let i_pos = NonZero::new(1i16)?;"]
    #[doc = "let i_neg = NonZero::new(-1i16)?;"]
    #[doc = "let i_min = NonZero::new(i16::MIN)?;"]
    #[doc = "let u_max = NonZero::new(u16::MAX / 2 + 1)?;"]
    ///
    /// assert_eq!(u_pos, i_pos.unsigned_abs());
    /// assert_eq!(u_pos, i_neg.unsigned_abs());
    /// assert_eq!(u_max, i_min.unsigned_abs());
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const fn unsigned_abs(self) -> NonZero<u16> {
        unsafe { NonZero::new_unchecked(self.get().unsigned_abs()) }
    }
    /// Returns `true` if `self` is positive and `false` if the
    /// number is negative.
    ///
    /// # Example
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let pos_five = NonZero::new(5i16)?;"]
    #[doc = "let neg_five = NonZero::new(-5i16)?;"]
    ///
    /// assert!(pos_five.is_positive());
    /// assert!(!neg_five.is_positive());
    /// # Some(())
    /// # }
    /// ```
    #[must_use]
    #[inline]
    #[stable(feature = "nonzero_negation_ops", since = "1.71.0")]
    #[rustc_const_stable(feature = "nonzero_negation_ops", since = "1.71.0")]
    pub const fn is_positive(self) -> bool { self.get().is_positive() }
    /// Returns `true` if `self` is negative and `false` if the
    /// number is positive.
    ///
    /// # Example
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let pos_five = NonZero::new(5i16)?;"]
    #[doc = "let neg_five = NonZero::new(-5i16)?;"]
    ///
    /// assert!(neg_five.is_negative());
    /// assert!(!pos_five.is_negative());
    /// # Some(())
    /// # }
    /// ```
    #[must_use]
    #[inline]
    #[stable(feature = "nonzero_negation_ops", since = "1.71.0")]
    #[rustc_const_stable(feature = "nonzero_negation_ops", since = "1.71.0")]
    pub const fn is_negative(self) -> bool { self.get().is_negative() }
    /// Checked negation. Computes `-self`,
    #[doc = "returning `None` if `self == NonZero::<i16>::MIN`."]
    ///
    /// # Example
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let pos_five = NonZero::new(5i16)?;"]
    #[doc = "let neg_five = NonZero::new(-5i16)?;"]
    #[doc = "let min = NonZero::new(i16::MIN)?;"]
    ///
    /// assert_eq!(pos_five.checked_neg(), Some(neg_five));
    /// assert_eq!(min.checked_neg(), None);
    /// # Some(())
    /// # }
    /// ```
    #[inline]
    #[stable(feature = "nonzero_negation_ops", since = "1.71.0")]
    #[rustc_const_stable(feature = "nonzero_negation_ops", since = "1.71.0")]
    pub const fn checked_neg(self) -> Option<Self> {
        if let Some(result) = self.get().checked_neg() {
            return Some(unsafe { Self::new_unchecked(result) });
        }
        None
    }
    /// Checked negation. Computes `-self`, panicking if `self == MIN`.
    ///
    /// # Panics
    ///
    /// ## Overflow behavior
    ///
    /// This function always panics on overflow, regardless of whether
    /// overflow checks are enabled.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_strict_ops)]
    ///
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let pos_six = NonZero::new(6i16)?;"]
    #[doc = "let neg_six = NonZero::new(-6i16)?;"]
    ///
    /// assert_eq!(pos_six.strict_neg(), neg_six);
    /// # Some(())
    /// # }
    /// ```
    ///
    /// The following panics because of overflow:
    ///
    /// ```should_panic
    /// #![feature(nonzero_strict_ops)]
    ///
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let min = NonZero::new(i16::MIN)?;"]
    ///
    /// let _ = min.strict_neg();
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_strict_ops", issue = "164850")]
    #[rustc_const_unstable(feature = "const_nonzero_strict_ops", issue =
    "164850")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    #[track_caller]
    pub const fn strict_neg(self) -> Self {
        unsafe { Self::new_unchecked(self.get().strict_neg()) }
    }
    /// Negates self, overflowing if this is equal to the minimum value.
    ///
    #[doc = "See [`i16::overflowing_neg`]"]
    /// for documentation on overflow behavior.
    ///
    /// # Example
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let pos_five = NonZero::new(5i16)?;"]
    #[doc = "let neg_five = NonZero::new(-5i16)?;"]
    #[doc = "let min = NonZero::new(i16::MIN)?;"]
    ///
    /// assert_eq!(pos_five.overflowing_neg(), (neg_five, false));
    /// assert_eq!(min.overflowing_neg(), (min, true));
    /// # Some(())
    /// # }
    /// ```
    #[inline]
    #[stable(feature = "nonzero_negation_ops", since = "1.71.0")]
    #[rustc_const_stable(feature = "nonzero_negation_ops", since = "1.71.0")]
    pub const fn overflowing_neg(self) -> (Self, bool) {
        let (result, overflow) = self.get().overflowing_neg();
        ((unsafe { Self::new_unchecked(result) }), overflow)
    }
    /// Saturating negation. Computes `-self`,
    #[doc = "returning [`NonZero::<i16>::MAX`]"]
    #[doc = "if `self == NonZero::<i16>::MIN`"]
    /// instead of overflowing.
    ///
    /// # Example
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let pos_five = NonZero::new(5i16)?;"]
    #[doc = "let neg_five = NonZero::new(-5i16)?;"]
    #[doc = "let min = NonZero::new(i16::MIN)?;"]
    #[doc = "let min_plus_one = NonZero::new(i16::MIN + 1)?;"]
    #[doc = "let max = NonZero::new(i16::MAX)?;"]
    ///
    /// assert_eq!(pos_five.saturating_neg(), neg_five);
    /// assert_eq!(min.saturating_neg(), max);
    /// assert_eq!(max.saturating_neg(), min_plus_one);
    /// # Some(())
    /// # }
    /// ```
    #[inline]
    #[stable(feature = "nonzero_negation_ops", since = "1.71.0")]
    #[rustc_const_stable(feature = "nonzero_negation_ops", since = "1.71.0")]
    pub const fn saturating_neg(self) -> Self {
        if let Some(result) = self.checked_neg() { return result; }
        Self::MAX
    }
    /// Wrapping (modular) negation. Computes `-self`, wrapping around at the boundary
    /// of the type.
    ///
    #[doc = "See [`i16::wrapping_neg`]"]
    /// for documentation on overflow behavior.
    ///
    /// # Example
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let pos_five = NonZero::new(5i16)?;"]
    #[doc = "let neg_five = NonZero::new(-5i16)?;"]
    #[doc = "let min = NonZero::new(i16::MIN)?;"]
    ///
    /// assert_eq!(pos_five.wrapping_neg(), neg_five);
    /// assert_eq!(min.wrapping_neg(), min);
    /// # Some(())
    /// # }
    /// ```
    #[inline]
    #[stable(feature = "nonzero_negation_ops", since = "1.71.0")]
    #[rustc_const_stable(feature = "nonzero_negation_ops", since = "1.71.0")]
    pub const fn wrapping_neg(self) -> Self {
        let result = self.get().wrapping_neg();
        unsafe { Self::new_unchecked(result) }
    }
    /// Returns the bit pattern of `self` reinterpreted as an unsigned integer of the same size.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    ///
    #[doc = "let n = NonZero::new(-1i16).unwrap();"]
    ///
    #[doc = "assert_eq!(n.cast_unsigned(), NonZero::<u16>::MAX);"]
    /// ```
    #[stable(feature = "integer_sign_cast", since = "1.87.0")]
    #[rustc_const_stable(feature = "integer_sign_cast", since = "1.87.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline(always)]
    pub const fn cast_unsigned(self) -> NonZero<u16> {
        unsafe { NonZero::new_unchecked(self.get().cast_unsigned()) }
    }
    /// Clamps this number to a symmetric range centred around zero.
    ///
    /// The method clamps the number's magnitude (absolute value) to be at most `limit`.
    ///
    /// This is functionally equivalent to `self.clamp(-limit, limit)`, but is more
    /// explicit about the intent.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(clamp_magnitude)]
    /// # use std::num::NonZero;
    /// #
    #[doc = "let limit = NonZero::<u16>::new(100).unwrap();"]
    ///
    /// assert_eq!(
    #[doc = "    NonZero::<i16>::new(120).unwrap().clamp_magnitude(limit),"]
    #[doc = "    NonZero::<i16>::new(100).unwrap(),"]
    /// );
    ///
    /// assert_eq!(
    #[doc = "    NonZero::<i16>::new(-120).unwrap().clamp_magnitude(limit),"]
    #[doc = "    NonZero::<i16>::new(-100).unwrap(),"]
    /// );
    ///
    /// assert_eq!(
    #[doc = "    NonZero::<i16>::new(80).unwrap().clamp_magnitude(limit),"]
    #[doc = "    NonZero::<i16>::new(80).unwrap(),"]
    /// );
    ///
    /// assert_eq!(
    #[doc = "    NonZero::<i16>::new(-80).unwrap().clamp_magnitude(limit),"]
    #[doc = "    NonZero::<i16>::new(-80).unwrap(),"]
    /// );
    /// ```
    #[inline]
    #[must_use =
    "method returns a new number and does not mutate the original value"]
    #[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
    #[unstable(feature = "clamp_magnitude", issue = "148519")]
    pub const fn clamp_magnitude(self, limit: NonZero<u16>) -> Self {
        unsafe {
            Self::new_unchecked(self.get().clamp_magnitude(limit.get()))
        }
    }
    /// Multiplies two non-zero integers together.
    /// Checks for overflow and returns [`None`] on overflow.
    /// As a consequence, the result cannot wrap to zero.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let two = NonZero::new(2i16)?;"]
    #[doc = "let four = NonZero::new(4i16)?;"]
    #[doc = "let max = NonZero::new(i16::MAX)?;"]
    ///
    /// assert_eq!(Some(four), two.checked_mul(two));
    /// assert_eq!(None, max.checked_mul(two));
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const fn checked_mul(self, other: Self) -> Option<Self> {
        if let Some(result) = self.get().checked_mul(other.get()) {
            Some(unsafe { Self::new_unchecked(result) })
        } else { None }
    }
    /// Multiplies two non-zero integers together, panicking if
    /// overflow occurs.
    ///
    /// # Panics
    ///
    /// ## Overflow behavior
    ///
    /// This function always panics on overflow, regardless of whether
    /// overflow checks are enabled.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_strict_ops)]
    ///
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let three = NonZero::new(3i16)?;"]
    #[doc = "let nine = NonZero::new(9i16)?;"]
    ///
    /// assert_eq!(nine, three.strict_mul(three));
    /// # Some(())
    /// # }
    /// ```
    ///
    /// The following panics because of overflow:
    ///
    /// ```should_panic
    /// #![feature(nonzero_strict_ops)]
    ///
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let two = NonZero::new(2i16)?;"]
    #[doc = "let max = NonZero::new(i16::MAX)?;"]
    ///
    /// let _ = max.strict_mul(two);
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_strict_ops", issue = "164850")]
    #[rustc_const_unstable(feature = "const_nonzero_strict_ops", issue =
    "164850")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    #[track_caller]
    pub const fn strict_mul(self, other: Self) -> Self {
        unsafe { Self::new_unchecked(self.get().strict_mul(other.get())) }
    }
    /// Multiplies two non-zero integers together.
    #[doc = "Return [`NonZero::<i16>::MAX`] on overflow."]
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let two = NonZero::new(2i16)?;"]
    #[doc = "let four = NonZero::new(4i16)?;"]
    #[doc = "let max = NonZero::new(i16::MAX)?;"]
    ///
    /// assert_eq!(four, two.saturating_mul(two));
    /// assert_eq!(max, four.saturating_mul(max));
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const fn saturating_mul(self, other: Self) -> Self {
        unsafe { Self::new_unchecked(self.get().saturating_mul(other.get())) }
    }
    /// Multiplies two non-zero integers together,
    /// assuming overflow cannot occur.
    /// Overflow is unchecked, and it is undefined behavior to overflow
    /// *even if the result would wrap to a non-zero value*.
    ///
    /// # Safety
    ///
    /// This results in undefined behavior when overflow occurs, i.e.
    /// when [`checked_mul`] would return `None`.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let two = NonZero::new(2i16)?;"]
    #[doc = "let four = NonZero::new(4i16)?;"]
    ///
    /// assert_eq!(four, unsafe { two.unchecked_mul(two) });
    /// # Some(())
    /// # }
    /// ```
    ///
    /// [`checked_mul`]: Self::checked_mul
    #[stable(feature = "nonzero_ops", since = "CURRENT_RUSTC_VERSION")]
    #[rustc_const_stable(feature = "nonzero_ops", since =
    "CURRENT_RUSTC_VERSION")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const unsafe fn unchecked_mul(self, other: Self) -> Self {
        unsafe { Self::new_unchecked(self.get().unchecked_mul(other.get())) }
    }
    /// Raises non-zero value to an integer power.
    /// Checks for overflow and returns [`None`] on overflow.
    /// As a consequence, the result cannot wrap to zero.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let three = NonZero::new(3i16)?;"]
    #[doc = "let twenty_seven = NonZero::new(27i16)?;"]
    #[doc = "let half_max = NonZero::new(i16::MAX / 2)?;"]
    ///
    /// assert_eq!(Some(twenty_seven), three.checked_pow(3));
    /// assert_eq!(None, half_max.checked_pow(3));
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const fn checked_pow(self, other: u32) -> Option<Self> {
        if let Some(result) = self.get().checked_pow(other) {
            Some(unsafe { Self::new_unchecked(result) })
        } else { None }
    }
    /// Raises a non-zero value to an integer power, panicking if
    /// overflow occurs.
    ///
    /// # Panics
    ///
    /// ## Overflow behavior
    ///
    /// This function always panics on overflow, regardless of whether
    /// overflow checks are enabled.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_strict_ops)]
    ///
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let two = NonZero::new(2i16)?;"]
    #[doc = "let sixteen = NonZero::new(16i16)?;"]
    ///
    /// assert_eq!(sixteen, two.strict_pow(4));
    /// # Some(())
    /// # }
    /// ```
    ///
    /// The following panics because of overflow:
    ///
    /// ```should_panic
    /// #![feature(nonzero_strict_ops)]
    ///
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let half_max = NonZero::new(i16::MAX / 2)?;"]
    ///
    /// let _ = half_max.strict_pow(2);
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_strict_ops", issue = "164850")]
    #[rustc_const_unstable(feature = "const_nonzero_strict_ops", issue =
    "164850")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    #[track_caller]
    pub const fn strict_pow(self, exp: u32) -> Self {
        unsafe { Self::new_unchecked(self.get().strict_pow(exp)) }
    }
    /// Raise non-zero value to an integer power.
    #[doc =
    "Return [`NonZero::<i16>::MIN`] or [`NonZero::<i16>::MAX`] on overflow."]
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let three = NonZero::new(3i16)?;"]
    #[doc = "let twenty_seven = NonZero::new(27i16)?;"]
    #[doc = "let max = NonZero::new(i16::MAX)?;"]
    ///
    /// assert_eq!(twenty_seven, three.saturating_pow(3));
    /// assert_eq!(max, max.saturating_pow(3));
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const fn saturating_pow(self, other: u32) -> Self {
        unsafe { Self::new_unchecked(self.get().saturating_pow(other)) }
    }
    /// Parses a non-zero integer from an ASCII-byte slice with decimal digits.
    ///
    /// The characters are expected to be an optional
    #[doc = " `+` or `-` "]
    /// sign followed by only digits. Leading and trailing non-digit characters (including
    /// whitespace) represent an error. Underscores (which are accepted in Rust literals)
    /// also represent an error.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc =
    "assert_eq!(NonZero::<i16>::from_ascii_bytes(b\"+10\"), Ok(NonZero::new(10)?));"]
    /// # Some(())
    /// # }
    /// ```
    ///
    /// Trailing space returns error:
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    #[doc = "assert!(NonZero::<i16>::from_ascii_bytes(b\"1 \").is_err());"]
    /// ```
    #[stable(feature = "int_from_ascii", since = "CURRENT_RUSTC_VERSION")]
    #[rustc_const_unstable(feature = "const_convert", issue = "143773")]
    #[inline]
    pub const fn from_ascii_bytes<T>(src: T) -> Result<Self, ParseIntError>
        where T: [const] AsRef<[u8]> + [const] crate::marker::Destruct {
        Self::from_ascii_bytes_radix_impl(src.as_ref(), 10)
    }
    /// Parses a non-zero integer from an ASCII-byte slice with digits in a given base.
    ///
    /// The characters are expected to be an optional
    #[doc = " `+` or `-` "]
    /// sign followed by only digits. Leading and trailing non-digit characters (including
    /// whitespace) represent an error. Underscores (which are accepted in Rust literals)
    /// also represent an error.
    ///
    /// Digits are a subset of these characters, depending on `radix`:
    ///
    /// - `0-9`
    /// - `a-z`
    /// - `A-Z`
    ///
    /// # Panics
    ///
    /// This method panics if `radix` is not in the range from 2 to 36.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc =
    "assert_eq!(NonZero::<i16>::from_ascii_bytes_radix(b\"A\", 16), Ok(NonZero::new(10)?));"]
    /// # Some(())
    /// # }
    /// ```
    ///
    /// Trailing space returns error:
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    #[doc =
    "assert!(NonZero::<i16>::from_ascii_bytes_radix(b\"1 \", 10).is_err());"]
    /// ```
    #[stable(feature = "int_from_ascii", since = "CURRENT_RUSTC_VERSION")]
    #[rustc_const_unstable(feature = "const_convert", issue = "143773")]
    #[inline]
    pub const fn from_ascii_bytes_radix<T>(src: T, radix: u32)
        -> Result<Self, ParseIntError> where T: [const] AsRef<[u8]> + [const]
        crate::marker::Destruct {
        Self::from_ascii_bytes_radix_impl(src.as_ref(), radix)
    }
    #[inline]
    const fn from_ascii_bytes_radix_impl(src: &[u8], radix: u32)
        -> Result<Self, ParseIntError> {
        let n =
            match <i16>::from_ascii_bytes_radix_impl(src, radix) {
                Ok(n) => n,
                Err(err) => return Err(err),
            };
        if let Some(n) = Self::new(n) {
            Ok(n)
        } else { Err(ParseIntError { kind: IntErrorKind::Zero }) }
    }
    /// Parses a non-zero integer from a string slice with digits in a given base.
    ///
    /// The string is expected to be an optional
    #[doc = " `+` or `-` "]
    /// sign followed by only digits. Leading and trailing non-digit characters (including
    /// whitespace) represent an error. Underscores (which are accepted in Rust literals)
    /// also represent an error.
    ///
    /// Digits are a subset of these characters, depending on `radix`:
    ///
    /// - `0-9`
    /// - `a-z`
    /// - `A-Z`
    ///
    /// # Panics
    ///
    /// This method panics if `radix` is not in the range from 2 to 36.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc =
    "assert_eq!(NonZero::<i16>::from_str_radix(\"A\", 16), Ok(NonZero::new(10)?));"]
    /// # Some(())
    /// # }
    /// ```
    ///
    /// Trailing space returns error:
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    #[doc = "assert!(NonZero::<i16>::from_str_radix(\"1 \", 10).is_err());"]
    /// ```
    #[stable(feature = "nonzero_from_str_radix", since = "1.98.0")]
    #[rustc_const_stable(feature = "nonzero_from_str_radix", since =
    "1.98.0")]
    #[inline]
    pub const fn from_str_radix(src: &str, radix: u32)
        -> Result<Self, ParseIntError> {
        Self::from_ascii_bytes_radix_impl(src.as_bytes(), radix)
    }
}
#[stable(feature = "nonzero_parse", since = "1.35.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl FromStr for NonZero<i16> {
    type Err = ParseIntError;
    /// Parses a non-zero integer from a string slice with decimal digits.
    ///
    /// The characters are expected to be an optional
    #[doc = " `+` or `-` "]
    /// sign followed by only digits. Leading and trailing non-digit characters (including
    /// whitespace) represent an error. Underscores (which are accepted in Rust literals)
    /// also represent an error.
    ///
    /// # Examples
    ///
    /// ```
    /// use std::num::NonZero;
    /// use std::str::FromStr;
    ///
    #[doc =
    "assert_eq!(NonZero::<i16>::from_str(\"+10\"), Ok(NonZero::new(10).unwrap()));"]
    /// ```
    ///
    /// Trailing space returns error:
    ///
    /// ```
    /// use std::num::NonZero;
    /// use std::str::FromStr;
    ///
    #[doc = "assert!(NonZero::<i16>::from_str(\"1 \").is_err());"]
    /// ```
    #[inline]
    fn from_str(src: &str) -> Result<Self, Self::Err> {
        Self::from_str_radix(src, 10)
    }
}
#[stable(feature = "signed_nonzero_neg", since = "1.71.0")]
#[rustc_const_unstable(feature = "const_ops", issue = "143802")]
const impl Neg for NonZero<i16> {
    type Output = Self;
    #[inline]
    fn neg(self) -> Self { unsafe { Self::new_unchecked(self.get().neg()) } }
}
#[stable(feature = "signed_nonzero_neg", since = "1.71.0")]
#[rustc_const_unstable(feature = "const_ops", issue = "143802")]
const impl Neg for &NonZero<i16> {
    type Output = <NonZero<i16> as Neg>::Output;
    #[inline]
    fn neg(self) -> <NonZero<i16> as Neg>::Output { Neg::neg(*self) }
}nonzero_integer! {
3005    Self = NonZeroI16,
3006    Primitive = signed i16,
3007    UnsignedPrimitive = u16,
3008    rot = 4,
3009    rot_op = "-0x5ffd",
3010    rot_result = "0x3a",
3011    swap_op = "0x1234",
3012    swapped = "0x3412",
3013    reversed = "0x2c48",
3014}
3015
3016#[doc = "An [`i32`] that is known not to equal zero."]
///
/// This enables some memory layout optimization.
#[doc = "For example, `Option<NonZeroI32>` is the same size as `i32`:"]
///
/// ```rust
#[doc =
"assert_eq!(size_of::<Option<core::num::NonZeroI32>>(), size_of::<i32>());"]
/// ```
///
/// # Layout
///
#[doc =
"`NonZeroI32` is guaranteed to have the same layout and bit validity as `i32`"]
/// with the exception that `0` is not a valid instance.
#[doc = "`Option<NonZeroI32>` is guaranteed to be ABI-compatible with `i32`,"]
/// including in FFI.
///
/// Thanks to the [null pointer optimization],
#[doc = "`NonZeroI32` and `Option<NonZeroI32>`"]
/// are guaranteed to have the same size and alignment:
///
/// ```
#[doc = "use std::num::NonZeroI32;"]
///
#[doc =
"assert_eq!(size_of::<NonZeroI32>(), size_of::<Option<NonZeroI32>>());"]
#[doc =
"assert_eq!(align_of::<NonZeroI32>(), align_of::<Option<NonZeroI32>>());"]
/// ```
///
/// # Compile-time creation
///
/// Since both [`Option::unwrap()`] and [`Option::expect()`] are `const`, it is possible to
/// define a new
#[doc = "`NonZeroI32`"]
/// at compile time via:
/// ```
#[doc = "use std::num::NonZeroI32;"]
///
#[doc =
"const TEN: NonZeroI32 = NonZeroI32::new(10).expect(\"ten is non-zero\");"]
/// ```
///
/// [null pointer optimization]: crate::option#representation
#[stable(feature = "signed_nonzero", since = "1.34.0")]
pub type NonZeroI32 = NonZero<i32>;
impl NonZero<i32> {
    /// The size of this non-zero integer type in bits.
    ///
    #[doc = "This value is equal to [`i32::BITS`]."]
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    #[doc = "assert_eq!(NonZero::<i32>::BITS, i32::BITS);"]
    /// ```
    #[stable(feature = "nonzero_bits", since = "1.67.0")]
    pub const BITS: u32 = <i32>::BITS;
    /// Returns the number of leading zeros in the binary representation of `self`.
    ///
    /// On many architectures, this function can perform better than `leading_zeros()` on the underlying integer type, as special handling of zero can be avoided.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::<i32>::new(-1i32)?;"]
    ///
    /// assert_eq!(n.leading_zeros(), 0);
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_leading_trailing_zeros", since = "1.53.0")]
    #[rustc_const_stable(feature = "nonzero_leading_trailing_zeros", since =
    "1.53.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const fn leading_zeros(self) -> u32 {
        unsafe { intrinsics::ctlz_nonzero(self.get() as u32) }
    }
    /// Returns the number of trailing zeros in the binary representation
    /// of `self`.
    ///
    /// On many architectures, this function can perform better than `trailing_zeros()` on the underlying integer type, as special handling of zero can be avoided.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::<i32>::new(0b0101000)?;"]
    ///
    /// assert_eq!(n.trailing_zeros(), 3);
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_leading_trailing_zeros", since = "1.53.0")]
    #[rustc_const_stable(feature = "nonzero_leading_trailing_zeros", since =
    "1.53.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const fn trailing_zeros(self) -> u32 {
        unsafe { intrinsics::cttz_nonzero(self.get() as u32) }
    }
    /// Returns `self` with only the most significant bit set.
    ///
    /// # Example
    ///
    /// ```
    /// # use core::num::NonZero;
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let a = NonZero::<i32>::new(0b_01100100)?;"]
    #[doc = "let b = NonZero::<i32>::new(0b_01000000)?;"]
    ///
    /// assert_eq!(a.isolate_highest_one(), b);
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "isolate_most_least_significant_one", since =
    "1.97.0")]
    #[rustc_const_stable(feature = "isolate_most_least_significant_one", since
    = "1.97.0")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn isolate_highest_one(self) -> Self {
        unsafe {
            let bit =
                (((1 as u32) <<
                                (<u32>::BITS - 1)).unchecked_shr(self.leading_zeros()));
            NonZero::new_unchecked(bit as i32)
        }
    }
    /// Returns `self` with only the least significant bit set.
    ///
    /// # Example
    ///
    /// ```
    /// # use core::num::NonZero;
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let a = NonZero::<i32>::new(0b_01100100)?;"]
    #[doc = "let b = NonZero::<i32>::new(0b_00000100)?;"]
    ///
    /// assert_eq!(a.isolate_lowest_one(), b);
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "isolate_most_least_significant_one", since =
    "1.97.0")]
    #[rustc_const_stable(feature = "isolate_most_least_significant_one", since
    = "1.97.0")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn isolate_lowest_one(self) -> Self {
        let n = self.get();
        let n = n & n.wrapping_neg();
        unsafe { NonZero::new_unchecked(n) }
    }
    /// Returns the index of the highest bit set to one in `self`.
    ///
    #[doc = ""]
    ///
    /// # Examples
    ///
    /// ```
    /// # use core::num::NonZero;
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "assert_eq!(NonZero::<i32>::new(0b1)?.highest_one(), 0);"]
    #[doc = "assert_eq!(NonZero::<i32>::new(0b1_0000)?.highest_one(), 4);"]
    #[doc = "assert_eq!(NonZero::<i32>::new(0b1_1111)?.highest_one(), 4);"]
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "int_lowest_highest_one", since = "1.97.0")]
    #[rustc_const_stable(feature = "int_lowest_highest_one", since =
    "1.97.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline(always)]
    pub const fn highest_one(self) -> u32 {
        Self::BITS - 1 - self.leading_zeros()
    }
    /// Returns the index of the lowest bit set to one in `self`.
    ///
    /// # Examples
    ///
    /// ```
    /// # use core::num::NonZero;
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "assert_eq!(NonZero::<i32>::new(0b1)?.lowest_one(), 0);"]
    #[doc = "assert_eq!(NonZero::<i32>::new(0b1_0000)?.lowest_one(), 4);"]
    #[doc = "assert_eq!(NonZero::<i32>::new(0b1_1111)?.lowest_one(), 0);"]
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "int_lowest_highest_one", since = "1.97.0")]
    #[rustc_const_stable(feature = "int_lowest_highest_one", since =
    "1.97.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline(always)]
    pub const fn lowest_one(self) -> u32 { self.trailing_zeros() }
    /// Returns the number of ones in the binary representation of `self`.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let a = NonZero::<i32>::new(0b100_0000)?;"]
    #[doc = "let b = NonZero::<i32>::new(0b100_0011)?;"]
    ///
    /// assert_eq!(a.count_ones(), NonZero::new(1)?);
    /// assert_eq!(b.count_ones(), NonZero::new(3)?);
    /// # Some(())
    /// # }
    /// ```
    ///
    #[stable(feature = "non_zero_count_ones", since = "1.86.0")]
    #[rustc_const_stable(feature = "non_zero_count_ones", since = "1.86.0")]
    #[doc(alias = "popcount")]
    #[doc(alias = "popcnt")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn count_ones(self) -> NonZero<u32> {
        unsafe { NonZero::new_unchecked(self.get().count_ones()) }
    }
    /// Shifts the bits to the left by a specified amount, `n`,
    /// wrapping the truncated bits to the end of the resulting integer.
    ///
    /// Please note this isn't the same operation as the `<<` shifting operator!
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x10000b3i32)?;"]
    #[doc = "let m = NonZero::new(0xb301)?;"]
    ///
    #[doc = "assert_eq!(n.rotate_left(8), m);"]
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn rotate_left(self, n: u32) -> Self {
        let result = self.get().rotate_left(n);
        unsafe { Self::new_unchecked(result) }
    }
    /// Shifts the bits to the right by a specified amount, `n`,
    /// wrapping the truncated bits to the beginning of the resulting
    /// integer.
    ///
    /// Please note this isn't the same operation as the `>>` shifting operator!
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0xb301i32)?;"]
    #[doc = "let m = NonZero::new(0x10000b3)?;"]
    ///
    #[doc = "assert_eq!(n.rotate_right(8), m);"]
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn rotate_right(self, n: u32) -> Self {
        let result = self.get().rotate_right(n);
        unsafe { Self::new_unchecked(result) }
    }
    /// Reverses the byte order of the integer.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x12345678i32)?;"]
    /// let m = n.swap_bytes();
    ///
    #[doc = "assert_eq!(m, NonZero::new(0x78563412)?);"]
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn swap_bytes(self) -> Self {
        let result = self.get().swap_bytes();
        unsafe { Self::new_unchecked(result) }
    }
    /// Reverses the order of bits in the integer. The least significant bit becomes the most significant bit,
    /// second least-significant bit becomes second most-significant bit, etc.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x12345678i32)?;"]
    /// let m = n.reverse_bits();
    ///
    #[doc = "assert_eq!(m, NonZero::new(0x1e6a2c48)?);"]
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn reverse_bits(self) -> Self {
        let result = self.get().reverse_bits();
        unsafe { Self::new_unchecked(result) }
    }
    /// Converts an integer from big endian to the target's endianness.
    ///
    /// On big endian this is a no-op. On little endian the bytes are
    /// swapped.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    #[doc = "use std::num::NonZeroI32;"]
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x1Ai32)?;"]
    ///
    /// if cfg!(target_endian = "big") {
    #[doc = "    assert_eq!(NonZeroI32::from_be(n), n)"]
    /// } else {
    #[doc = "    assert_eq!(NonZeroI32::from_be(n), n.swap_bytes())"]
    /// }
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use]
    #[inline(always)]
    pub const fn from_be(x: Self) -> Self {
        let result = i32::from_be(x.get());
        unsafe { Self::new_unchecked(result) }
    }
    /// Converts an integer from little endian to the target's endianness.
    ///
    /// On little endian this is a no-op. On big endian the bytes are
    /// swapped.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    #[doc = "use std::num::NonZeroI32;"]
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x1Ai32)?;"]
    ///
    /// if cfg!(target_endian = "little") {
    #[doc = "    assert_eq!(NonZeroI32::from_le(n), n)"]
    /// } else {
    #[doc = "    assert_eq!(NonZeroI32::from_le(n), n.swap_bytes())"]
    /// }
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use]
    #[inline(always)]
    pub const fn from_le(x: Self) -> Self {
        let result = i32::from_le(x.get());
        unsafe { Self::new_unchecked(result) }
    }
    /// Converts `self` to big endian from the target's endianness.
    ///
    /// On big endian this is a no-op. On little endian the bytes are
    /// swapped.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x1Ai32)?;"]
    ///
    /// if cfg!(target_endian = "big") {
    ///     assert_eq!(n.to_be(), n)
    /// } else {
    ///     assert_eq!(n.to_be(), n.swap_bytes())
    /// }
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn to_be(self) -> Self {
        let result = self.get().to_be();
        unsafe { Self::new_unchecked(result) }
    }
    /// Converts `self` to little endian from the target's endianness.
    ///
    /// On little endian this is a no-op. On big endian the bytes are
    /// swapped.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x1Ai32)?;"]
    ///
    /// if cfg!(target_endian = "little") {
    ///     assert_eq!(n.to_le(), n)
    /// } else {
    ///     assert_eq!(n.to_le(), n.swap_bytes())
    /// }
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn to_le(self) -> Self {
        let result = self.get().to_le();
        unsafe { Self::new_unchecked(result) }
    }
    /// The smallest value that can be represented by this non-zero
    /// integer type,
    #[doc = "equal to [`i32::MIN`]."]
    ///
    /// Note: While most integer types are defined for every whole
    /// number between `MIN` and `MAX`, signed non-zero integers are
    /// a special case. They have a "gap" at 0.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    #[doc = "assert_eq!(NonZero::<i32>::MIN.get(), i32::MIN);"]
    /// ```
    #[stable(feature = "nonzero_min_max", since = "1.70.0")]
    pub const MIN: Self = Self::new(<i32>::MIN).unwrap();
    /// The largest value that can be represented by this non-zero
    /// integer type,
    #[doc = "equal to [`i32::MAX`]."]
    ///
    /// Note: While most integer types are defined for every whole
    /// number between `MIN` and `MAX`, signed non-zero integers are
    /// a special case. They have a "gap" at 0.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    #[doc = "assert_eq!(NonZero::<i32>::MAX.get(), i32::MAX);"]
    /// ```
    #[stable(feature = "nonzero_min_max", since = "1.70.0")]
    pub const MAX: Self = Self::new(<i32>::MAX).unwrap();
    /// Computes the absolute value of self.
    #[doc = "See [`i32::abs`]"]
    /// for documentation on overflow behavior.
    ///
    /// # Example
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let pos = NonZero::new(1i32)?;"]
    #[doc = "let neg = NonZero::new(-1i32)?;"]
    ///
    /// assert_eq!(pos, pos.abs());
    /// assert_eq!(pos, neg.abs());
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const fn abs(self) -> Self {
        unsafe { Self::new_unchecked(self.get().abs()) }
    }
    /// Checked absolute value.
    /// Checks for overflow and returns [`None`] if
    #[doc = "`self == NonZero::<i32>::MIN`."]
    /// The result cannot be zero.
    ///
    /// # Example
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let pos = NonZero::new(1i32)?;"]
    #[doc = "let neg = NonZero::new(-1i32)?;"]
    #[doc = "let min = NonZero::new(i32::MIN)?;"]
    ///
    /// assert_eq!(Some(pos), neg.checked_abs());
    /// assert_eq!(None, min.checked_abs());
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const fn checked_abs(self) -> Option<Self> {
        if let Some(nz) = self.get().checked_abs() {
            Some(unsafe { Self::new_unchecked(nz) })
        } else { None }
    }
    /// Computes the absolute value of self,
    /// with overflow information, see
    #[doc = "[`i32::overflowing_abs`]."]
    ///
    /// # Example
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let pos = NonZero::new(1i32)?;"]
    #[doc = "let neg = NonZero::new(-1i32)?;"]
    #[doc = "let min = NonZero::new(i32::MIN)?;"]
    ///
    /// assert_eq!((pos, false), pos.overflowing_abs());
    /// assert_eq!((pos, false), neg.overflowing_abs());
    /// assert_eq!((min, true), min.overflowing_abs());
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const fn overflowing_abs(self) -> (Self, bool) {
        let (nz, flag) = self.get().overflowing_abs();
        (unsafe { Self::new_unchecked(nz) }, flag)
    }
    /// Saturating absolute value, see
    #[doc = "[`i32::saturating_abs`]."]
    ///
    /// # Example
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let pos = NonZero::new(1i32)?;"]
    #[doc = "let neg = NonZero::new(-1i32)?;"]
    #[doc = "let min = NonZero::new(i32::MIN)?;"]
    #[doc = "let min_plus = NonZero::new(i32::MIN + 1)?;"]
    #[doc = "let max = NonZero::new(i32::MAX)?;"]
    ///
    /// assert_eq!(pos, pos.saturating_abs());
    /// assert_eq!(pos, neg.saturating_abs());
    /// assert_eq!(max, min.saturating_abs());
    /// assert_eq!(max, min_plus.saturating_abs());
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const fn saturating_abs(self) -> Self {
        unsafe { Self::new_unchecked(self.get().saturating_abs()) }
    }
    /// Wrapping absolute value, see
    #[doc = "[`i32::wrapping_abs`]."]
    ///
    /// # Example
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let pos = NonZero::new(1i32)?;"]
    #[doc = "let neg = NonZero::new(-1i32)?;"]
    #[doc = "let min = NonZero::new(i32::MIN)?;"]
    #[doc = "# let max = NonZero::new(i32::MAX)?;"]
    ///
    /// assert_eq!(pos, pos.wrapping_abs());
    /// assert_eq!(pos, neg.wrapping_abs());
    /// assert_eq!(min, min.wrapping_abs());
    /// assert_eq!(max, (-max).wrapping_abs());
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const fn wrapping_abs(self) -> Self {
        unsafe { Self::new_unchecked(self.get().wrapping_abs()) }
    }
    /// Computes the absolute value of self
    /// without any wrapping or panicking.
    ///
    /// # Example
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let u_pos = NonZero::new(1u32)?;"]
    #[doc = "let i_pos = NonZero::new(1i32)?;"]
    #[doc = "let i_neg = NonZero::new(-1i32)?;"]
    #[doc = "let i_min = NonZero::new(i32::MIN)?;"]
    #[doc = "let u_max = NonZero::new(u32::MAX / 2 + 1)?;"]
    ///
    /// assert_eq!(u_pos, i_pos.unsigned_abs());
    /// assert_eq!(u_pos, i_neg.unsigned_abs());
    /// assert_eq!(u_max, i_min.unsigned_abs());
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const fn unsigned_abs(self) -> NonZero<u32> {
        unsafe { NonZero::new_unchecked(self.get().unsigned_abs()) }
    }
    /// Returns `true` if `self` is positive and `false` if the
    /// number is negative.
    ///
    /// # Example
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let pos_five = NonZero::new(5i32)?;"]
    #[doc = "let neg_five = NonZero::new(-5i32)?;"]
    ///
    /// assert!(pos_five.is_positive());
    /// assert!(!neg_five.is_positive());
    /// # Some(())
    /// # }
    /// ```
    #[must_use]
    #[inline]
    #[stable(feature = "nonzero_negation_ops", since = "1.71.0")]
    #[rustc_const_stable(feature = "nonzero_negation_ops", since = "1.71.0")]
    pub const fn is_positive(self) -> bool { self.get().is_positive() }
    /// Returns `true` if `self` is negative and `false` if the
    /// number is positive.
    ///
    /// # Example
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let pos_five = NonZero::new(5i32)?;"]
    #[doc = "let neg_five = NonZero::new(-5i32)?;"]
    ///
    /// assert!(neg_five.is_negative());
    /// assert!(!pos_five.is_negative());
    /// # Some(())
    /// # }
    /// ```
    #[must_use]
    #[inline]
    #[stable(feature = "nonzero_negation_ops", since = "1.71.0")]
    #[rustc_const_stable(feature = "nonzero_negation_ops", since = "1.71.0")]
    pub const fn is_negative(self) -> bool { self.get().is_negative() }
    /// Checked negation. Computes `-self`,
    #[doc = "returning `None` if `self == NonZero::<i32>::MIN`."]
    ///
    /// # Example
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let pos_five = NonZero::new(5i32)?;"]
    #[doc = "let neg_five = NonZero::new(-5i32)?;"]
    #[doc = "let min = NonZero::new(i32::MIN)?;"]
    ///
    /// assert_eq!(pos_five.checked_neg(), Some(neg_five));
    /// assert_eq!(min.checked_neg(), None);
    /// # Some(())
    /// # }
    /// ```
    #[inline]
    #[stable(feature = "nonzero_negation_ops", since = "1.71.0")]
    #[rustc_const_stable(feature = "nonzero_negation_ops", since = "1.71.0")]
    pub const fn checked_neg(self) -> Option<Self> {
        if let Some(result) = self.get().checked_neg() {
            return Some(unsafe { Self::new_unchecked(result) });
        }
        None
    }
    /// Checked negation. Computes `-self`, panicking if `self == MIN`.
    ///
    /// # Panics
    ///
    /// ## Overflow behavior
    ///
    /// This function always panics on overflow, regardless of whether
    /// overflow checks are enabled.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_strict_ops)]
    ///
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let pos_six = NonZero::new(6i32)?;"]
    #[doc = "let neg_six = NonZero::new(-6i32)?;"]
    ///
    /// assert_eq!(pos_six.strict_neg(), neg_six);
    /// # Some(())
    /// # }
    /// ```
    ///
    /// The following panics because of overflow:
    ///
    /// ```should_panic
    /// #![feature(nonzero_strict_ops)]
    ///
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let min = NonZero::new(i32::MIN)?;"]
    ///
    /// let _ = min.strict_neg();
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_strict_ops", issue = "164850")]
    #[rustc_const_unstable(feature = "const_nonzero_strict_ops", issue =
    "164850")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    #[track_caller]
    pub const fn strict_neg(self) -> Self {
        unsafe { Self::new_unchecked(self.get().strict_neg()) }
    }
    /// Negates self, overflowing if this is equal to the minimum value.
    ///
    #[doc = "See [`i32::overflowing_neg`]"]
    /// for documentation on overflow behavior.
    ///
    /// # Example
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let pos_five = NonZero::new(5i32)?;"]
    #[doc = "let neg_five = NonZero::new(-5i32)?;"]
    #[doc = "let min = NonZero::new(i32::MIN)?;"]
    ///
    /// assert_eq!(pos_five.overflowing_neg(), (neg_five, false));
    /// assert_eq!(min.overflowing_neg(), (min, true));
    /// # Some(())
    /// # }
    /// ```
    #[inline]
    #[stable(feature = "nonzero_negation_ops", since = "1.71.0")]
    #[rustc_const_stable(feature = "nonzero_negation_ops", since = "1.71.0")]
    pub const fn overflowing_neg(self) -> (Self, bool) {
        let (result, overflow) = self.get().overflowing_neg();
        ((unsafe { Self::new_unchecked(result) }), overflow)
    }
    /// Saturating negation. Computes `-self`,
    #[doc = "returning [`NonZero::<i32>::MAX`]"]
    #[doc = "if `self == NonZero::<i32>::MIN`"]
    /// instead of overflowing.
    ///
    /// # Example
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let pos_five = NonZero::new(5i32)?;"]
    #[doc = "let neg_five = NonZero::new(-5i32)?;"]
    #[doc = "let min = NonZero::new(i32::MIN)?;"]
    #[doc = "let min_plus_one = NonZero::new(i32::MIN + 1)?;"]
    #[doc = "let max = NonZero::new(i32::MAX)?;"]
    ///
    /// assert_eq!(pos_five.saturating_neg(), neg_five);
    /// assert_eq!(min.saturating_neg(), max);
    /// assert_eq!(max.saturating_neg(), min_plus_one);
    /// # Some(())
    /// # }
    /// ```
    #[inline]
    #[stable(feature = "nonzero_negation_ops", since = "1.71.0")]
    #[rustc_const_stable(feature = "nonzero_negation_ops", since = "1.71.0")]
    pub const fn saturating_neg(self) -> Self {
        if let Some(result) = self.checked_neg() { return result; }
        Self::MAX
    }
    /// Wrapping (modular) negation. Computes `-self`, wrapping around at the boundary
    /// of the type.
    ///
    #[doc = "See [`i32::wrapping_neg`]"]
    /// for documentation on overflow behavior.
    ///
    /// # Example
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let pos_five = NonZero::new(5i32)?;"]
    #[doc = "let neg_five = NonZero::new(-5i32)?;"]
    #[doc = "let min = NonZero::new(i32::MIN)?;"]
    ///
    /// assert_eq!(pos_five.wrapping_neg(), neg_five);
    /// assert_eq!(min.wrapping_neg(), min);
    /// # Some(())
    /// # }
    /// ```
    #[inline]
    #[stable(feature = "nonzero_negation_ops", since = "1.71.0")]
    #[rustc_const_stable(feature = "nonzero_negation_ops", since = "1.71.0")]
    pub const fn wrapping_neg(self) -> Self {
        let result = self.get().wrapping_neg();
        unsafe { Self::new_unchecked(result) }
    }
    /// Returns the bit pattern of `self` reinterpreted as an unsigned integer of the same size.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    ///
    #[doc = "let n = NonZero::new(-1i32).unwrap();"]
    ///
    #[doc = "assert_eq!(n.cast_unsigned(), NonZero::<u32>::MAX);"]
    /// ```
    #[stable(feature = "integer_sign_cast", since = "1.87.0")]
    #[rustc_const_stable(feature = "integer_sign_cast", since = "1.87.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline(always)]
    pub const fn cast_unsigned(self) -> NonZero<u32> {
        unsafe { NonZero::new_unchecked(self.get().cast_unsigned()) }
    }
    /// Clamps this number to a symmetric range centred around zero.
    ///
    /// The method clamps the number's magnitude (absolute value) to be at most `limit`.
    ///
    /// This is functionally equivalent to `self.clamp(-limit, limit)`, but is more
    /// explicit about the intent.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(clamp_magnitude)]
    /// # use std::num::NonZero;
    /// #
    #[doc = "let limit = NonZero::<u32>::new(100).unwrap();"]
    ///
    /// assert_eq!(
    #[doc = "    NonZero::<i32>::new(120).unwrap().clamp_magnitude(limit),"]
    #[doc = "    NonZero::<i32>::new(100).unwrap(),"]
    /// );
    ///
    /// assert_eq!(
    #[doc = "    NonZero::<i32>::new(-120).unwrap().clamp_magnitude(limit),"]
    #[doc = "    NonZero::<i32>::new(-100).unwrap(),"]
    /// );
    ///
    /// assert_eq!(
    #[doc = "    NonZero::<i32>::new(80).unwrap().clamp_magnitude(limit),"]
    #[doc = "    NonZero::<i32>::new(80).unwrap(),"]
    /// );
    ///
    /// assert_eq!(
    #[doc = "    NonZero::<i32>::new(-80).unwrap().clamp_magnitude(limit),"]
    #[doc = "    NonZero::<i32>::new(-80).unwrap(),"]
    /// );
    /// ```
    #[inline]
    #[must_use =
    "method returns a new number and does not mutate the original value"]
    #[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
    #[unstable(feature = "clamp_magnitude", issue = "148519")]
    pub const fn clamp_magnitude(self, limit: NonZero<u32>) -> Self {
        unsafe {
            Self::new_unchecked(self.get().clamp_magnitude(limit.get()))
        }
    }
    /// Multiplies two non-zero integers together.
    /// Checks for overflow and returns [`None`] on overflow.
    /// As a consequence, the result cannot wrap to zero.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let two = NonZero::new(2i32)?;"]
    #[doc = "let four = NonZero::new(4i32)?;"]
    #[doc = "let max = NonZero::new(i32::MAX)?;"]
    ///
    /// assert_eq!(Some(four), two.checked_mul(two));
    /// assert_eq!(None, max.checked_mul(two));
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const fn checked_mul(self, other: Self) -> Option<Self> {
        if let Some(result) = self.get().checked_mul(other.get()) {
            Some(unsafe { Self::new_unchecked(result) })
        } else { None }
    }
    /// Multiplies two non-zero integers together, panicking if
    /// overflow occurs.
    ///
    /// # Panics
    ///
    /// ## Overflow behavior
    ///
    /// This function always panics on overflow, regardless of whether
    /// overflow checks are enabled.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_strict_ops)]
    ///
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let three = NonZero::new(3i32)?;"]
    #[doc = "let nine = NonZero::new(9i32)?;"]
    ///
    /// assert_eq!(nine, three.strict_mul(three));
    /// # Some(())
    /// # }
    /// ```
    ///
    /// The following panics because of overflow:
    ///
    /// ```should_panic
    /// #![feature(nonzero_strict_ops)]
    ///
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let two = NonZero::new(2i32)?;"]
    #[doc = "let max = NonZero::new(i32::MAX)?;"]
    ///
    /// let _ = max.strict_mul(two);
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_strict_ops", issue = "164850")]
    #[rustc_const_unstable(feature = "const_nonzero_strict_ops", issue =
    "164850")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    #[track_caller]
    pub const fn strict_mul(self, other: Self) -> Self {
        unsafe { Self::new_unchecked(self.get().strict_mul(other.get())) }
    }
    /// Multiplies two non-zero integers together.
    #[doc = "Return [`NonZero::<i32>::MAX`] on overflow."]
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let two = NonZero::new(2i32)?;"]
    #[doc = "let four = NonZero::new(4i32)?;"]
    #[doc = "let max = NonZero::new(i32::MAX)?;"]
    ///
    /// assert_eq!(four, two.saturating_mul(two));
    /// assert_eq!(max, four.saturating_mul(max));
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const fn saturating_mul(self, other: Self) -> Self {
        unsafe { Self::new_unchecked(self.get().saturating_mul(other.get())) }
    }
    /// Multiplies two non-zero integers together,
    /// assuming overflow cannot occur.
    /// Overflow is unchecked, and it is undefined behavior to overflow
    /// *even if the result would wrap to a non-zero value*.
    ///
    /// # Safety
    ///
    /// This results in undefined behavior when overflow occurs, i.e.
    /// when [`checked_mul`] would return `None`.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let two = NonZero::new(2i32)?;"]
    #[doc = "let four = NonZero::new(4i32)?;"]
    ///
    /// assert_eq!(four, unsafe { two.unchecked_mul(two) });
    /// # Some(())
    /// # }
    /// ```
    ///
    /// [`checked_mul`]: Self::checked_mul
    #[stable(feature = "nonzero_ops", since = "CURRENT_RUSTC_VERSION")]
    #[rustc_const_stable(feature = "nonzero_ops", since =
    "CURRENT_RUSTC_VERSION")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const unsafe fn unchecked_mul(self, other: Self) -> Self {
        unsafe { Self::new_unchecked(self.get().unchecked_mul(other.get())) }
    }
    /// Raises non-zero value to an integer power.
    /// Checks for overflow and returns [`None`] on overflow.
    /// As a consequence, the result cannot wrap to zero.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let three = NonZero::new(3i32)?;"]
    #[doc = "let twenty_seven = NonZero::new(27i32)?;"]
    #[doc = "let half_max = NonZero::new(i32::MAX / 2)?;"]
    ///
    /// assert_eq!(Some(twenty_seven), three.checked_pow(3));
    /// assert_eq!(None, half_max.checked_pow(3));
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const fn checked_pow(self, other: u32) -> Option<Self> {
        if let Some(result) = self.get().checked_pow(other) {
            Some(unsafe { Self::new_unchecked(result) })
        } else { None }
    }
    /// Raises a non-zero value to an integer power, panicking if
    /// overflow occurs.
    ///
    /// # Panics
    ///
    /// ## Overflow behavior
    ///
    /// This function always panics on overflow, regardless of whether
    /// overflow checks are enabled.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_strict_ops)]
    ///
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let two = NonZero::new(2i32)?;"]
    #[doc = "let sixteen = NonZero::new(16i32)?;"]
    ///
    /// assert_eq!(sixteen, two.strict_pow(4));
    /// # Some(())
    /// # }
    /// ```
    ///
    /// The following panics because of overflow:
    ///
    /// ```should_panic
    /// #![feature(nonzero_strict_ops)]
    ///
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let half_max = NonZero::new(i32::MAX / 2)?;"]
    ///
    /// let _ = half_max.strict_pow(2);
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_strict_ops", issue = "164850")]
    #[rustc_const_unstable(feature = "const_nonzero_strict_ops", issue =
    "164850")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    #[track_caller]
    pub const fn strict_pow(self, exp: u32) -> Self {
        unsafe { Self::new_unchecked(self.get().strict_pow(exp)) }
    }
    /// Raise non-zero value to an integer power.
    #[doc =
    "Return [`NonZero::<i32>::MIN`] or [`NonZero::<i32>::MAX`] on overflow."]
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let three = NonZero::new(3i32)?;"]
    #[doc = "let twenty_seven = NonZero::new(27i32)?;"]
    #[doc = "let max = NonZero::new(i32::MAX)?;"]
    ///
    /// assert_eq!(twenty_seven, three.saturating_pow(3));
    /// assert_eq!(max, max.saturating_pow(3));
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const fn saturating_pow(self, other: u32) -> Self {
        unsafe { Self::new_unchecked(self.get().saturating_pow(other)) }
    }
    /// Parses a non-zero integer from an ASCII-byte slice with decimal digits.
    ///
    /// The characters are expected to be an optional
    #[doc = " `+` or `-` "]
    /// sign followed by only digits. Leading and trailing non-digit characters (including
    /// whitespace) represent an error. Underscores (which are accepted in Rust literals)
    /// also represent an error.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc =
    "assert_eq!(NonZero::<i32>::from_ascii_bytes(b\"+10\"), Ok(NonZero::new(10)?));"]
    /// # Some(())
    /// # }
    /// ```
    ///
    /// Trailing space returns error:
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    #[doc = "assert!(NonZero::<i32>::from_ascii_bytes(b\"1 \").is_err());"]
    /// ```
    #[stable(feature = "int_from_ascii", since = "CURRENT_RUSTC_VERSION")]
    #[rustc_const_unstable(feature = "const_convert", issue = "143773")]
    #[inline]
    pub const fn from_ascii_bytes<T>(src: T) -> Result<Self, ParseIntError>
        where T: [const] AsRef<[u8]> + [const] crate::marker::Destruct {
        Self::from_ascii_bytes_radix_impl(src.as_ref(), 10)
    }
    /// Parses a non-zero integer from an ASCII-byte slice with digits in a given base.
    ///
    /// The characters are expected to be an optional
    #[doc = " `+` or `-` "]
    /// sign followed by only digits. Leading and trailing non-digit characters (including
    /// whitespace) represent an error. Underscores (which are accepted in Rust literals)
    /// also represent an error.
    ///
    /// Digits are a subset of these characters, depending on `radix`:
    ///
    /// - `0-9`
    /// - `a-z`
    /// - `A-Z`
    ///
    /// # Panics
    ///
    /// This method panics if `radix` is not in the range from 2 to 36.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc =
    "assert_eq!(NonZero::<i32>::from_ascii_bytes_radix(b\"A\", 16), Ok(NonZero::new(10)?));"]
    /// # Some(())
    /// # }
    /// ```
    ///
    /// Trailing space returns error:
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    #[doc =
    "assert!(NonZero::<i32>::from_ascii_bytes_radix(b\"1 \", 10).is_err());"]
    /// ```
    #[stable(feature = "int_from_ascii", since = "CURRENT_RUSTC_VERSION")]
    #[rustc_const_unstable(feature = "const_convert", issue = "143773")]
    #[inline]
    pub const fn from_ascii_bytes_radix<T>(src: T, radix: u32)
        -> Result<Self, ParseIntError> where T: [const] AsRef<[u8]> + [const]
        crate::marker::Destruct {
        Self::from_ascii_bytes_radix_impl(src.as_ref(), radix)
    }
    #[inline]
    const fn from_ascii_bytes_radix_impl(src: &[u8], radix: u32)
        -> Result<Self, ParseIntError> {
        let n =
            match <i32>::from_ascii_bytes_radix_impl(src, radix) {
                Ok(n) => n,
                Err(err) => return Err(err),
            };
        if let Some(n) = Self::new(n) {
            Ok(n)
        } else { Err(ParseIntError { kind: IntErrorKind::Zero }) }
    }
    /// Parses a non-zero integer from a string slice with digits in a given base.
    ///
    /// The string is expected to be an optional
    #[doc = " `+` or `-` "]
    /// sign followed by only digits. Leading and trailing non-digit characters (including
    /// whitespace) represent an error. Underscores (which are accepted in Rust literals)
    /// also represent an error.
    ///
    /// Digits are a subset of these characters, depending on `radix`:
    ///
    /// - `0-9`
    /// - `a-z`
    /// - `A-Z`
    ///
    /// # Panics
    ///
    /// This method panics if `radix` is not in the range from 2 to 36.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc =
    "assert_eq!(NonZero::<i32>::from_str_radix(\"A\", 16), Ok(NonZero::new(10)?));"]
    /// # Some(())
    /// # }
    /// ```
    ///
    /// Trailing space returns error:
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    #[doc = "assert!(NonZero::<i32>::from_str_radix(\"1 \", 10).is_err());"]
    /// ```
    #[stable(feature = "nonzero_from_str_radix", since = "1.98.0")]
    #[rustc_const_stable(feature = "nonzero_from_str_radix", since =
    "1.98.0")]
    #[inline]
    pub const fn from_str_radix(src: &str, radix: u32)
        -> Result<Self, ParseIntError> {
        Self::from_ascii_bytes_radix_impl(src.as_bytes(), radix)
    }
}
#[stable(feature = "nonzero_parse", since = "1.35.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl FromStr for NonZero<i32> {
    type Err = ParseIntError;
    /// Parses a non-zero integer from a string slice with decimal digits.
    ///
    /// The characters are expected to be an optional
    #[doc = " `+` or `-` "]
    /// sign followed by only digits. Leading and trailing non-digit characters (including
    /// whitespace) represent an error. Underscores (which are accepted in Rust literals)
    /// also represent an error.
    ///
    /// # Examples
    ///
    /// ```
    /// use std::num::NonZero;
    /// use std::str::FromStr;
    ///
    #[doc =
    "assert_eq!(NonZero::<i32>::from_str(\"+10\"), Ok(NonZero::new(10).unwrap()));"]
    /// ```
    ///
    /// Trailing space returns error:
    ///
    /// ```
    /// use std::num::NonZero;
    /// use std::str::FromStr;
    ///
    #[doc = "assert!(NonZero::<i32>::from_str(\"1 \").is_err());"]
    /// ```
    #[inline]
    fn from_str(src: &str) -> Result<Self, Self::Err> {
        Self::from_str_radix(src, 10)
    }
}
#[stable(feature = "signed_nonzero_neg", since = "1.71.0")]
#[rustc_const_unstable(feature = "const_ops", issue = "143802")]
const impl Neg for NonZero<i32> {
    type Output = Self;
    #[inline]
    fn neg(self) -> Self { unsafe { Self::new_unchecked(self.get().neg()) } }
}
#[stable(feature = "signed_nonzero_neg", since = "1.71.0")]
#[rustc_const_unstable(feature = "const_ops", issue = "143802")]
const impl Neg for &NonZero<i32> {
    type Output = <NonZero<i32> as Neg>::Output;
    #[inline]
    fn neg(self) -> <NonZero<i32> as Neg>::Output { Neg::neg(*self) }
}nonzero_integer! {
3017    Self = NonZeroI32,
3018    Primitive = signed i32,
3019    UnsignedPrimitive = u32,
3020    rot = 8,
3021    rot_op = "0x10000b3",
3022    rot_result = "0xb301",
3023    swap_op = "0x12345678",
3024    swapped = "0x78563412",
3025    reversed = "0x1e6a2c48",
3026}
3027
3028#[doc = "An [`i64`] that is known not to equal zero."]
///
/// This enables some memory layout optimization.
#[doc = "For example, `Option<NonZeroI64>` is the same size as `i64`:"]
///
/// ```rust
#[doc =
"assert_eq!(size_of::<Option<core::num::NonZeroI64>>(), size_of::<i64>());"]
/// ```
///
/// # Layout
///
#[doc =
"`NonZeroI64` is guaranteed to have the same layout and bit validity as `i64`"]
/// with the exception that `0` is not a valid instance.
#[doc = "`Option<NonZeroI64>` is guaranteed to be ABI-compatible with `i64`,"]
/// including in FFI.
///
/// Thanks to the [null pointer optimization],
#[doc = "`NonZeroI64` and `Option<NonZeroI64>`"]
/// are guaranteed to have the same size and alignment:
///
/// ```
#[doc = "use std::num::NonZeroI64;"]
///
#[doc =
"assert_eq!(size_of::<NonZeroI64>(), size_of::<Option<NonZeroI64>>());"]
#[doc =
"assert_eq!(align_of::<NonZeroI64>(), align_of::<Option<NonZeroI64>>());"]
/// ```
///
/// # Compile-time creation
///
/// Since both [`Option::unwrap()`] and [`Option::expect()`] are `const`, it is possible to
/// define a new
#[doc = "`NonZeroI64`"]
/// at compile time via:
/// ```
#[doc = "use std::num::NonZeroI64;"]
///
#[doc =
"const TEN: NonZeroI64 = NonZeroI64::new(10).expect(\"ten is non-zero\");"]
/// ```
///
/// [null pointer optimization]: crate::option#representation
#[stable(feature = "signed_nonzero", since = "1.34.0")]
pub type NonZeroI64 = NonZero<i64>;
impl NonZero<i64> {
    /// The size of this non-zero integer type in bits.
    ///
    #[doc = "This value is equal to [`i64::BITS`]."]
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    #[doc = "assert_eq!(NonZero::<i64>::BITS, i64::BITS);"]
    /// ```
    #[stable(feature = "nonzero_bits", since = "1.67.0")]
    pub const BITS: u32 = <i64>::BITS;
    /// Returns the number of leading zeros in the binary representation of `self`.
    ///
    /// On many architectures, this function can perform better than `leading_zeros()` on the underlying integer type, as special handling of zero can be avoided.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::<i64>::new(-1i64)?;"]
    ///
    /// assert_eq!(n.leading_zeros(), 0);
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_leading_trailing_zeros", since = "1.53.0")]
    #[rustc_const_stable(feature = "nonzero_leading_trailing_zeros", since =
    "1.53.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const fn leading_zeros(self) -> u32 {
        unsafe { intrinsics::ctlz_nonzero(self.get() as u64) }
    }
    /// Returns the number of trailing zeros in the binary representation
    /// of `self`.
    ///
    /// On many architectures, this function can perform better than `trailing_zeros()` on the underlying integer type, as special handling of zero can be avoided.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::<i64>::new(0b0101000)?;"]
    ///
    /// assert_eq!(n.trailing_zeros(), 3);
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_leading_trailing_zeros", since = "1.53.0")]
    #[rustc_const_stable(feature = "nonzero_leading_trailing_zeros", since =
    "1.53.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const fn trailing_zeros(self) -> u32 {
        unsafe { intrinsics::cttz_nonzero(self.get() as u64) }
    }
    /// Returns `self` with only the most significant bit set.
    ///
    /// # Example
    ///
    /// ```
    /// # use core::num::NonZero;
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let a = NonZero::<i64>::new(0b_01100100)?;"]
    #[doc = "let b = NonZero::<i64>::new(0b_01000000)?;"]
    ///
    /// assert_eq!(a.isolate_highest_one(), b);
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "isolate_most_least_significant_one", since =
    "1.97.0")]
    #[rustc_const_stable(feature = "isolate_most_least_significant_one", since
    = "1.97.0")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn isolate_highest_one(self) -> Self {
        unsafe {
            let bit =
                (((1 as u64) <<
                                (<u64>::BITS - 1)).unchecked_shr(self.leading_zeros()));
            NonZero::new_unchecked(bit as i64)
        }
    }
    /// Returns `self` with only the least significant bit set.
    ///
    /// # Example
    ///
    /// ```
    /// # use core::num::NonZero;
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let a = NonZero::<i64>::new(0b_01100100)?;"]
    #[doc = "let b = NonZero::<i64>::new(0b_00000100)?;"]
    ///
    /// assert_eq!(a.isolate_lowest_one(), b);
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "isolate_most_least_significant_one", since =
    "1.97.0")]
    #[rustc_const_stable(feature = "isolate_most_least_significant_one", since
    = "1.97.0")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn isolate_lowest_one(self) -> Self {
        let n = self.get();
        let n = n & n.wrapping_neg();
        unsafe { NonZero::new_unchecked(n) }
    }
    /// Returns the index of the highest bit set to one in `self`.
    ///
    #[doc = ""]
    ///
    /// # Examples
    ///
    /// ```
    /// # use core::num::NonZero;
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "assert_eq!(NonZero::<i64>::new(0b1)?.highest_one(), 0);"]
    #[doc = "assert_eq!(NonZero::<i64>::new(0b1_0000)?.highest_one(), 4);"]
    #[doc = "assert_eq!(NonZero::<i64>::new(0b1_1111)?.highest_one(), 4);"]
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "int_lowest_highest_one", since = "1.97.0")]
    #[rustc_const_stable(feature = "int_lowest_highest_one", since =
    "1.97.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline(always)]
    pub const fn highest_one(self) -> u32 {
        Self::BITS - 1 - self.leading_zeros()
    }
    /// Returns the index of the lowest bit set to one in `self`.
    ///
    /// # Examples
    ///
    /// ```
    /// # use core::num::NonZero;
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "assert_eq!(NonZero::<i64>::new(0b1)?.lowest_one(), 0);"]
    #[doc = "assert_eq!(NonZero::<i64>::new(0b1_0000)?.lowest_one(), 4);"]
    #[doc = "assert_eq!(NonZero::<i64>::new(0b1_1111)?.lowest_one(), 0);"]
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "int_lowest_highest_one", since = "1.97.0")]
    #[rustc_const_stable(feature = "int_lowest_highest_one", since =
    "1.97.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline(always)]
    pub const fn lowest_one(self) -> u32 { self.trailing_zeros() }
    /// Returns the number of ones in the binary representation of `self`.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let a = NonZero::<i64>::new(0b100_0000)?;"]
    #[doc = "let b = NonZero::<i64>::new(0b100_0011)?;"]
    ///
    /// assert_eq!(a.count_ones(), NonZero::new(1)?);
    /// assert_eq!(b.count_ones(), NonZero::new(3)?);
    /// # Some(())
    /// # }
    /// ```
    ///
    #[stable(feature = "non_zero_count_ones", since = "1.86.0")]
    #[rustc_const_stable(feature = "non_zero_count_ones", since = "1.86.0")]
    #[doc(alias = "popcount")]
    #[doc(alias = "popcnt")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn count_ones(self) -> NonZero<u32> {
        unsafe { NonZero::new_unchecked(self.get().count_ones()) }
    }
    /// Shifts the bits to the left by a specified amount, `n`,
    /// wrapping the truncated bits to the end of the resulting integer.
    ///
    /// Please note this isn't the same operation as the `<<` shifting operator!
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0xaa00000000006e1i64)?;"]
    #[doc = "let m = NonZero::new(0x6e10aa)?;"]
    ///
    #[doc = "assert_eq!(n.rotate_left(12), m);"]
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn rotate_left(self, n: u32) -> Self {
        let result = self.get().rotate_left(n);
        unsafe { Self::new_unchecked(result) }
    }
    /// Shifts the bits to the right by a specified amount, `n`,
    /// wrapping the truncated bits to the beginning of the resulting
    /// integer.
    ///
    /// Please note this isn't the same operation as the `>>` shifting operator!
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x6e10aai64)?;"]
    #[doc = "let m = NonZero::new(0xaa00000000006e1)?;"]
    ///
    #[doc = "assert_eq!(n.rotate_right(12), m);"]
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn rotate_right(self, n: u32) -> Self {
        let result = self.get().rotate_right(n);
        unsafe { Self::new_unchecked(result) }
    }
    /// Reverses the byte order of the integer.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x1234567890123456i64)?;"]
    /// let m = n.swap_bytes();
    ///
    #[doc = "assert_eq!(m, NonZero::new(0x5634129078563412)?);"]
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn swap_bytes(self) -> Self {
        let result = self.get().swap_bytes();
        unsafe { Self::new_unchecked(result) }
    }
    /// Reverses the order of bits in the integer. The least significant bit becomes the most significant bit,
    /// second least-significant bit becomes second most-significant bit, etc.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x1234567890123456i64)?;"]
    /// let m = n.reverse_bits();
    ///
    #[doc = "assert_eq!(m, NonZero::new(0x6a2c48091e6a2c48)?);"]
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn reverse_bits(self) -> Self {
        let result = self.get().reverse_bits();
        unsafe { Self::new_unchecked(result) }
    }
    /// Converts an integer from big endian to the target's endianness.
    ///
    /// On big endian this is a no-op. On little endian the bytes are
    /// swapped.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    #[doc = "use std::num::NonZeroI64;"]
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x1Ai64)?;"]
    ///
    /// if cfg!(target_endian = "big") {
    #[doc = "    assert_eq!(NonZeroI64::from_be(n), n)"]
    /// } else {
    #[doc = "    assert_eq!(NonZeroI64::from_be(n), n.swap_bytes())"]
    /// }
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use]
    #[inline(always)]
    pub const fn from_be(x: Self) -> Self {
        let result = i64::from_be(x.get());
        unsafe { Self::new_unchecked(result) }
    }
    /// Converts an integer from little endian to the target's endianness.
    ///
    /// On little endian this is a no-op. On big endian the bytes are
    /// swapped.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    #[doc = "use std::num::NonZeroI64;"]
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x1Ai64)?;"]
    ///
    /// if cfg!(target_endian = "little") {
    #[doc = "    assert_eq!(NonZeroI64::from_le(n), n)"]
    /// } else {
    #[doc = "    assert_eq!(NonZeroI64::from_le(n), n.swap_bytes())"]
    /// }
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use]
    #[inline(always)]
    pub const fn from_le(x: Self) -> Self {
        let result = i64::from_le(x.get());
        unsafe { Self::new_unchecked(result) }
    }
    /// Converts `self` to big endian from the target's endianness.
    ///
    /// On big endian this is a no-op. On little endian the bytes are
    /// swapped.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x1Ai64)?;"]
    ///
    /// if cfg!(target_endian = "big") {
    ///     assert_eq!(n.to_be(), n)
    /// } else {
    ///     assert_eq!(n.to_be(), n.swap_bytes())
    /// }
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn to_be(self) -> Self {
        let result = self.get().to_be();
        unsafe { Self::new_unchecked(result) }
    }
    /// Converts `self` to little endian from the target's endianness.
    ///
    /// On little endian this is a no-op. On big endian the bytes are
    /// swapped.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x1Ai64)?;"]
    ///
    /// if cfg!(target_endian = "little") {
    ///     assert_eq!(n.to_le(), n)
    /// } else {
    ///     assert_eq!(n.to_le(), n.swap_bytes())
    /// }
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn to_le(self) -> Self {
        let result = self.get().to_le();
        unsafe { Self::new_unchecked(result) }
    }
    /// The smallest value that can be represented by this non-zero
    /// integer type,
    #[doc = "equal to [`i64::MIN`]."]
    ///
    /// Note: While most integer types are defined for every whole
    /// number between `MIN` and `MAX`, signed non-zero integers are
    /// a special case. They have a "gap" at 0.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    #[doc = "assert_eq!(NonZero::<i64>::MIN.get(), i64::MIN);"]
    /// ```
    #[stable(feature = "nonzero_min_max", since = "1.70.0")]
    pub const MIN: Self = Self::new(<i64>::MIN).unwrap();
    /// The largest value that can be represented by this non-zero
    /// integer type,
    #[doc = "equal to [`i64::MAX`]."]
    ///
    /// Note: While most integer types are defined for every whole
    /// number between `MIN` and `MAX`, signed non-zero integers are
    /// a special case. They have a "gap" at 0.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    #[doc = "assert_eq!(NonZero::<i64>::MAX.get(), i64::MAX);"]
    /// ```
    #[stable(feature = "nonzero_min_max", since = "1.70.0")]
    pub const MAX: Self = Self::new(<i64>::MAX).unwrap();
    /// Computes the absolute value of self.
    #[doc = "See [`i64::abs`]"]
    /// for documentation on overflow behavior.
    ///
    /// # Example
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let pos = NonZero::new(1i64)?;"]
    #[doc = "let neg = NonZero::new(-1i64)?;"]
    ///
    /// assert_eq!(pos, pos.abs());
    /// assert_eq!(pos, neg.abs());
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const fn abs(self) -> Self {
        unsafe { Self::new_unchecked(self.get().abs()) }
    }
    /// Checked absolute value.
    /// Checks for overflow and returns [`None`] if
    #[doc = "`self == NonZero::<i64>::MIN`."]
    /// The result cannot be zero.
    ///
    /// # Example
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let pos = NonZero::new(1i64)?;"]
    #[doc = "let neg = NonZero::new(-1i64)?;"]
    #[doc = "let min = NonZero::new(i64::MIN)?;"]
    ///
    /// assert_eq!(Some(pos), neg.checked_abs());
    /// assert_eq!(None, min.checked_abs());
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const fn checked_abs(self) -> Option<Self> {
        if let Some(nz) = self.get().checked_abs() {
            Some(unsafe { Self::new_unchecked(nz) })
        } else { None }
    }
    /// Computes the absolute value of self,
    /// with overflow information, see
    #[doc = "[`i64::overflowing_abs`]."]
    ///
    /// # Example
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let pos = NonZero::new(1i64)?;"]
    #[doc = "let neg = NonZero::new(-1i64)?;"]
    #[doc = "let min = NonZero::new(i64::MIN)?;"]
    ///
    /// assert_eq!((pos, false), pos.overflowing_abs());
    /// assert_eq!((pos, false), neg.overflowing_abs());
    /// assert_eq!((min, true), min.overflowing_abs());
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const fn overflowing_abs(self) -> (Self, bool) {
        let (nz, flag) = self.get().overflowing_abs();
        (unsafe { Self::new_unchecked(nz) }, flag)
    }
    /// Saturating absolute value, see
    #[doc = "[`i64::saturating_abs`]."]
    ///
    /// # Example
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let pos = NonZero::new(1i64)?;"]
    #[doc = "let neg = NonZero::new(-1i64)?;"]
    #[doc = "let min = NonZero::new(i64::MIN)?;"]
    #[doc = "let min_plus = NonZero::new(i64::MIN + 1)?;"]
    #[doc = "let max = NonZero::new(i64::MAX)?;"]
    ///
    /// assert_eq!(pos, pos.saturating_abs());
    /// assert_eq!(pos, neg.saturating_abs());
    /// assert_eq!(max, min.saturating_abs());
    /// assert_eq!(max, min_plus.saturating_abs());
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const fn saturating_abs(self) -> Self {
        unsafe { Self::new_unchecked(self.get().saturating_abs()) }
    }
    /// Wrapping absolute value, see
    #[doc = "[`i64::wrapping_abs`]."]
    ///
    /// # Example
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let pos = NonZero::new(1i64)?;"]
    #[doc = "let neg = NonZero::new(-1i64)?;"]
    #[doc = "let min = NonZero::new(i64::MIN)?;"]
    #[doc = "# let max = NonZero::new(i64::MAX)?;"]
    ///
    /// assert_eq!(pos, pos.wrapping_abs());
    /// assert_eq!(pos, neg.wrapping_abs());
    /// assert_eq!(min, min.wrapping_abs());
    /// assert_eq!(max, (-max).wrapping_abs());
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const fn wrapping_abs(self) -> Self {
        unsafe { Self::new_unchecked(self.get().wrapping_abs()) }
    }
    /// Computes the absolute value of self
    /// without any wrapping or panicking.
    ///
    /// # Example
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let u_pos = NonZero::new(1u64)?;"]
    #[doc = "let i_pos = NonZero::new(1i64)?;"]
    #[doc = "let i_neg = NonZero::new(-1i64)?;"]
    #[doc = "let i_min = NonZero::new(i64::MIN)?;"]
    #[doc = "let u_max = NonZero::new(u64::MAX / 2 + 1)?;"]
    ///
    /// assert_eq!(u_pos, i_pos.unsigned_abs());
    /// assert_eq!(u_pos, i_neg.unsigned_abs());
    /// assert_eq!(u_max, i_min.unsigned_abs());
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const fn unsigned_abs(self) -> NonZero<u64> {
        unsafe { NonZero::new_unchecked(self.get().unsigned_abs()) }
    }
    /// Returns `true` if `self` is positive and `false` if the
    /// number is negative.
    ///
    /// # Example
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let pos_five = NonZero::new(5i64)?;"]
    #[doc = "let neg_five = NonZero::new(-5i64)?;"]
    ///
    /// assert!(pos_five.is_positive());
    /// assert!(!neg_five.is_positive());
    /// # Some(())
    /// # }
    /// ```
    #[must_use]
    #[inline]
    #[stable(feature = "nonzero_negation_ops", since = "1.71.0")]
    #[rustc_const_stable(feature = "nonzero_negation_ops", since = "1.71.0")]
    pub const fn is_positive(self) -> bool { self.get().is_positive() }
    /// Returns `true` if `self` is negative and `false` if the
    /// number is positive.
    ///
    /// # Example
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let pos_five = NonZero::new(5i64)?;"]
    #[doc = "let neg_five = NonZero::new(-5i64)?;"]
    ///
    /// assert!(neg_five.is_negative());
    /// assert!(!pos_five.is_negative());
    /// # Some(())
    /// # }
    /// ```
    #[must_use]
    #[inline]
    #[stable(feature = "nonzero_negation_ops", since = "1.71.0")]
    #[rustc_const_stable(feature = "nonzero_negation_ops", since = "1.71.0")]
    pub const fn is_negative(self) -> bool { self.get().is_negative() }
    /// Checked negation. Computes `-self`,
    #[doc = "returning `None` if `self == NonZero::<i64>::MIN`."]
    ///
    /// # Example
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let pos_five = NonZero::new(5i64)?;"]
    #[doc = "let neg_five = NonZero::new(-5i64)?;"]
    #[doc = "let min = NonZero::new(i64::MIN)?;"]
    ///
    /// assert_eq!(pos_five.checked_neg(), Some(neg_five));
    /// assert_eq!(min.checked_neg(), None);
    /// # Some(())
    /// # }
    /// ```
    #[inline]
    #[stable(feature = "nonzero_negation_ops", since = "1.71.0")]
    #[rustc_const_stable(feature = "nonzero_negation_ops", since = "1.71.0")]
    pub const fn checked_neg(self) -> Option<Self> {
        if let Some(result) = self.get().checked_neg() {
            return Some(unsafe { Self::new_unchecked(result) });
        }
        None
    }
    /// Checked negation. Computes `-self`, panicking if `self == MIN`.
    ///
    /// # Panics
    ///
    /// ## Overflow behavior
    ///
    /// This function always panics on overflow, regardless of whether
    /// overflow checks are enabled.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_strict_ops)]
    ///
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let pos_six = NonZero::new(6i64)?;"]
    #[doc = "let neg_six = NonZero::new(-6i64)?;"]
    ///
    /// assert_eq!(pos_six.strict_neg(), neg_six);
    /// # Some(())
    /// # }
    /// ```
    ///
    /// The following panics because of overflow:
    ///
    /// ```should_panic
    /// #![feature(nonzero_strict_ops)]
    ///
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let min = NonZero::new(i64::MIN)?;"]
    ///
    /// let _ = min.strict_neg();
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_strict_ops", issue = "164850")]
    #[rustc_const_unstable(feature = "const_nonzero_strict_ops", issue =
    "164850")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    #[track_caller]
    pub const fn strict_neg(self) -> Self {
        unsafe { Self::new_unchecked(self.get().strict_neg()) }
    }
    /// Negates self, overflowing if this is equal to the minimum value.
    ///
    #[doc = "See [`i64::overflowing_neg`]"]
    /// for documentation on overflow behavior.
    ///
    /// # Example
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let pos_five = NonZero::new(5i64)?;"]
    #[doc = "let neg_five = NonZero::new(-5i64)?;"]
    #[doc = "let min = NonZero::new(i64::MIN)?;"]
    ///
    /// assert_eq!(pos_five.overflowing_neg(), (neg_five, false));
    /// assert_eq!(min.overflowing_neg(), (min, true));
    /// # Some(())
    /// # }
    /// ```
    #[inline]
    #[stable(feature = "nonzero_negation_ops", since = "1.71.0")]
    #[rustc_const_stable(feature = "nonzero_negation_ops", since = "1.71.0")]
    pub const fn overflowing_neg(self) -> (Self, bool) {
        let (result, overflow) = self.get().overflowing_neg();
        ((unsafe { Self::new_unchecked(result) }), overflow)
    }
    /// Saturating negation. Computes `-self`,
    #[doc = "returning [`NonZero::<i64>::MAX`]"]
    #[doc = "if `self == NonZero::<i64>::MIN`"]
    /// instead of overflowing.
    ///
    /// # Example
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let pos_five = NonZero::new(5i64)?;"]
    #[doc = "let neg_five = NonZero::new(-5i64)?;"]
    #[doc = "let min = NonZero::new(i64::MIN)?;"]
    #[doc = "let min_plus_one = NonZero::new(i64::MIN + 1)?;"]
    #[doc = "let max = NonZero::new(i64::MAX)?;"]
    ///
    /// assert_eq!(pos_five.saturating_neg(), neg_five);
    /// assert_eq!(min.saturating_neg(), max);
    /// assert_eq!(max.saturating_neg(), min_plus_one);
    /// # Some(())
    /// # }
    /// ```
    #[inline]
    #[stable(feature = "nonzero_negation_ops", since = "1.71.0")]
    #[rustc_const_stable(feature = "nonzero_negation_ops", since = "1.71.0")]
    pub const fn saturating_neg(self) -> Self {
        if let Some(result) = self.checked_neg() { return result; }
        Self::MAX
    }
    /// Wrapping (modular) negation. Computes `-self`, wrapping around at the boundary
    /// of the type.
    ///
    #[doc = "See [`i64::wrapping_neg`]"]
    /// for documentation on overflow behavior.
    ///
    /// # Example
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let pos_five = NonZero::new(5i64)?;"]
    #[doc = "let neg_five = NonZero::new(-5i64)?;"]
    #[doc = "let min = NonZero::new(i64::MIN)?;"]
    ///
    /// assert_eq!(pos_five.wrapping_neg(), neg_five);
    /// assert_eq!(min.wrapping_neg(), min);
    /// # Some(())
    /// # }
    /// ```
    #[inline]
    #[stable(feature = "nonzero_negation_ops", since = "1.71.0")]
    #[rustc_const_stable(feature = "nonzero_negation_ops", since = "1.71.0")]
    pub const fn wrapping_neg(self) -> Self {
        let result = self.get().wrapping_neg();
        unsafe { Self::new_unchecked(result) }
    }
    /// Returns the bit pattern of `self` reinterpreted as an unsigned integer of the same size.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    ///
    #[doc = "let n = NonZero::new(-1i64).unwrap();"]
    ///
    #[doc = "assert_eq!(n.cast_unsigned(), NonZero::<u64>::MAX);"]
    /// ```
    #[stable(feature = "integer_sign_cast", since = "1.87.0")]
    #[rustc_const_stable(feature = "integer_sign_cast", since = "1.87.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline(always)]
    pub const fn cast_unsigned(self) -> NonZero<u64> {
        unsafe { NonZero::new_unchecked(self.get().cast_unsigned()) }
    }
    /// Clamps this number to a symmetric range centred around zero.
    ///
    /// The method clamps the number's magnitude (absolute value) to be at most `limit`.
    ///
    /// This is functionally equivalent to `self.clamp(-limit, limit)`, but is more
    /// explicit about the intent.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(clamp_magnitude)]
    /// # use std::num::NonZero;
    /// #
    #[doc = "let limit = NonZero::<u64>::new(100).unwrap();"]
    ///
    /// assert_eq!(
    #[doc = "    NonZero::<i64>::new(120).unwrap().clamp_magnitude(limit),"]
    #[doc = "    NonZero::<i64>::new(100).unwrap(),"]
    /// );
    ///
    /// assert_eq!(
    #[doc = "    NonZero::<i64>::new(-120).unwrap().clamp_magnitude(limit),"]
    #[doc = "    NonZero::<i64>::new(-100).unwrap(),"]
    /// );
    ///
    /// assert_eq!(
    #[doc = "    NonZero::<i64>::new(80).unwrap().clamp_magnitude(limit),"]
    #[doc = "    NonZero::<i64>::new(80).unwrap(),"]
    /// );
    ///
    /// assert_eq!(
    #[doc = "    NonZero::<i64>::new(-80).unwrap().clamp_magnitude(limit),"]
    #[doc = "    NonZero::<i64>::new(-80).unwrap(),"]
    /// );
    /// ```
    #[inline]
    #[must_use =
    "method returns a new number and does not mutate the original value"]
    #[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
    #[unstable(feature = "clamp_magnitude", issue = "148519")]
    pub const fn clamp_magnitude(self, limit: NonZero<u64>) -> Self {
        unsafe {
            Self::new_unchecked(self.get().clamp_magnitude(limit.get()))
        }
    }
    /// Multiplies two non-zero integers together.
    /// Checks for overflow and returns [`None`] on overflow.
    /// As a consequence, the result cannot wrap to zero.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let two = NonZero::new(2i64)?;"]
    #[doc = "let four = NonZero::new(4i64)?;"]
    #[doc = "let max = NonZero::new(i64::MAX)?;"]
    ///
    /// assert_eq!(Some(four), two.checked_mul(two));
    /// assert_eq!(None, max.checked_mul(two));
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const fn checked_mul(self, other: Self) -> Option<Self> {
        if let Some(result) = self.get().checked_mul(other.get()) {
            Some(unsafe { Self::new_unchecked(result) })
        } else { None }
    }
    /// Multiplies two non-zero integers together, panicking if
    /// overflow occurs.
    ///
    /// # Panics
    ///
    /// ## Overflow behavior
    ///
    /// This function always panics on overflow, regardless of whether
    /// overflow checks are enabled.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_strict_ops)]
    ///
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let three = NonZero::new(3i64)?;"]
    #[doc = "let nine = NonZero::new(9i64)?;"]
    ///
    /// assert_eq!(nine, three.strict_mul(three));
    /// # Some(())
    /// # }
    /// ```
    ///
    /// The following panics because of overflow:
    ///
    /// ```should_panic
    /// #![feature(nonzero_strict_ops)]
    ///
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let two = NonZero::new(2i64)?;"]
    #[doc = "let max = NonZero::new(i64::MAX)?;"]
    ///
    /// let _ = max.strict_mul(two);
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_strict_ops", issue = "164850")]
    #[rustc_const_unstable(feature = "const_nonzero_strict_ops", issue =
    "164850")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    #[track_caller]
    pub const fn strict_mul(self, other: Self) -> Self {
        unsafe { Self::new_unchecked(self.get().strict_mul(other.get())) }
    }
    /// Multiplies two non-zero integers together.
    #[doc = "Return [`NonZero::<i64>::MAX`] on overflow."]
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let two = NonZero::new(2i64)?;"]
    #[doc = "let four = NonZero::new(4i64)?;"]
    #[doc = "let max = NonZero::new(i64::MAX)?;"]
    ///
    /// assert_eq!(four, two.saturating_mul(two));
    /// assert_eq!(max, four.saturating_mul(max));
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const fn saturating_mul(self, other: Self) -> Self {
        unsafe { Self::new_unchecked(self.get().saturating_mul(other.get())) }
    }
    /// Multiplies two non-zero integers together,
    /// assuming overflow cannot occur.
    /// Overflow is unchecked, and it is undefined behavior to overflow
    /// *even if the result would wrap to a non-zero value*.
    ///
    /// # Safety
    ///
    /// This results in undefined behavior when overflow occurs, i.e.
    /// when [`checked_mul`] would return `None`.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let two = NonZero::new(2i64)?;"]
    #[doc = "let four = NonZero::new(4i64)?;"]
    ///
    /// assert_eq!(four, unsafe { two.unchecked_mul(two) });
    /// # Some(())
    /// # }
    /// ```
    ///
    /// [`checked_mul`]: Self::checked_mul
    #[stable(feature = "nonzero_ops", since = "CURRENT_RUSTC_VERSION")]
    #[rustc_const_stable(feature = "nonzero_ops", since =
    "CURRENT_RUSTC_VERSION")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const unsafe fn unchecked_mul(self, other: Self) -> Self {
        unsafe { Self::new_unchecked(self.get().unchecked_mul(other.get())) }
    }
    /// Raises non-zero value to an integer power.
    /// Checks for overflow and returns [`None`] on overflow.
    /// As a consequence, the result cannot wrap to zero.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let three = NonZero::new(3i64)?;"]
    #[doc = "let twenty_seven = NonZero::new(27i64)?;"]
    #[doc = "let half_max = NonZero::new(i64::MAX / 2)?;"]
    ///
    /// assert_eq!(Some(twenty_seven), three.checked_pow(3));
    /// assert_eq!(None, half_max.checked_pow(3));
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const fn checked_pow(self, other: u32) -> Option<Self> {
        if let Some(result) = self.get().checked_pow(other) {
            Some(unsafe { Self::new_unchecked(result) })
        } else { None }
    }
    /// Raises a non-zero value to an integer power, panicking if
    /// overflow occurs.
    ///
    /// # Panics
    ///
    /// ## Overflow behavior
    ///
    /// This function always panics on overflow, regardless of whether
    /// overflow checks are enabled.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_strict_ops)]
    ///
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let two = NonZero::new(2i64)?;"]
    #[doc = "let sixteen = NonZero::new(16i64)?;"]
    ///
    /// assert_eq!(sixteen, two.strict_pow(4));
    /// # Some(())
    /// # }
    /// ```
    ///
    /// The following panics because of overflow:
    ///
    /// ```should_panic
    /// #![feature(nonzero_strict_ops)]
    ///
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let half_max = NonZero::new(i64::MAX / 2)?;"]
    ///
    /// let _ = half_max.strict_pow(2);
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_strict_ops", issue = "164850")]
    #[rustc_const_unstable(feature = "const_nonzero_strict_ops", issue =
    "164850")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    #[track_caller]
    pub const fn strict_pow(self, exp: u32) -> Self {
        unsafe { Self::new_unchecked(self.get().strict_pow(exp)) }
    }
    /// Raise non-zero value to an integer power.
    #[doc =
    "Return [`NonZero::<i64>::MIN`] or [`NonZero::<i64>::MAX`] on overflow."]
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let three = NonZero::new(3i64)?;"]
    #[doc = "let twenty_seven = NonZero::new(27i64)?;"]
    #[doc = "let max = NonZero::new(i64::MAX)?;"]
    ///
    /// assert_eq!(twenty_seven, three.saturating_pow(3));
    /// assert_eq!(max, max.saturating_pow(3));
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const fn saturating_pow(self, other: u32) -> Self {
        unsafe { Self::new_unchecked(self.get().saturating_pow(other)) }
    }
    /// Parses a non-zero integer from an ASCII-byte slice with decimal digits.
    ///
    /// The characters are expected to be an optional
    #[doc = " `+` or `-` "]
    /// sign followed by only digits. Leading and trailing non-digit characters (including
    /// whitespace) represent an error. Underscores (which are accepted in Rust literals)
    /// also represent an error.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc =
    "assert_eq!(NonZero::<i64>::from_ascii_bytes(b\"+10\"), Ok(NonZero::new(10)?));"]
    /// # Some(())
    /// # }
    /// ```
    ///
    /// Trailing space returns error:
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    #[doc = "assert!(NonZero::<i64>::from_ascii_bytes(b\"1 \").is_err());"]
    /// ```
    #[stable(feature = "int_from_ascii", since = "CURRENT_RUSTC_VERSION")]
    #[rustc_const_unstable(feature = "const_convert", issue = "143773")]
    #[inline]
    pub const fn from_ascii_bytes<T>(src: T) -> Result<Self, ParseIntError>
        where T: [const] AsRef<[u8]> + [const] crate::marker::Destruct {
        Self::from_ascii_bytes_radix_impl(src.as_ref(), 10)
    }
    /// Parses a non-zero integer from an ASCII-byte slice with digits in a given base.
    ///
    /// The characters are expected to be an optional
    #[doc = " `+` or `-` "]
    /// sign followed by only digits. Leading and trailing non-digit characters (including
    /// whitespace) represent an error. Underscores (which are accepted in Rust literals)
    /// also represent an error.
    ///
    /// Digits are a subset of these characters, depending on `radix`:
    ///
    /// - `0-9`
    /// - `a-z`
    /// - `A-Z`
    ///
    /// # Panics
    ///
    /// This method panics if `radix` is not in the range from 2 to 36.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc =
    "assert_eq!(NonZero::<i64>::from_ascii_bytes_radix(b\"A\", 16), Ok(NonZero::new(10)?));"]
    /// # Some(())
    /// # }
    /// ```
    ///
    /// Trailing space returns error:
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    #[doc =
    "assert!(NonZero::<i64>::from_ascii_bytes_radix(b\"1 \", 10).is_err());"]
    /// ```
    #[stable(feature = "int_from_ascii", since = "CURRENT_RUSTC_VERSION")]
    #[rustc_const_unstable(feature = "const_convert", issue = "143773")]
    #[inline]
    pub const fn from_ascii_bytes_radix<T>(src: T, radix: u32)
        -> Result<Self, ParseIntError> where T: [const] AsRef<[u8]> + [const]
        crate::marker::Destruct {
        Self::from_ascii_bytes_radix_impl(src.as_ref(), radix)
    }
    #[inline]
    const fn from_ascii_bytes_radix_impl(src: &[u8], radix: u32)
        -> Result<Self, ParseIntError> {
        let n =
            match <i64>::from_ascii_bytes_radix_impl(src, radix) {
                Ok(n) => n,
                Err(err) => return Err(err),
            };
        if let Some(n) = Self::new(n) {
            Ok(n)
        } else { Err(ParseIntError { kind: IntErrorKind::Zero }) }
    }
    /// Parses a non-zero integer from a string slice with digits in a given base.
    ///
    /// The string is expected to be an optional
    #[doc = " `+` or `-` "]
    /// sign followed by only digits. Leading and trailing non-digit characters (including
    /// whitespace) represent an error. Underscores (which are accepted in Rust literals)
    /// also represent an error.
    ///
    /// Digits are a subset of these characters, depending on `radix`:
    ///
    /// - `0-9`
    /// - `a-z`
    /// - `A-Z`
    ///
    /// # Panics
    ///
    /// This method panics if `radix` is not in the range from 2 to 36.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc =
    "assert_eq!(NonZero::<i64>::from_str_radix(\"A\", 16), Ok(NonZero::new(10)?));"]
    /// # Some(())
    /// # }
    /// ```
    ///
    /// Trailing space returns error:
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    #[doc = "assert!(NonZero::<i64>::from_str_radix(\"1 \", 10).is_err());"]
    /// ```
    #[stable(feature = "nonzero_from_str_radix", since = "1.98.0")]
    #[rustc_const_stable(feature = "nonzero_from_str_radix", since =
    "1.98.0")]
    #[inline]
    pub const fn from_str_radix(src: &str, radix: u32)
        -> Result<Self, ParseIntError> {
        Self::from_ascii_bytes_radix_impl(src.as_bytes(), radix)
    }
}
#[stable(feature = "nonzero_parse", since = "1.35.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl FromStr for NonZero<i64> {
    type Err = ParseIntError;
    /// Parses a non-zero integer from a string slice with decimal digits.
    ///
    /// The characters are expected to be an optional
    #[doc = " `+` or `-` "]
    /// sign followed by only digits. Leading and trailing non-digit characters (including
    /// whitespace) represent an error. Underscores (which are accepted in Rust literals)
    /// also represent an error.
    ///
    /// # Examples
    ///
    /// ```
    /// use std::num::NonZero;
    /// use std::str::FromStr;
    ///
    #[doc =
    "assert_eq!(NonZero::<i64>::from_str(\"+10\"), Ok(NonZero::new(10).unwrap()));"]
    /// ```
    ///
    /// Trailing space returns error:
    ///
    /// ```
    /// use std::num::NonZero;
    /// use std::str::FromStr;
    ///
    #[doc = "assert!(NonZero::<i64>::from_str(\"1 \").is_err());"]
    /// ```
    #[inline]
    fn from_str(src: &str) -> Result<Self, Self::Err> {
        Self::from_str_radix(src, 10)
    }
}
#[stable(feature = "signed_nonzero_neg", since = "1.71.0")]
#[rustc_const_unstable(feature = "const_ops", issue = "143802")]
const impl Neg for NonZero<i64> {
    type Output = Self;
    #[inline]
    fn neg(self) -> Self { unsafe { Self::new_unchecked(self.get().neg()) } }
}
#[stable(feature = "signed_nonzero_neg", since = "1.71.0")]
#[rustc_const_unstable(feature = "const_ops", issue = "143802")]
const impl Neg for &NonZero<i64> {
    type Output = <NonZero<i64> as Neg>::Output;
    #[inline]
    fn neg(self) -> <NonZero<i64> as Neg>::Output { Neg::neg(*self) }
}nonzero_integer! {
3029    Self = NonZeroI64,
3030    Primitive = signed i64,
3031    UnsignedPrimitive = u64,
3032    rot = 12,
3033    rot_op = "0xaa00000000006e1",
3034    rot_result = "0x6e10aa",
3035    swap_op = "0x1234567890123456",
3036    swapped = "0x5634129078563412",
3037    reversed = "0x6a2c48091e6a2c48",
3038}
3039
3040#[doc = "An [`i128`] that is known not to equal zero."]
///
/// This enables some memory layout optimization.
#[doc = "For example, `Option<NonZeroI128>` is the same size as `i128`:"]
///
/// ```rust
#[doc =
"assert_eq!(size_of::<Option<core::num::NonZeroI128>>(), size_of::<i128>());"]
/// ```
///
/// # Layout
///
#[doc =
"`NonZeroI128` is guaranteed to have the same layout and bit validity as `i128`"]
/// with the exception that `0` is not a valid instance.
#[doc =
"`Option<NonZeroI128>` is guaranteed to be ABI-compatible with `i128`,"]
/// including in FFI.
///
/// Thanks to the [null pointer optimization],
#[doc = "`NonZeroI128` and `Option<NonZeroI128>`"]
/// are guaranteed to have the same size and alignment:
///
/// ```
#[doc = "use std::num::NonZeroI128;"]
///
#[doc =
"assert_eq!(size_of::<NonZeroI128>(), size_of::<Option<NonZeroI128>>());"]
#[doc =
"assert_eq!(align_of::<NonZeroI128>(), align_of::<Option<NonZeroI128>>());"]
/// ```
///
/// # Compile-time creation
///
/// Since both [`Option::unwrap()`] and [`Option::expect()`] are `const`, it is possible to
/// define a new
#[doc = "`NonZeroI128`"]
/// at compile time via:
/// ```
#[doc = "use std::num::NonZeroI128;"]
///
#[doc =
"const TEN: NonZeroI128 = NonZeroI128::new(10).expect(\"ten is non-zero\");"]
/// ```
///
/// [null pointer optimization]: crate::option#representation
#[stable(feature = "signed_nonzero", since = "1.34.0")]
pub type NonZeroI128 = NonZero<i128>;
impl NonZero<i128> {
    /// The size of this non-zero integer type in bits.
    ///
    #[doc = "This value is equal to [`i128::BITS`]."]
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    #[doc = "assert_eq!(NonZero::<i128>::BITS, i128::BITS);"]
    /// ```
    #[stable(feature = "nonzero_bits", since = "1.67.0")]
    pub const BITS: u32 = <i128>::BITS;
    /// Returns the number of leading zeros in the binary representation of `self`.
    ///
    /// On many architectures, this function can perform better than `leading_zeros()` on the underlying integer type, as special handling of zero can be avoided.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::<i128>::new(-1i128)?;"]
    ///
    /// assert_eq!(n.leading_zeros(), 0);
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_leading_trailing_zeros", since = "1.53.0")]
    #[rustc_const_stable(feature = "nonzero_leading_trailing_zeros", since =
    "1.53.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const fn leading_zeros(self) -> u32 {
        unsafe { intrinsics::ctlz_nonzero(self.get() as u128) }
    }
    /// Returns the number of trailing zeros in the binary representation
    /// of `self`.
    ///
    /// On many architectures, this function can perform better than `trailing_zeros()` on the underlying integer type, as special handling of zero can be avoided.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::<i128>::new(0b0101000)?;"]
    ///
    /// assert_eq!(n.trailing_zeros(), 3);
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_leading_trailing_zeros", since = "1.53.0")]
    #[rustc_const_stable(feature = "nonzero_leading_trailing_zeros", since =
    "1.53.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const fn trailing_zeros(self) -> u32 {
        unsafe { intrinsics::cttz_nonzero(self.get() as u128) }
    }
    /// Returns `self` with only the most significant bit set.
    ///
    /// # Example
    ///
    /// ```
    /// # use core::num::NonZero;
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let a = NonZero::<i128>::new(0b_01100100)?;"]
    #[doc = "let b = NonZero::<i128>::new(0b_01000000)?;"]
    ///
    /// assert_eq!(a.isolate_highest_one(), b);
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "isolate_most_least_significant_one", since =
    "1.97.0")]
    #[rustc_const_stable(feature = "isolate_most_least_significant_one", since
    = "1.97.0")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn isolate_highest_one(self) -> Self {
        unsafe {
            let bit =
                (((1 as u128) <<
                                (<u128>::BITS - 1)).unchecked_shr(self.leading_zeros()));
            NonZero::new_unchecked(bit as i128)
        }
    }
    /// Returns `self` with only the least significant bit set.
    ///
    /// # Example
    ///
    /// ```
    /// # use core::num::NonZero;
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let a = NonZero::<i128>::new(0b_01100100)?;"]
    #[doc = "let b = NonZero::<i128>::new(0b_00000100)?;"]
    ///
    /// assert_eq!(a.isolate_lowest_one(), b);
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "isolate_most_least_significant_one", since =
    "1.97.0")]
    #[rustc_const_stable(feature = "isolate_most_least_significant_one", since
    = "1.97.0")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn isolate_lowest_one(self) -> Self {
        let n = self.get();
        let n = n & n.wrapping_neg();
        unsafe { NonZero::new_unchecked(n) }
    }
    /// Returns the index of the highest bit set to one in `self`.
    ///
    #[doc = ""]
    ///
    /// # Examples
    ///
    /// ```
    /// # use core::num::NonZero;
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "assert_eq!(NonZero::<i128>::new(0b1)?.highest_one(), 0);"]
    #[doc = "assert_eq!(NonZero::<i128>::new(0b1_0000)?.highest_one(), 4);"]
    #[doc = "assert_eq!(NonZero::<i128>::new(0b1_1111)?.highest_one(), 4);"]
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "int_lowest_highest_one", since = "1.97.0")]
    #[rustc_const_stable(feature = "int_lowest_highest_one", since =
    "1.97.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline(always)]
    pub const fn highest_one(self) -> u32 {
        Self::BITS - 1 - self.leading_zeros()
    }
    /// Returns the index of the lowest bit set to one in `self`.
    ///
    /// # Examples
    ///
    /// ```
    /// # use core::num::NonZero;
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "assert_eq!(NonZero::<i128>::new(0b1)?.lowest_one(), 0);"]
    #[doc = "assert_eq!(NonZero::<i128>::new(0b1_0000)?.lowest_one(), 4);"]
    #[doc = "assert_eq!(NonZero::<i128>::new(0b1_1111)?.lowest_one(), 0);"]
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "int_lowest_highest_one", since = "1.97.0")]
    #[rustc_const_stable(feature = "int_lowest_highest_one", since =
    "1.97.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline(always)]
    pub const fn lowest_one(self) -> u32 { self.trailing_zeros() }
    /// Returns the number of ones in the binary representation of `self`.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let a = NonZero::<i128>::new(0b100_0000)?;"]
    #[doc = "let b = NonZero::<i128>::new(0b100_0011)?;"]
    ///
    /// assert_eq!(a.count_ones(), NonZero::new(1)?);
    /// assert_eq!(b.count_ones(), NonZero::new(3)?);
    /// # Some(())
    /// # }
    /// ```
    ///
    #[stable(feature = "non_zero_count_ones", since = "1.86.0")]
    #[rustc_const_stable(feature = "non_zero_count_ones", since = "1.86.0")]
    #[doc(alias = "popcount")]
    #[doc(alias = "popcnt")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn count_ones(self) -> NonZero<u32> {
        unsafe { NonZero::new_unchecked(self.get().count_ones()) }
    }
    /// Shifts the bits to the left by a specified amount, `n`,
    /// wrapping the truncated bits to the end of the resulting integer.
    ///
    /// Please note this isn't the same operation as the `<<` shifting operator!
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x13f40000000000000000000000004f76i128)?;"]
    #[doc = "let m = NonZero::new(0x4f7613f4)?;"]
    ///
    #[doc = "assert_eq!(n.rotate_left(16), m);"]
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn rotate_left(self, n: u32) -> Self {
        let result = self.get().rotate_left(n);
        unsafe { Self::new_unchecked(result) }
    }
    /// Shifts the bits to the right by a specified amount, `n`,
    /// wrapping the truncated bits to the beginning of the resulting
    /// integer.
    ///
    /// Please note this isn't the same operation as the `>>` shifting operator!
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x4f7613f4i128)?;"]
    #[doc = "let m = NonZero::new(0x13f40000000000000000000000004f76)?;"]
    ///
    #[doc = "assert_eq!(n.rotate_right(16), m);"]
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn rotate_right(self, n: u32) -> Self {
        let result = self.get().rotate_right(n);
        unsafe { Self::new_unchecked(result) }
    }
    /// Reverses the byte order of the integer.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x12345678901234567890123456789012i128)?;"]
    /// let m = n.swap_bytes();
    ///
    #[doc =
    "assert_eq!(m, NonZero::new(0x12907856341290785634129078563412)?);"]
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn swap_bytes(self) -> Self {
        let result = self.get().swap_bytes();
        unsafe { Self::new_unchecked(result) }
    }
    /// Reverses the order of bits in the integer. The least significant bit becomes the most significant bit,
    /// second least-significant bit becomes second most-significant bit, etc.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x12345678901234567890123456789012i128)?;"]
    /// let m = n.reverse_bits();
    ///
    #[doc =
    "assert_eq!(m, NonZero::new(0x48091e6a2c48091e6a2c48091e6a2c48)?);"]
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn reverse_bits(self) -> Self {
        let result = self.get().reverse_bits();
        unsafe { Self::new_unchecked(result) }
    }
    /// Converts an integer from big endian to the target's endianness.
    ///
    /// On big endian this is a no-op. On little endian the bytes are
    /// swapped.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    #[doc = "use std::num::NonZeroI128;"]
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x1Ai128)?;"]
    ///
    /// if cfg!(target_endian = "big") {
    #[doc = "    assert_eq!(NonZeroI128::from_be(n), n)"]
    /// } else {
    #[doc = "    assert_eq!(NonZeroI128::from_be(n), n.swap_bytes())"]
    /// }
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use]
    #[inline(always)]
    pub const fn from_be(x: Self) -> Self {
        let result = i128::from_be(x.get());
        unsafe { Self::new_unchecked(result) }
    }
    /// Converts an integer from little endian to the target's endianness.
    ///
    /// On little endian this is a no-op. On big endian the bytes are
    /// swapped.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    #[doc = "use std::num::NonZeroI128;"]
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x1Ai128)?;"]
    ///
    /// if cfg!(target_endian = "little") {
    #[doc = "    assert_eq!(NonZeroI128::from_le(n), n)"]
    /// } else {
    #[doc = "    assert_eq!(NonZeroI128::from_le(n), n.swap_bytes())"]
    /// }
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use]
    #[inline(always)]
    pub const fn from_le(x: Self) -> Self {
        let result = i128::from_le(x.get());
        unsafe { Self::new_unchecked(result) }
    }
    /// Converts `self` to big endian from the target's endianness.
    ///
    /// On big endian this is a no-op. On little endian the bytes are
    /// swapped.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x1Ai128)?;"]
    ///
    /// if cfg!(target_endian = "big") {
    ///     assert_eq!(n.to_be(), n)
    /// } else {
    ///     assert_eq!(n.to_be(), n.swap_bytes())
    /// }
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn to_be(self) -> Self {
        let result = self.get().to_be();
        unsafe { Self::new_unchecked(result) }
    }
    /// Converts `self` to little endian from the target's endianness.
    ///
    /// On little endian this is a no-op. On big endian the bytes are
    /// swapped.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x1Ai128)?;"]
    ///
    /// if cfg!(target_endian = "little") {
    ///     assert_eq!(n.to_le(), n)
    /// } else {
    ///     assert_eq!(n.to_le(), n.swap_bytes())
    /// }
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn to_le(self) -> Self {
        let result = self.get().to_le();
        unsafe { Self::new_unchecked(result) }
    }
    /// The smallest value that can be represented by this non-zero
    /// integer type,
    #[doc = "equal to [`i128::MIN`]."]
    ///
    /// Note: While most integer types are defined for every whole
    /// number between `MIN` and `MAX`, signed non-zero integers are
    /// a special case. They have a "gap" at 0.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    #[doc = "assert_eq!(NonZero::<i128>::MIN.get(), i128::MIN);"]
    /// ```
    #[stable(feature = "nonzero_min_max", since = "1.70.0")]
    pub const MIN: Self = Self::new(<i128>::MIN).unwrap();
    /// The largest value that can be represented by this non-zero
    /// integer type,
    #[doc = "equal to [`i128::MAX`]."]
    ///
    /// Note: While most integer types are defined for every whole
    /// number between `MIN` and `MAX`, signed non-zero integers are
    /// a special case. They have a "gap" at 0.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    #[doc = "assert_eq!(NonZero::<i128>::MAX.get(), i128::MAX);"]
    /// ```
    #[stable(feature = "nonzero_min_max", since = "1.70.0")]
    pub const MAX: Self = Self::new(<i128>::MAX).unwrap();
    /// Computes the absolute value of self.
    #[doc = "See [`i128::abs`]"]
    /// for documentation on overflow behavior.
    ///
    /// # Example
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let pos = NonZero::new(1i128)?;"]
    #[doc = "let neg = NonZero::new(-1i128)?;"]
    ///
    /// assert_eq!(pos, pos.abs());
    /// assert_eq!(pos, neg.abs());
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const fn abs(self) -> Self {
        unsafe { Self::new_unchecked(self.get().abs()) }
    }
    /// Checked absolute value.
    /// Checks for overflow and returns [`None`] if
    #[doc = "`self == NonZero::<i128>::MIN`."]
    /// The result cannot be zero.
    ///
    /// # Example
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let pos = NonZero::new(1i128)?;"]
    #[doc = "let neg = NonZero::new(-1i128)?;"]
    #[doc = "let min = NonZero::new(i128::MIN)?;"]
    ///
    /// assert_eq!(Some(pos), neg.checked_abs());
    /// assert_eq!(None, min.checked_abs());
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const fn checked_abs(self) -> Option<Self> {
        if let Some(nz) = self.get().checked_abs() {
            Some(unsafe { Self::new_unchecked(nz) })
        } else { None }
    }
    /// Computes the absolute value of self,
    /// with overflow information, see
    #[doc = "[`i128::overflowing_abs`]."]
    ///
    /// # Example
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let pos = NonZero::new(1i128)?;"]
    #[doc = "let neg = NonZero::new(-1i128)?;"]
    #[doc = "let min = NonZero::new(i128::MIN)?;"]
    ///
    /// assert_eq!((pos, false), pos.overflowing_abs());
    /// assert_eq!((pos, false), neg.overflowing_abs());
    /// assert_eq!((min, true), min.overflowing_abs());
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const fn overflowing_abs(self) -> (Self, bool) {
        let (nz, flag) = self.get().overflowing_abs();
        (unsafe { Self::new_unchecked(nz) }, flag)
    }
    /// Saturating absolute value, see
    #[doc = "[`i128::saturating_abs`]."]
    ///
    /// # Example
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let pos = NonZero::new(1i128)?;"]
    #[doc = "let neg = NonZero::new(-1i128)?;"]
    #[doc = "let min = NonZero::new(i128::MIN)?;"]
    #[doc = "let min_plus = NonZero::new(i128::MIN + 1)?;"]
    #[doc = "let max = NonZero::new(i128::MAX)?;"]
    ///
    /// assert_eq!(pos, pos.saturating_abs());
    /// assert_eq!(pos, neg.saturating_abs());
    /// assert_eq!(max, min.saturating_abs());
    /// assert_eq!(max, min_plus.saturating_abs());
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const fn saturating_abs(self) -> Self {
        unsafe { Self::new_unchecked(self.get().saturating_abs()) }
    }
    /// Wrapping absolute value, see
    #[doc = "[`i128::wrapping_abs`]."]
    ///
    /// # Example
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let pos = NonZero::new(1i128)?;"]
    #[doc = "let neg = NonZero::new(-1i128)?;"]
    #[doc = "let min = NonZero::new(i128::MIN)?;"]
    #[doc = "# let max = NonZero::new(i128::MAX)?;"]
    ///
    /// assert_eq!(pos, pos.wrapping_abs());
    /// assert_eq!(pos, neg.wrapping_abs());
    /// assert_eq!(min, min.wrapping_abs());
    /// assert_eq!(max, (-max).wrapping_abs());
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const fn wrapping_abs(self) -> Self {
        unsafe { Self::new_unchecked(self.get().wrapping_abs()) }
    }
    /// Computes the absolute value of self
    /// without any wrapping or panicking.
    ///
    /// # Example
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let u_pos = NonZero::new(1u128)?;"]
    #[doc = "let i_pos = NonZero::new(1i128)?;"]
    #[doc = "let i_neg = NonZero::new(-1i128)?;"]
    #[doc = "let i_min = NonZero::new(i128::MIN)?;"]
    #[doc = "let u_max = NonZero::new(u128::MAX / 2 + 1)?;"]
    ///
    /// assert_eq!(u_pos, i_pos.unsigned_abs());
    /// assert_eq!(u_pos, i_neg.unsigned_abs());
    /// assert_eq!(u_max, i_min.unsigned_abs());
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const fn unsigned_abs(self) -> NonZero<u128> {
        unsafe { NonZero::new_unchecked(self.get().unsigned_abs()) }
    }
    /// Returns `true` if `self` is positive and `false` if the
    /// number is negative.
    ///
    /// # Example
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let pos_five = NonZero::new(5i128)?;"]
    #[doc = "let neg_five = NonZero::new(-5i128)?;"]
    ///
    /// assert!(pos_five.is_positive());
    /// assert!(!neg_five.is_positive());
    /// # Some(())
    /// # }
    /// ```
    #[must_use]
    #[inline]
    #[stable(feature = "nonzero_negation_ops", since = "1.71.0")]
    #[rustc_const_stable(feature = "nonzero_negation_ops", since = "1.71.0")]
    pub const fn is_positive(self) -> bool { self.get().is_positive() }
    /// Returns `true` if `self` is negative and `false` if the
    /// number is positive.
    ///
    /// # Example
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let pos_five = NonZero::new(5i128)?;"]
    #[doc = "let neg_five = NonZero::new(-5i128)?;"]
    ///
    /// assert!(neg_five.is_negative());
    /// assert!(!pos_five.is_negative());
    /// # Some(())
    /// # }
    /// ```
    #[must_use]
    #[inline]
    #[stable(feature = "nonzero_negation_ops", since = "1.71.0")]
    #[rustc_const_stable(feature = "nonzero_negation_ops", since = "1.71.0")]
    pub const fn is_negative(self) -> bool { self.get().is_negative() }
    /// Checked negation. Computes `-self`,
    #[doc = "returning `None` if `self == NonZero::<i128>::MIN`."]
    ///
    /// # Example
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let pos_five = NonZero::new(5i128)?;"]
    #[doc = "let neg_five = NonZero::new(-5i128)?;"]
    #[doc = "let min = NonZero::new(i128::MIN)?;"]
    ///
    /// assert_eq!(pos_five.checked_neg(), Some(neg_five));
    /// assert_eq!(min.checked_neg(), None);
    /// # Some(())
    /// # }
    /// ```
    #[inline]
    #[stable(feature = "nonzero_negation_ops", since = "1.71.0")]
    #[rustc_const_stable(feature = "nonzero_negation_ops", since = "1.71.0")]
    pub const fn checked_neg(self) -> Option<Self> {
        if let Some(result) = self.get().checked_neg() {
            return Some(unsafe { Self::new_unchecked(result) });
        }
        None
    }
    /// Checked negation. Computes `-self`, panicking if `self == MIN`.
    ///
    /// # Panics
    ///
    /// ## Overflow behavior
    ///
    /// This function always panics on overflow, regardless of whether
    /// overflow checks are enabled.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_strict_ops)]
    ///
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let pos_six = NonZero::new(6i128)?;"]
    #[doc = "let neg_six = NonZero::new(-6i128)?;"]
    ///
    /// assert_eq!(pos_six.strict_neg(), neg_six);
    /// # Some(())
    /// # }
    /// ```
    ///
    /// The following panics because of overflow:
    ///
    /// ```should_panic
    /// #![feature(nonzero_strict_ops)]
    ///
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let min = NonZero::new(i128::MIN)?;"]
    ///
    /// let _ = min.strict_neg();
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_strict_ops", issue = "164850")]
    #[rustc_const_unstable(feature = "const_nonzero_strict_ops", issue =
    "164850")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    #[track_caller]
    pub const fn strict_neg(self) -> Self {
        unsafe { Self::new_unchecked(self.get().strict_neg()) }
    }
    /// Negates self, overflowing if this is equal to the minimum value.
    ///
    #[doc = "See [`i128::overflowing_neg`]"]
    /// for documentation on overflow behavior.
    ///
    /// # Example
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let pos_five = NonZero::new(5i128)?;"]
    #[doc = "let neg_five = NonZero::new(-5i128)?;"]
    #[doc = "let min = NonZero::new(i128::MIN)?;"]
    ///
    /// assert_eq!(pos_five.overflowing_neg(), (neg_five, false));
    /// assert_eq!(min.overflowing_neg(), (min, true));
    /// # Some(())
    /// # }
    /// ```
    #[inline]
    #[stable(feature = "nonzero_negation_ops", since = "1.71.0")]
    #[rustc_const_stable(feature = "nonzero_negation_ops", since = "1.71.0")]
    pub const fn overflowing_neg(self) -> (Self, bool) {
        let (result, overflow) = self.get().overflowing_neg();
        ((unsafe { Self::new_unchecked(result) }), overflow)
    }
    /// Saturating negation. Computes `-self`,
    #[doc = "returning [`NonZero::<i128>::MAX`]"]
    #[doc = "if `self == NonZero::<i128>::MIN`"]
    /// instead of overflowing.
    ///
    /// # Example
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let pos_five = NonZero::new(5i128)?;"]
    #[doc = "let neg_five = NonZero::new(-5i128)?;"]
    #[doc = "let min = NonZero::new(i128::MIN)?;"]
    #[doc = "let min_plus_one = NonZero::new(i128::MIN + 1)?;"]
    #[doc = "let max = NonZero::new(i128::MAX)?;"]
    ///
    /// assert_eq!(pos_five.saturating_neg(), neg_five);
    /// assert_eq!(min.saturating_neg(), max);
    /// assert_eq!(max.saturating_neg(), min_plus_one);
    /// # Some(())
    /// # }
    /// ```
    #[inline]
    #[stable(feature = "nonzero_negation_ops", since = "1.71.0")]
    #[rustc_const_stable(feature = "nonzero_negation_ops", since = "1.71.0")]
    pub const fn saturating_neg(self) -> Self {
        if let Some(result) = self.checked_neg() { return result; }
        Self::MAX
    }
    /// Wrapping (modular) negation. Computes `-self`, wrapping around at the boundary
    /// of the type.
    ///
    #[doc = "See [`i128::wrapping_neg`]"]
    /// for documentation on overflow behavior.
    ///
    /// # Example
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let pos_five = NonZero::new(5i128)?;"]
    #[doc = "let neg_five = NonZero::new(-5i128)?;"]
    #[doc = "let min = NonZero::new(i128::MIN)?;"]
    ///
    /// assert_eq!(pos_five.wrapping_neg(), neg_five);
    /// assert_eq!(min.wrapping_neg(), min);
    /// # Some(())
    /// # }
    /// ```
    #[inline]
    #[stable(feature = "nonzero_negation_ops", since = "1.71.0")]
    #[rustc_const_stable(feature = "nonzero_negation_ops", since = "1.71.0")]
    pub const fn wrapping_neg(self) -> Self {
        let result = self.get().wrapping_neg();
        unsafe { Self::new_unchecked(result) }
    }
    /// Returns the bit pattern of `self` reinterpreted as an unsigned integer of the same size.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    ///
    #[doc = "let n = NonZero::new(-1i128).unwrap();"]
    ///
    #[doc = "assert_eq!(n.cast_unsigned(), NonZero::<u128>::MAX);"]
    /// ```
    #[stable(feature = "integer_sign_cast", since = "1.87.0")]
    #[rustc_const_stable(feature = "integer_sign_cast", since = "1.87.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline(always)]
    pub const fn cast_unsigned(self) -> NonZero<u128> {
        unsafe { NonZero::new_unchecked(self.get().cast_unsigned()) }
    }
    /// Clamps this number to a symmetric range centred around zero.
    ///
    /// The method clamps the number's magnitude (absolute value) to be at most `limit`.
    ///
    /// This is functionally equivalent to `self.clamp(-limit, limit)`, but is more
    /// explicit about the intent.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(clamp_magnitude)]
    /// # use std::num::NonZero;
    /// #
    #[doc = "let limit = NonZero::<u128>::new(100).unwrap();"]
    ///
    /// assert_eq!(
    #[doc = "    NonZero::<i128>::new(120).unwrap().clamp_magnitude(limit),"]
    #[doc = "    NonZero::<i128>::new(100).unwrap(),"]
    /// );
    ///
    /// assert_eq!(
    #[doc = "    NonZero::<i128>::new(-120).unwrap().clamp_magnitude(limit),"]
    #[doc = "    NonZero::<i128>::new(-100).unwrap(),"]
    /// );
    ///
    /// assert_eq!(
    #[doc = "    NonZero::<i128>::new(80).unwrap().clamp_magnitude(limit),"]
    #[doc = "    NonZero::<i128>::new(80).unwrap(),"]
    /// );
    ///
    /// assert_eq!(
    #[doc = "    NonZero::<i128>::new(-80).unwrap().clamp_magnitude(limit),"]
    #[doc = "    NonZero::<i128>::new(-80).unwrap(),"]
    /// );
    /// ```
    #[inline]
    #[must_use =
    "method returns a new number and does not mutate the original value"]
    #[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
    #[unstable(feature = "clamp_magnitude", issue = "148519")]
    pub const fn clamp_magnitude(self, limit: NonZero<u128>) -> Self {
        unsafe {
            Self::new_unchecked(self.get().clamp_magnitude(limit.get()))
        }
    }
    /// Multiplies two non-zero integers together.
    /// Checks for overflow and returns [`None`] on overflow.
    /// As a consequence, the result cannot wrap to zero.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let two = NonZero::new(2i128)?;"]
    #[doc = "let four = NonZero::new(4i128)?;"]
    #[doc = "let max = NonZero::new(i128::MAX)?;"]
    ///
    /// assert_eq!(Some(four), two.checked_mul(two));
    /// assert_eq!(None, max.checked_mul(two));
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const fn checked_mul(self, other: Self) -> Option<Self> {
        if let Some(result) = self.get().checked_mul(other.get()) {
            Some(unsafe { Self::new_unchecked(result) })
        } else { None }
    }
    /// Multiplies two non-zero integers together, panicking if
    /// overflow occurs.
    ///
    /// # Panics
    ///
    /// ## Overflow behavior
    ///
    /// This function always panics on overflow, regardless of whether
    /// overflow checks are enabled.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_strict_ops)]
    ///
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let three = NonZero::new(3i128)?;"]
    #[doc = "let nine = NonZero::new(9i128)?;"]
    ///
    /// assert_eq!(nine, three.strict_mul(three));
    /// # Some(())
    /// # }
    /// ```
    ///
    /// The following panics because of overflow:
    ///
    /// ```should_panic
    /// #![feature(nonzero_strict_ops)]
    ///
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let two = NonZero::new(2i128)?;"]
    #[doc = "let max = NonZero::new(i128::MAX)?;"]
    ///
    /// let _ = max.strict_mul(two);
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_strict_ops", issue = "164850")]
    #[rustc_const_unstable(feature = "const_nonzero_strict_ops", issue =
    "164850")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    #[track_caller]
    pub const fn strict_mul(self, other: Self) -> Self {
        unsafe { Self::new_unchecked(self.get().strict_mul(other.get())) }
    }
    /// Multiplies two non-zero integers together.
    #[doc = "Return [`NonZero::<i128>::MAX`] on overflow."]
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let two = NonZero::new(2i128)?;"]
    #[doc = "let four = NonZero::new(4i128)?;"]
    #[doc = "let max = NonZero::new(i128::MAX)?;"]
    ///
    /// assert_eq!(four, two.saturating_mul(two));
    /// assert_eq!(max, four.saturating_mul(max));
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const fn saturating_mul(self, other: Self) -> Self {
        unsafe { Self::new_unchecked(self.get().saturating_mul(other.get())) }
    }
    /// Multiplies two non-zero integers together,
    /// assuming overflow cannot occur.
    /// Overflow is unchecked, and it is undefined behavior to overflow
    /// *even if the result would wrap to a non-zero value*.
    ///
    /// # Safety
    ///
    /// This results in undefined behavior when overflow occurs, i.e.
    /// when [`checked_mul`] would return `None`.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let two = NonZero::new(2i128)?;"]
    #[doc = "let four = NonZero::new(4i128)?;"]
    ///
    /// assert_eq!(four, unsafe { two.unchecked_mul(two) });
    /// # Some(())
    /// # }
    /// ```
    ///
    /// [`checked_mul`]: Self::checked_mul
    #[stable(feature = "nonzero_ops", since = "CURRENT_RUSTC_VERSION")]
    #[rustc_const_stable(feature = "nonzero_ops", since =
    "CURRENT_RUSTC_VERSION")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const unsafe fn unchecked_mul(self, other: Self) -> Self {
        unsafe { Self::new_unchecked(self.get().unchecked_mul(other.get())) }
    }
    /// Raises non-zero value to an integer power.
    /// Checks for overflow and returns [`None`] on overflow.
    /// As a consequence, the result cannot wrap to zero.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let three = NonZero::new(3i128)?;"]
    #[doc = "let twenty_seven = NonZero::new(27i128)?;"]
    #[doc = "let half_max = NonZero::new(i128::MAX / 2)?;"]
    ///
    /// assert_eq!(Some(twenty_seven), three.checked_pow(3));
    /// assert_eq!(None, half_max.checked_pow(3));
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const fn checked_pow(self, other: u32) -> Option<Self> {
        if let Some(result) = self.get().checked_pow(other) {
            Some(unsafe { Self::new_unchecked(result) })
        } else { None }
    }
    /// Raises a non-zero value to an integer power, panicking if
    /// overflow occurs.
    ///
    /// # Panics
    ///
    /// ## Overflow behavior
    ///
    /// This function always panics on overflow, regardless of whether
    /// overflow checks are enabled.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_strict_ops)]
    ///
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let two = NonZero::new(2i128)?;"]
    #[doc = "let sixteen = NonZero::new(16i128)?;"]
    ///
    /// assert_eq!(sixteen, two.strict_pow(4));
    /// # Some(())
    /// # }
    /// ```
    ///
    /// The following panics because of overflow:
    ///
    /// ```should_panic
    /// #![feature(nonzero_strict_ops)]
    ///
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let half_max = NonZero::new(i128::MAX / 2)?;"]
    ///
    /// let _ = half_max.strict_pow(2);
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_strict_ops", issue = "164850")]
    #[rustc_const_unstable(feature = "const_nonzero_strict_ops", issue =
    "164850")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    #[track_caller]
    pub const fn strict_pow(self, exp: u32) -> Self {
        unsafe { Self::new_unchecked(self.get().strict_pow(exp)) }
    }
    /// Raise non-zero value to an integer power.
    #[doc =
    "Return [`NonZero::<i128>::MIN`] or [`NonZero::<i128>::MAX`] on overflow."]
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let three = NonZero::new(3i128)?;"]
    #[doc = "let twenty_seven = NonZero::new(27i128)?;"]
    #[doc = "let max = NonZero::new(i128::MAX)?;"]
    ///
    /// assert_eq!(twenty_seven, three.saturating_pow(3));
    /// assert_eq!(max, max.saturating_pow(3));
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const fn saturating_pow(self, other: u32) -> Self {
        unsafe { Self::new_unchecked(self.get().saturating_pow(other)) }
    }
    /// Parses a non-zero integer from an ASCII-byte slice with decimal digits.
    ///
    /// The characters are expected to be an optional
    #[doc = " `+` or `-` "]
    /// sign followed by only digits. Leading and trailing non-digit characters (including
    /// whitespace) represent an error. Underscores (which are accepted in Rust literals)
    /// also represent an error.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc =
    "assert_eq!(NonZero::<i128>::from_ascii_bytes(b\"+10\"), Ok(NonZero::new(10)?));"]
    /// # Some(())
    /// # }
    /// ```
    ///
    /// Trailing space returns error:
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    #[doc = "assert!(NonZero::<i128>::from_ascii_bytes(b\"1 \").is_err());"]
    /// ```
    #[stable(feature = "int_from_ascii", since = "CURRENT_RUSTC_VERSION")]
    #[rustc_const_unstable(feature = "const_convert", issue = "143773")]
    #[inline]
    pub const fn from_ascii_bytes<T>(src: T) -> Result<Self, ParseIntError>
        where T: [const] AsRef<[u8]> + [const] crate::marker::Destruct {
        Self::from_ascii_bytes_radix_impl(src.as_ref(), 10)
    }
    /// Parses a non-zero integer from an ASCII-byte slice with digits in a given base.
    ///
    /// The characters are expected to be an optional
    #[doc = " `+` or `-` "]
    /// sign followed by only digits. Leading and trailing non-digit characters (including
    /// whitespace) represent an error. Underscores (which are accepted in Rust literals)
    /// also represent an error.
    ///
    /// Digits are a subset of these characters, depending on `radix`:
    ///
    /// - `0-9`
    /// - `a-z`
    /// - `A-Z`
    ///
    /// # Panics
    ///
    /// This method panics if `radix` is not in the range from 2 to 36.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc =
    "assert_eq!(NonZero::<i128>::from_ascii_bytes_radix(b\"A\", 16), Ok(NonZero::new(10)?));"]
    /// # Some(())
    /// # }
    /// ```
    ///
    /// Trailing space returns error:
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    #[doc =
    "assert!(NonZero::<i128>::from_ascii_bytes_radix(b\"1 \", 10).is_err());"]
    /// ```
    #[stable(feature = "int_from_ascii", since = "CURRENT_RUSTC_VERSION")]
    #[rustc_const_unstable(feature = "const_convert", issue = "143773")]
    #[inline]
    pub const fn from_ascii_bytes_radix<T>(src: T, radix: u32)
        -> Result<Self, ParseIntError> where T: [const] AsRef<[u8]> + [const]
        crate::marker::Destruct {
        Self::from_ascii_bytes_radix_impl(src.as_ref(), radix)
    }
    #[inline]
    const fn from_ascii_bytes_radix_impl(src: &[u8], radix: u32)
        -> Result<Self, ParseIntError> {
        let n =
            match <i128>::from_ascii_bytes_radix_impl(src, radix) {
                Ok(n) => n,
                Err(err) => return Err(err),
            };
        if let Some(n) = Self::new(n) {
            Ok(n)
        } else { Err(ParseIntError { kind: IntErrorKind::Zero }) }
    }
    /// Parses a non-zero integer from a string slice with digits in a given base.
    ///
    /// The string is expected to be an optional
    #[doc = " `+` or `-` "]
    /// sign followed by only digits. Leading and trailing non-digit characters (including
    /// whitespace) represent an error. Underscores (which are accepted in Rust literals)
    /// also represent an error.
    ///
    /// Digits are a subset of these characters, depending on `radix`:
    ///
    /// - `0-9`
    /// - `a-z`
    /// - `A-Z`
    ///
    /// # Panics
    ///
    /// This method panics if `radix` is not in the range from 2 to 36.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc =
    "assert_eq!(NonZero::<i128>::from_str_radix(\"A\", 16), Ok(NonZero::new(10)?));"]
    /// # Some(())
    /// # }
    /// ```
    ///
    /// Trailing space returns error:
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    #[doc = "assert!(NonZero::<i128>::from_str_radix(\"1 \", 10).is_err());"]
    /// ```
    #[stable(feature = "nonzero_from_str_radix", since = "1.98.0")]
    #[rustc_const_stable(feature = "nonzero_from_str_radix", since =
    "1.98.0")]
    #[inline]
    pub const fn from_str_radix(src: &str, radix: u32)
        -> Result<Self, ParseIntError> {
        Self::from_ascii_bytes_radix_impl(src.as_bytes(), radix)
    }
}
#[stable(feature = "nonzero_parse", since = "1.35.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl FromStr for NonZero<i128> {
    type Err = ParseIntError;
    /// Parses a non-zero integer from a string slice with decimal digits.
    ///
    /// The characters are expected to be an optional
    #[doc = " `+` or `-` "]
    /// sign followed by only digits. Leading and trailing non-digit characters (including
    /// whitespace) represent an error. Underscores (which are accepted in Rust literals)
    /// also represent an error.
    ///
    /// # Examples
    ///
    /// ```
    /// use std::num::NonZero;
    /// use std::str::FromStr;
    ///
    #[doc =
    "assert_eq!(NonZero::<i128>::from_str(\"+10\"), Ok(NonZero::new(10).unwrap()));"]
    /// ```
    ///
    /// Trailing space returns error:
    ///
    /// ```
    /// use std::num::NonZero;
    /// use std::str::FromStr;
    ///
    #[doc = "assert!(NonZero::<i128>::from_str(\"1 \").is_err());"]
    /// ```
    #[inline]
    fn from_str(src: &str) -> Result<Self, Self::Err> {
        Self::from_str_radix(src, 10)
    }
}
#[stable(feature = "signed_nonzero_neg", since = "1.71.0")]
#[rustc_const_unstable(feature = "const_ops", issue = "143802")]
const impl Neg for NonZero<i128> {
    type Output = Self;
    #[inline]
    fn neg(self) -> Self { unsafe { Self::new_unchecked(self.get().neg()) } }
}
#[stable(feature = "signed_nonzero_neg", since = "1.71.0")]
#[rustc_const_unstable(feature = "const_ops", issue = "143802")]
const impl Neg for &NonZero<i128> {
    type Output = <NonZero<i128> as Neg>::Output;
    #[inline]
    fn neg(self) -> <NonZero<i128> as Neg>::Output { Neg::neg(*self) }
}nonzero_integer! {
3041    Self = NonZeroI128,
3042    Primitive = signed i128,
3043    UnsignedPrimitive = u128,
3044    rot = 16,
3045    rot_op = "0x13f40000000000000000000000004f76",
3046    rot_result = "0x4f7613f4",
3047    swap_op = "0x12345678901234567890123456789012",
3048    swapped = "0x12907856341290785634129078563412",
3049    reversed = "0x48091e6a2c48091e6a2c48091e6a2c48",
3050}
3051
3052#[cfg(target_pointer_width = "16")]
3053nonzero_integer! {
3054    Self = NonZeroIsize,
3055    Primitive = signed isize,
3056    UnsignedPrimitive = usize,
3057    rot = 4,
3058    rot_op = "-0x5ffd",
3059    rot_result = "0x3a",
3060    swap_op = "0x1234",
3061    swapped = "0x3412",
3062    reversed = "0x2c48",
3063}
3064
3065#[cfg(target_pointer_width = "32")]
3066nonzero_integer! {
3067    Self = NonZeroIsize,
3068    Primitive = signed isize,
3069    UnsignedPrimitive = usize,
3070    rot = 8,
3071    rot_op = "0x10000b3",
3072    rot_result = "0xb301",
3073    swap_op = "0x12345678",
3074    swapped = "0x78563412",
3075    reversed = "0x1e6a2c48",
3076}
3077
3078#[cfg(target_pointer_width = "64")]
3079#[doc = "An [`isize`] that is known not to equal zero."]
///
/// This enables some memory layout optimization.
#[doc = "For example, `Option<NonZeroIsize>` is the same size as `isize`:"]
///
/// ```rust
#[doc =
"assert_eq!(size_of::<Option<core::num::NonZeroIsize>>(), size_of::<isize>());"]
/// ```
///
/// # Layout
///
#[doc =
"`NonZeroIsize` is guaranteed to have the same layout and bit validity as `isize`"]
/// with the exception that `0` is not a valid instance.
#[doc =
"`Option<NonZeroIsize>` is guaranteed to be ABI-compatible with `isize`,"]
/// including in FFI.
///
/// Thanks to the [null pointer optimization],
#[doc = "`NonZeroIsize` and `Option<NonZeroIsize>`"]
/// are guaranteed to have the same size and alignment:
///
/// ```
#[doc = "use std::num::NonZeroIsize;"]
///
#[doc =
"assert_eq!(size_of::<NonZeroIsize>(), size_of::<Option<NonZeroIsize>>());"]
#[doc =
"assert_eq!(align_of::<NonZeroIsize>(), align_of::<Option<NonZeroIsize>>());"]
/// ```
///
/// # Compile-time creation
///
/// Since both [`Option::unwrap()`] and [`Option::expect()`] are `const`, it is possible to
/// define a new
#[doc = "`NonZeroIsize`"]
/// at compile time via:
/// ```
#[doc = "use std::num::NonZeroIsize;"]
///
#[doc =
"const TEN: NonZeroIsize = NonZeroIsize::new(10).expect(\"ten is non-zero\");"]
/// ```
///
/// [null pointer optimization]: crate::option#representation
#[stable(feature = "signed_nonzero", since = "1.34.0")]
pub type NonZeroIsize = NonZero<isize>;
impl NonZero<isize> {
    /// The size of this non-zero integer type in bits.
    ///
    #[doc = "This value is equal to [`isize::BITS`]."]
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    #[doc = "assert_eq!(NonZero::<isize>::BITS, isize::BITS);"]
    /// ```
    #[stable(feature = "nonzero_bits", since = "1.67.0")]
    pub const BITS: u32 = <isize>::BITS;
    /// Returns the number of leading zeros in the binary representation of `self`.
    ///
    /// On many architectures, this function can perform better than `leading_zeros()` on the underlying integer type, as special handling of zero can be avoided.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::<isize>::new(-1isize)?;"]
    ///
    /// assert_eq!(n.leading_zeros(), 0);
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_leading_trailing_zeros", since = "1.53.0")]
    #[rustc_const_stable(feature = "nonzero_leading_trailing_zeros", since =
    "1.53.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const fn leading_zeros(self) -> u32 {
        unsafe { intrinsics::ctlz_nonzero(self.get() as usize) }
    }
    /// Returns the number of trailing zeros in the binary representation
    /// of `self`.
    ///
    /// On many architectures, this function can perform better than `trailing_zeros()` on the underlying integer type, as special handling of zero can be avoided.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::<isize>::new(0b0101000)?;"]
    ///
    /// assert_eq!(n.trailing_zeros(), 3);
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_leading_trailing_zeros", since = "1.53.0")]
    #[rustc_const_stable(feature = "nonzero_leading_trailing_zeros", since =
    "1.53.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const fn trailing_zeros(self) -> u32 {
        unsafe { intrinsics::cttz_nonzero(self.get() as usize) }
    }
    /// Returns `self` with only the most significant bit set.
    ///
    /// # Example
    ///
    /// ```
    /// # use core::num::NonZero;
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let a = NonZero::<isize>::new(0b_01100100)?;"]
    #[doc = "let b = NonZero::<isize>::new(0b_01000000)?;"]
    ///
    /// assert_eq!(a.isolate_highest_one(), b);
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "isolate_most_least_significant_one", since =
    "1.97.0")]
    #[rustc_const_stable(feature = "isolate_most_least_significant_one", since
    = "1.97.0")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn isolate_highest_one(self) -> Self {
        unsafe {
            let bit =
                (((1 as usize) <<
                                (<usize>::BITS - 1)).unchecked_shr(self.leading_zeros()));
            NonZero::new_unchecked(bit as isize)
        }
    }
    /// Returns `self` with only the least significant bit set.
    ///
    /// # Example
    ///
    /// ```
    /// # use core::num::NonZero;
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let a = NonZero::<isize>::new(0b_01100100)?;"]
    #[doc = "let b = NonZero::<isize>::new(0b_00000100)?;"]
    ///
    /// assert_eq!(a.isolate_lowest_one(), b);
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "isolate_most_least_significant_one", since =
    "1.97.0")]
    #[rustc_const_stable(feature = "isolate_most_least_significant_one", since
    = "1.97.0")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn isolate_lowest_one(self) -> Self {
        let n = self.get();
        let n = n & n.wrapping_neg();
        unsafe { NonZero::new_unchecked(n) }
    }
    /// Returns the index of the highest bit set to one in `self`.
    ///
    #[doc = ""]
    ///
    /// # Examples
    ///
    /// ```
    /// # use core::num::NonZero;
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "assert_eq!(NonZero::<isize>::new(0b1)?.highest_one(), 0);"]
    #[doc = "assert_eq!(NonZero::<isize>::new(0b1_0000)?.highest_one(), 4);"]
    #[doc = "assert_eq!(NonZero::<isize>::new(0b1_1111)?.highest_one(), 4);"]
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "int_lowest_highest_one", since = "1.97.0")]
    #[rustc_const_stable(feature = "int_lowest_highest_one", since =
    "1.97.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline(always)]
    pub const fn highest_one(self) -> u32 {
        Self::BITS - 1 - self.leading_zeros()
    }
    /// Returns the index of the lowest bit set to one in `self`.
    ///
    /// # Examples
    ///
    /// ```
    /// # use core::num::NonZero;
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "assert_eq!(NonZero::<isize>::new(0b1)?.lowest_one(), 0);"]
    #[doc = "assert_eq!(NonZero::<isize>::new(0b1_0000)?.lowest_one(), 4);"]
    #[doc = "assert_eq!(NonZero::<isize>::new(0b1_1111)?.lowest_one(), 0);"]
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "int_lowest_highest_one", since = "1.97.0")]
    #[rustc_const_stable(feature = "int_lowest_highest_one", since =
    "1.97.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline(always)]
    pub const fn lowest_one(self) -> u32 { self.trailing_zeros() }
    /// Returns the number of ones in the binary representation of `self`.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let a = NonZero::<isize>::new(0b100_0000)?;"]
    #[doc = "let b = NonZero::<isize>::new(0b100_0011)?;"]
    ///
    /// assert_eq!(a.count_ones(), NonZero::new(1)?);
    /// assert_eq!(b.count_ones(), NonZero::new(3)?);
    /// # Some(())
    /// # }
    /// ```
    ///
    #[stable(feature = "non_zero_count_ones", since = "1.86.0")]
    #[rustc_const_stable(feature = "non_zero_count_ones", since = "1.86.0")]
    #[doc(alias = "popcount")]
    #[doc(alias = "popcnt")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn count_ones(self) -> NonZero<u32> {
        unsafe { NonZero::new_unchecked(self.get().count_ones()) }
    }
    /// Shifts the bits to the left by a specified amount, `n`,
    /// wrapping the truncated bits to the end of the resulting integer.
    ///
    /// Please note this isn't the same operation as the `<<` shifting operator!
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0xaa00000000006e1isize)?;"]
    #[doc = "let m = NonZero::new(0x6e10aa)?;"]
    ///
    #[doc = "assert_eq!(n.rotate_left(12), m);"]
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn rotate_left(self, n: u32) -> Self {
        let result = self.get().rotate_left(n);
        unsafe { Self::new_unchecked(result) }
    }
    /// Shifts the bits to the right by a specified amount, `n`,
    /// wrapping the truncated bits to the beginning of the resulting
    /// integer.
    ///
    /// Please note this isn't the same operation as the `>>` shifting operator!
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x6e10aaisize)?;"]
    #[doc = "let m = NonZero::new(0xaa00000000006e1)?;"]
    ///
    #[doc = "assert_eq!(n.rotate_right(12), m);"]
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn rotate_right(self, n: u32) -> Self {
        let result = self.get().rotate_right(n);
        unsafe { Self::new_unchecked(result) }
    }
    /// Reverses the byte order of the integer.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x1234567890123456isize)?;"]
    /// let m = n.swap_bytes();
    ///
    #[doc = "assert_eq!(m, NonZero::new(0x5634129078563412)?);"]
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn swap_bytes(self) -> Self {
        let result = self.get().swap_bytes();
        unsafe { Self::new_unchecked(result) }
    }
    /// Reverses the order of bits in the integer. The least significant bit becomes the most significant bit,
    /// second least-significant bit becomes second most-significant bit, etc.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x1234567890123456isize)?;"]
    /// let m = n.reverse_bits();
    ///
    #[doc = "assert_eq!(m, NonZero::new(0x6a2c48091e6a2c48)?);"]
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn reverse_bits(self) -> Self {
        let result = self.get().reverse_bits();
        unsafe { Self::new_unchecked(result) }
    }
    /// Converts an integer from big endian to the target's endianness.
    ///
    /// On big endian this is a no-op. On little endian the bytes are
    /// swapped.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    #[doc = "use std::num::NonZeroIsize;"]
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x1Aisize)?;"]
    ///
    /// if cfg!(target_endian = "big") {
    #[doc = "    assert_eq!(NonZeroIsize::from_be(n), n)"]
    /// } else {
    #[doc = "    assert_eq!(NonZeroIsize::from_be(n), n.swap_bytes())"]
    /// }
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use]
    #[inline(always)]
    pub const fn from_be(x: Self) -> Self {
        let result = isize::from_be(x.get());
        unsafe { Self::new_unchecked(result) }
    }
    /// Converts an integer from little endian to the target's endianness.
    ///
    /// On little endian this is a no-op. On big endian the bytes are
    /// swapped.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    #[doc = "use std::num::NonZeroIsize;"]
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x1Aisize)?;"]
    ///
    /// if cfg!(target_endian = "little") {
    #[doc = "    assert_eq!(NonZeroIsize::from_le(n), n)"]
    /// } else {
    #[doc = "    assert_eq!(NonZeroIsize::from_le(n), n.swap_bytes())"]
    /// }
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use]
    #[inline(always)]
    pub const fn from_le(x: Self) -> Self {
        let result = isize::from_le(x.get());
        unsafe { Self::new_unchecked(result) }
    }
    /// Converts `self` to big endian from the target's endianness.
    ///
    /// On big endian this is a no-op. On little endian the bytes are
    /// swapped.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x1Aisize)?;"]
    ///
    /// if cfg!(target_endian = "big") {
    ///     assert_eq!(n.to_be(), n)
    /// } else {
    ///     assert_eq!(n.to_be(), n.swap_bytes())
    /// }
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn to_be(self) -> Self {
        let result = self.get().to_be();
        unsafe { Self::new_unchecked(result) }
    }
    /// Converts `self` to little endian from the target's endianness.
    ///
    /// On little endian this is a no-op. On big endian the bytes are
    /// swapped.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_bitwise)]
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let n = NonZero::new(0x1Aisize)?;"]
    ///
    /// if cfg!(target_endian = "little") {
    ///     assert_eq!(n.to_le(), n)
    /// } else {
    ///     assert_eq!(n.to_le(), n.swap_bytes())
    /// }
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_bitwise", issue = "128281")]
    #[must_use =
    "this returns the result of the operation, \
                        without modifying the original"]
    #[inline(always)]
    pub const fn to_le(self) -> Self {
        let result = self.get().to_le();
        unsafe { Self::new_unchecked(result) }
    }
    /// The smallest value that can be represented by this non-zero
    /// integer type,
    #[doc = "equal to [`isize::MIN`]."]
    ///
    /// Note: While most integer types are defined for every whole
    /// number between `MIN` and `MAX`, signed non-zero integers are
    /// a special case. They have a "gap" at 0.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    #[doc = "assert_eq!(NonZero::<isize>::MIN.get(), isize::MIN);"]
    /// ```
    #[stable(feature = "nonzero_min_max", since = "1.70.0")]
    pub const MIN: Self = Self::new(<isize>::MIN).unwrap();
    /// The largest value that can be represented by this non-zero
    /// integer type,
    #[doc = "equal to [`isize::MAX`]."]
    ///
    /// Note: While most integer types are defined for every whole
    /// number between `MIN` and `MAX`, signed non-zero integers are
    /// a special case. They have a "gap" at 0.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    #[doc = "assert_eq!(NonZero::<isize>::MAX.get(), isize::MAX);"]
    /// ```
    #[stable(feature = "nonzero_min_max", since = "1.70.0")]
    pub const MAX: Self = Self::new(<isize>::MAX).unwrap();
    /// Computes the absolute value of self.
    #[doc = "See [`isize::abs`]"]
    /// for documentation on overflow behavior.
    ///
    /// # Example
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let pos = NonZero::new(1isize)?;"]
    #[doc = "let neg = NonZero::new(-1isize)?;"]
    ///
    /// assert_eq!(pos, pos.abs());
    /// assert_eq!(pos, neg.abs());
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const fn abs(self) -> Self {
        unsafe { Self::new_unchecked(self.get().abs()) }
    }
    /// Checked absolute value.
    /// Checks for overflow and returns [`None`] if
    #[doc = "`self == NonZero::<isize>::MIN`."]
    /// The result cannot be zero.
    ///
    /// # Example
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let pos = NonZero::new(1isize)?;"]
    #[doc = "let neg = NonZero::new(-1isize)?;"]
    #[doc = "let min = NonZero::new(isize::MIN)?;"]
    ///
    /// assert_eq!(Some(pos), neg.checked_abs());
    /// assert_eq!(None, min.checked_abs());
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const fn checked_abs(self) -> Option<Self> {
        if let Some(nz) = self.get().checked_abs() {
            Some(unsafe { Self::new_unchecked(nz) })
        } else { None }
    }
    /// Computes the absolute value of self,
    /// with overflow information, see
    #[doc = "[`isize::overflowing_abs`]."]
    ///
    /// # Example
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let pos = NonZero::new(1isize)?;"]
    #[doc = "let neg = NonZero::new(-1isize)?;"]
    #[doc = "let min = NonZero::new(isize::MIN)?;"]
    ///
    /// assert_eq!((pos, false), pos.overflowing_abs());
    /// assert_eq!((pos, false), neg.overflowing_abs());
    /// assert_eq!((min, true), min.overflowing_abs());
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const fn overflowing_abs(self) -> (Self, bool) {
        let (nz, flag) = self.get().overflowing_abs();
        (unsafe { Self::new_unchecked(nz) }, flag)
    }
    /// Saturating absolute value, see
    #[doc = "[`isize::saturating_abs`]."]
    ///
    /// # Example
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let pos = NonZero::new(1isize)?;"]
    #[doc = "let neg = NonZero::new(-1isize)?;"]
    #[doc = "let min = NonZero::new(isize::MIN)?;"]
    #[doc = "let min_plus = NonZero::new(isize::MIN + 1)?;"]
    #[doc = "let max = NonZero::new(isize::MAX)?;"]
    ///
    /// assert_eq!(pos, pos.saturating_abs());
    /// assert_eq!(pos, neg.saturating_abs());
    /// assert_eq!(max, min.saturating_abs());
    /// assert_eq!(max, min_plus.saturating_abs());
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const fn saturating_abs(self) -> Self {
        unsafe { Self::new_unchecked(self.get().saturating_abs()) }
    }
    /// Wrapping absolute value, see
    #[doc = "[`isize::wrapping_abs`]."]
    ///
    /// # Example
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let pos = NonZero::new(1isize)?;"]
    #[doc = "let neg = NonZero::new(-1isize)?;"]
    #[doc = "let min = NonZero::new(isize::MIN)?;"]
    #[doc = "# let max = NonZero::new(isize::MAX)?;"]
    ///
    /// assert_eq!(pos, pos.wrapping_abs());
    /// assert_eq!(pos, neg.wrapping_abs());
    /// assert_eq!(min, min.wrapping_abs());
    /// assert_eq!(max, (-max).wrapping_abs());
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const fn wrapping_abs(self) -> Self {
        unsafe { Self::new_unchecked(self.get().wrapping_abs()) }
    }
    /// Computes the absolute value of self
    /// without any wrapping or panicking.
    ///
    /// # Example
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let u_pos = NonZero::new(1usize)?;"]
    #[doc = "let i_pos = NonZero::new(1isize)?;"]
    #[doc = "let i_neg = NonZero::new(-1isize)?;"]
    #[doc = "let i_min = NonZero::new(isize::MIN)?;"]
    #[doc = "let u_max = NonZero::new(usize::MAX / 2 + 1)?;"]
    ///
    /// assert_eq!(u_pos, i_pos.unsigned_abs());
    /// assert_eq!(u_pos, i_neg.unsigned_abs());
    /// assert_eq!(u_max, i_min.unsigned_abs());
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    pub const fn unsigned_abs(self) -> NonZero<usize> {
        unsafe { NonZero::new_unchecked(self.get().unsigned_abs()) }
    }
    /// Returns `true` if `self` is positive and `false` if the
    /// number is negative.
    ///
    /// # Example
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let pos_five = NonZero::new(5isize)?;"]
    #[doc = "let neg_five = NonZero::new(-5isize)?;"]
    ///
    /// assert!(pos_five.is_positive());
    /// assert!(!neg_five.is_positive());
    /// # Some(())
    /// # }
    /// ```
    #[must_use]
    #[inline]
    #[stable(feature = "nonzero_negation_ops", since = "1.71.0")]
    #[rustc_const_stable(feature = "nonzero_negation_ops", since = "1.71.0")]
    pub const fn is_positive(self) -> bool { self.get().is_positive() }
    /// Returns `true` if `self` is negative and `false` if the
    /// number is positive.
    ///
    /// # Example
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let pos_five = NonZero::new(5isize)?;"]
    #[doc = "let neg_five = NonZero::new(-5isize)?;"]
    ///
    /// assert!(neg_five.is_negative());
    /// assert!(!pos_five.is_negative());
    /// # Some(())
    /// # }
    /// ```
    #[must_use]
    #[inline]
    #[stable(feature = "nonzero_negation_ops", since = "1.71.0")]
    #[rustc_const_stable(feature = "nonzero_negation_ops", since = "1.71.0")]
    pub const fn is_negative(self) -> bool { self.get().is_negative() }
    /// Checked negation. Computes `-self`,
    #[doc = "returning `None` if `self == NonZero::<isize>::MIN`."]
    ///
    /// # Example
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let pos_five = NonZero::new(5isize)?;"]
    #[doc = "let neg_five = NonZero::new(-5isize)?;"]
    #[doc = "let min = NonZero::new(isize::MIN)?;"]
    ///
    /// assert_eq!(pos_five.checked_neg(), Some(neg_five));
    /// assert_eq!(min.checked_neg(), None);
    /// # Some(())
    /// # }
    /// ```
    #[inline]
    #[stable(feature = "nonzero_negation_ops", since = "1.71.0")]
    #[rustc_const_stable(feature = "nonzero_negation_ops", since = "1.71.0")]
    pub const fn checked_neg(self) -> Option<Self> {
        if let Some(result) = self.get().checked_neg() {
            return Some(unsafe { Self::new_unchecked(result) });
        }
        None
    }
    /// Checked negation. Computes `-self`, panicking if `self == MIN`.
    ///
    /// # Panics
    ///
    /// ## Overflow behavior
    ///
    /// This function always panics on overflow, regardless of whether
    /// overflow checks are enabled.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_strict_ops)]
    ///
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let pos_six = NonZero::new(6isize)?;"]
    #[doc = "let neg_six = NonZero::new(-6isize)?;"]
    ///
    /// assert_eq!(pos_six.strict_neg(), neg_six);
    /// # Some(())
    /// # }
    /// ```
    ///
    /// The following panics because of overflow:
    ///
    /// ```should_panic
    /// #![feature(nonzero_strict_ops)]
    ///
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let min = NonZero::new(isize::MIN)?;"]
    ///
    /// let _ = min.strict_neg();
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_strict_ops", issue = "164850")]
    #[rustc_const_unstable(feature = "const_nonzero_strict_ops", issue =
    "164850")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline]
    #[track_caller]
    pub const fn strict_neg(self) -> Self {
        unsafe { Self::new_unchecked(self.get().strict_neg()) }
    }
    /// Negates self, overflowing if this is equal to the minimum value.
    ///
    #[doc = "See [`isize::overflowing_neg`]"]
    /// for documentation on overflow behavior.
    ///
    /// # Example
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let pos_five = NonZero::new(5isize)?;"]
    #[doc = "let neg_five = NonZero::new(-5isize)?;"]
    #[doc = "let min = NonZero::new(isize::MIN)?;"]
    ///
    /// assert_eq!(pos_five.overflowing_neg(), (neg_five, false));
    /// assert_eq!(min.overflowing_neg(), (min, true));
    /// # Some(())
    /// # }
    /// ```
    #[inline]
    #[stable(feature = "nonzero_negation_ops", since = "1.71.0")]
    #[rustc_const_stable(feature = "nonzero_negation_ops", since = "1.71.0")]
    pub const fn overflowing_neg(self) -> (Self, bool) {
        let (result, overflow) = self.get().overflowing_neg();
        ((unsafe { Self::new_unchecked(result) }), overflow)
    }
    /// Saturating negation. Computes `-self`,
    #[doc = "returning [`NonZero::<isize>::MAX`]"]
    #[doc = "if `self == NonZero::<isize>::MIN`"]
    /// instead of overflowing.
    ///
    /// # Example
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let pos_five = NonZero::new(5isize)?;"]
    #[doc = "let neg_five = NonZero::new(-5isize)?;"]
    #[doc = "let min = NonZero::new(isize::MIN)?;"]
    #[doc = "let min_plus_one = NonZero::new(isize::MIN + 1)?;"]
    #[doc = "let max = NonZero::new(isize::MAX)?;"]
    ///
    /// assert_eq!(pos_five.saturating_neg(), neg_five);
    /// assert_eq!(min.saturating_neg(), max);
    /// assert_eq!(max.saturating_neg(), min_plus_one);
    /// # Some(())
    /// # }
    /// ```
    #[inline]
    #[stable(feature = "nonzero_negation_ops", since = "1.71.0")]
    #[rustc_const_stable(feature = "nonzero_negation_ops", since = "1.71.0")]
    pub const fn saturating_neg(self) -> Self {
        if let Some(result) = self.checked_neg() { return result; }
        Self::MAX
    }
    /// Wrapping (modular) negation. Computes `-self`, wrapping around at the boundary
    /// of the type.
    ///
    #[doc = "See [`isize::wrapping_neg`]"]
    /// for documentation on overflow behavior.
    ///
    /// # Example
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let pos_five = NonZero::new(5isize)?;"]
    #[doc = "let neg_five = NonZero::new(-5isize)?;"]
    #[doc = "let min = NonZero::new(isize::MIN)?;"]
    ///
    /// assert_eq!(pos_five.wrapping_neg(), neg_five);
    /// assert_eq!(min.wrapping_neg(), min);
    /// # Some(())
    /// # }
    /// ```
    #[inline]
    #[stable(feature = "nonzero_negation_ops", since = "1.71.0")]
    #[rustc_const_stable(feature = "nonzero_negation_ops", since = "1.71.0")]
    pub const fn wrapping_neg(self) -> Self {
        let result = self.get().wrapping_neg();
        unsafe { Self::new_unchecked(result) }
    }
    /// Returns the bit pattern of `self` reinterpreted as an unsigned integer of the same size.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    ///
    #[doc = "let n = NonZero::new(-1isize).unwrap();"]
    ///
    #[doc = "assert_eq!(n.cast_unsigned(), NonZero::<usize>::MAX);"]
    /// ```
    #[stable(feature = "integer_sign_cast", since = "1.87.0")]
    #[rustc_const_stable(feature = "integer_sign_cast", since = "1.87.0")]
    #[must_use =
    "this returns the result of the operation, \
                      without modifying the original"]
    #[inline(always)]
    pub const fn cast_unsigned(self) -> NonZero<usize> {
        unsafe { NonZero::new_unchecked(self.get().cast_unsigned()) }
    }
    /// Clamps this number to a symmetric range centred around zero.
    ///
    /// The method clamps the number's magnitude (absolute value) to be at most `limit`.
    ///
    /// This is functionally equivalent to `self.clamp(-limit, limit)`, but is more
    /// explicit about the intent.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(clamp_magnitude)]
    /// # use std::num::NonZero;
    /// #
    #[doc = "let limit = NonZero::<usize>::new(100).unwrap();"]
    ///
    /// assert_eq!(
    #[doc = "    NonZero::<isize>::new(120).unwrap().clamp_magnitude(limit),"]
    #[doc = "    NonZero::<isize>::new(100).unwrap(),"]
    /// );
    ///
    /// assert_eq!(
    #[doc =
    "    NonZero::<isize>::new(-120).unwrap().clamp_magnitude(limit),"]
    #[doc = "    NonZero::<isize>::new(-100).unwrap(),"]
    /// );
    ///
    /// assert_eq!(
    #[doc = "    NonZero::<isize>::new(80).unwrap().clamp_magnitude(limit),"]
    #[doc = "    NonZero::<isize>::new(80).unwrap(),"]
    /// );
    ///
    /// assert_eq!(
    #[doc = "    NonZero::<isize>::new(-80).unwrap().clamp_magnitude(limit),"]
    #[doc = "    NonZero::<isize>::new(-80).unwrap(),"]
    /// );
    /// ```
    #[inline]
    #[must_use =
    "method returns a new number and does not mutate the original value"]
    #[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
    #[unstable(feature = "clamp_magnitude", issue = "148519")]
    pub const fn clamp_magnitude(self, limit: NonZero<usize>) -> Self {
        unsafe {
            Self::new_unchecked(self.get().clamp_magnitude(limit.get()))
        }
    }
    /// Multiplies two non-zero integers together.
    /// Checks for overflow and returns [`None`] on overflow.
    /// As a consequence, the result cannot wrap to zero.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let two = NonZero::new(2isize)?;"]
    #[doc = "let four = NonZero::new(4isize)?;"]
    #[doc = "let max = NonZero::new(isize::MAX)?;"]
    ///
    /// assert_eq!(Some(four), two.checked_mul(two));
    /// assert_eq!(None, max.checked_mul(two));
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const fn checked_mul(self, other: Self) -> Option<Self> {
        if let Some(result) = self.get().checked_mul(other.get()) {
            Some(unsafe { Self::new_unchecked(result) })
        } else { None }
    }
    /// Multiplies two non-zero integers together, panicking if
    /// overflow occurs.
    ///
    /// # Panics
    ///
    /// ## Overflow behavior
    ///
    /// This function always panics on overflow, regardless of whether
    /// overflow checks are enabled.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_strict_ops)]
    ///
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let three = NonZero::new(3isize)?;"]
    #[doc = "let nine = NonZero::new(9isize)?;"]
    ///
    /// assert_eq!(nine, three.strict_mul(three));
    /// # Some(())
    /// # }
    /// ```
    ///
    /// The following panics because of overflow:
    ///
    /// ```should_panic
    /// #![feature(nonzero_strict_ops)]
    ///
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let two = NonZero::new(2isize)?;"]
    #[doc = "let max = NonZero::new(isize::MAX)?;"]
    ///
    /// let _ = max.strict_mul(two);
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_strict_ops", issue = "164850")]
    #[rustc_const_unstable(feature = "const_nonzero_strict_ops", issue =
    "164850")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    #[track_caller]
    pub const fn strict_mul(self, other: Self) -> Self {
        unsafe { Self::new_unchecked(self.get().strict_mul(other.get())) }
    }
    /// Multiplies two non-zero integers together.
    #[doc = "Return [`NonZero::<isize>::MAX`] on overflow."]
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let two = NonZero::new(2isize)?;"]
    #[doc = "let four = NonZero::new(4isize)?;"]
    #[doc = "let max = NonZero::new(isize::MAX)?;"]
    ///
    /// assert_eq!(four, two.saturating_mul(two));
    /// assert_eq!(max, four.saturating_mul(max));
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const fn saturating_mul(self, other: Self) -> Self {
        unsafe { Self::new_unchecked(self.get().saturating_mul(other.get())) }
    }
    /// Multiplies two non-zero integers together,
    /// assuming overflow cannot occur.
    /// Overflow is unchecked, and it is undefined behavior to overflow
    /// *even if the result would wrap to a non-zero value*.
    ///
    /// # Safety
    ///
    /// This results in undefined behavior when overflow occurs, i.e.
    /// when [`checked_mul`] would return `None`.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let two = NonZero::new(2isize)?;"]
    #[doc = "let four = NonZero::new(4isize)?;"]
    ///
    /// assert_eq!(four, unsafe { two.unchecked_mul(two) });
    /// # Some(())
    /// # }
    /// ```
    ///
    /// [`checked_mul`]: Self::checked_mul
    #[stable(feature = "nonzero_ops", since = "CURRENT_RUSTC_VERSION")]
    #[rustc_const_stable(feature = "nonzero_ops", since =
    "CURRENT_RUSTC_VERSION")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const unsafe fn unchecked_mul(self, other: Self) -> Self {
        unsafe { Self::new_unchecked(self.get().unchecked_mul(other.get())) }
    }
    /// Raises non-zero value to an integer power.
    /// Checks for overflow and returns [`None`] on overflow.
    /// As a consequence, the result cannot wrap to zero.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let three = NonZero::new(3isize)?;"]
    #[doc = "let twenty_seven = NonZero::new(27isize)?;"]
    #[doc = "let half_max = NonZero::new(isize::MAX / 2)?;"]
    ///
    /// assert_eq!(Some(twenty_seven), three.checked_pow(3));
    /// assert_eq!(None, half_max.checked_pow(3));
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const fn checked_pow(self, other: u32) -> Option<Self> {
        if let Some(result) = self.get().checked_pow(other) {
            Some(unsafe { Self::new_unchecked(result) })
        } else { None }
    }
    /// Raises a non-zero value to an integer power, panicking if
    /// overflow occurs.
    ///
    /// # Panics
    ///
    /// ## Overflow behavior
    ///
    /// This function always panics on overflow, regardless of whether
    /// overflow checks are enabled.
    ///
    /// # Examples
    ///
    /// ```
    /// #![feature(nonzero_strict_ops)]
    ///
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let two = NonZero::new(2isize)?;"]
    #[doc = "let sixteen = NonZero::new(16isize)?;"]
    ///
    /// assert_eq!(sixteen, two.strict_pow(4));
    /// # Some(())
    /// # }
    /// ```
    ///
    /// The following panics because of overflow:
    ///
    /// ```should_panic
    /// #![feature(nonzero_strict_ops)]
    ///
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let half_max = NonZero::new(isize::MAX / 2)?;"]
    ///
    /// let _ = half_max.strict_pow(2);
    /// # Some(())
    /// # }
    /// ```
    #[unstable(feature = "nonzero_strict_ops", issue = "164850")]
    #[rustc_const_unstable(feature = "const_nonzero_strict_ops", issue =
    "164850")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    #[track_caller]
    pub const fn strict_pow(self, exp: u32) -> Self {
        unsafe { Self::new_unchecked(self.get().strict_pow(exp)) }
    }
    /// Raise non-zero value to an integer power.
    #[doc =
    "Return [`NonZero::<isize>::MIN`] or [`NonZero::<isize>::MAX`] on overflow."]
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc = "let three = NonZero::new(3isize)?;"]
    #[doc = "let twenty_seven = NonZero::new(27isize)?;"]
    #[doc = "let max = NonZero::new(isize::MAX)?;"]
    ///
    /// assert_eq!(twenty_seven, three.saturating_pow(3));
    /// assert_eq!(max, max.saturating_pow(3));
    /// # Some(())
    /// # }
    /// ```
    #[stable(feature = "nonzero_checked_ops", since = "1.64.0")]
    #[rustc_const_stable(feature = "const_nonzero_checked_ops", since =
    "1.64.0")]
    #[must_use =
    "this returns the result of the operation, \
                          without modifying the original"]
    #[inline]
    pub const fn saturating_pow(self, other: u32) -> Self {
        unsafe { Self::new_unchecked(self.get().saturating_pow(other)) }
    }
    /// Parses a non-zero integer from an ASCII-byte slice with decimal digits.
    ///
    /// The characters are expected to be an optional
    #[doc = " `+` or `-` "]
    /// sign followed by only digits. Leading and trailing non-digit characters (including
    /// whitespace) represent an error. Underscores (which are accepted in Rust literals)
    /// also represent an error.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc =
    "assert_eq!(NonZero::<isize>::from_ascii_bytes(b\"+10\"), Ok(NonZero::new(10)?));"]
    /// # Some(())
    /// # }
    /// ```
    ///
    /// Trailing space returns error:
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    #[doc = "assert!(NonZero::<isize>::from_ascii_bytes(b\"1 \").is_err());"]
    /// ```
    #[stable(feature = "int_from_ascii", since = "CURRENT_RUSTC_VERSION")]
    #[rustc_const_unstable(feature = "const_convert", issue = "143773")]
    #[inline]
    pub const fn from_ascii_bytes<T>(src: T) -> Result<Self, ParseIntError>
        where T: [const] AsRef<[u8]> + [const] crate::marker::Destruct {
        Self::from_ascii_bytes_radix_impl(src.as_ref(), 10)
    }
    /// Parses a non-zero integer from an ASCII-byte slice with digits in a given base.
    ///
    /// The characters are expected to be an optional
    #[doc = " `+` or `-` "]
    /// sign followed by only digits. Leading and trailing non-digit characters (including
    /// whitespace) represent an error. Underscores (which are accepted in Rust literals)
    /// also represent an error.
    ///
    /// Digits are a subset of these characters, depending on `radix`:
    ///
    /// - `0-9`
    /// - `a-z`
    /// - `A-Z`
    ///
    /// # Panics
    ///
    /// This method panics if `radix` is not in the range from 2 to 36.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc =
    "assert_eq!(NonZero::<isize>::from_ascii_bytes_radix(b\"A\", 16), Ok(NonZero::new(10)?));"]
    /// # Some(())
    /// # }
    /// ```
    ///
    /// Trailing space returns error:
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    #[doc =
    "assert!(NonZero::<isize>::from_ascii_bytes_radix(b\"1 \", 10).is_err());"]
    /// ```
    #[stable(feature = "int_from_ascii", since = "CURRENT_RUSTC_VERSION")]
    #[rustc_const_unstable(feature = "const_convert", issue = "143773")]
    #[inline]
    pub const fn from_ascii_bytes_radix<T>(src: T, radix: u32)
        -> Result<Self, ParseIntError> where T: [const] AsRef<[u8]> + [const]
        crate::marker::Destruct {
        Self::from_ascii_bytes_radix_impl(src.as_ref(), radix)
    }
    #[inline]
    const fn from_ascii_bytes_radix_impl(src: &[u8], radix: u32)
        -> Result<Self, ParseIntError> {
        let n =
            match <isize>::from_ascii_bytes_radix_impl(src, radix) {
                Ok(n) => n,
                Err(err) => return Err(err),
            };
        if let Some(n) = Self::new(n) {
            Ok(n)
        } else { Err(ParseIntError { kind: IntErrorKind::Zero }) }
    }
    /// Parses a non-zero integer from a string slice with digits in a given base.
    ///
    /// The string is expected to be an optional
    #[doc = " `+` or `-` "]
    /// sign followed by only digits. Leading and trailing non-digit characters (including
    /// whitespace) represent an error. Underscores (which are accepted in Rust literals)
    /// also represent an error.
    ///
    /// Digits are a subset of these characters, depending on `radix`:
    ///
    /// - `0-9`
    /// - `a-z`
    /// - `A-Z`
    ///
    /// # Panics
    ///
    /// This method panics if `radix` is not in the range from 2 to 36.
    ///
    /// # Examples
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    /// # fn main() { test().unwrap(); }
    /// # fn test() -> Option<()> {
    #[doc =
    "assert_eq!(NonZero::<isize>::from_str_radix(\"A\", 16), Ok(NonZero::new(10)?));"]
    /// # Some(())
    /// # }
    /// ```
    ///
    /// Trailing space returns error:
    ///
    /// ```
    /// # use std::num::NonZero;
    /// #
    #[doc = "assert!(NonZero::<isize>::from_str_radix(\"1 \", 10).is_err());"]
    /// ```
    #[stable(feature = "nonzero_from_str_radix", since = "1.98.0")]
    #[rustc_const_stable(feature = "nonzero_from_str_radix", since =
    "1.98.0")]
    #[inline]
    pub const fn from_str_radix(src: &str, radix: u32)
        -> Result<Self, ParseIntError> {
        Self::from_ascii_bytes_radix_impl(src.as_bytes(), radix)
    }
}
#[stable(feature = "nonzero_parse", since = "1.35.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl FromStr for NonZero<isize> {
    type Err = ParseIntError;
    /// Parses a non-zero integer from a string slice with decimal digits.
    ///
    /// The characters are expected to be an optional
    #[doc = " `+` or `-` "]
    /// sign followed by only digits. Leading and trailing non-digit characters (including
    /// whitespace) represent an error. Underscores (which are accepted in Rust literals)
    /// also represent an error.
    ///
    /// # Examples
    ///
    /// ```
    /// use std::num::NonZero;
    /// use std::str::FromStr;
    ///
    #[doc =
    "assert_eq!(NonZero::<isize>::from_str(\"+10\"), Ok(NonZero::new(10).unwrap()));"]
    /// ```
    ///
    /// Trailing space returns error:
    ///
    /// ```
    /// use std::num::NonZero;
    /// use std::str::FromStr;
    ///
    #[doc = "assert!(NonZero::<isize>::from_str(\"1 \").is_err());"]
    /// ```
    #[inline]
    fn from_str(src: &str) -> Result<Self, Self::Err> {
        Self::from_str_radix(src, 10)
    }
}
#[stable(feature = "signed_nonzero_neg", since = "1.71.0")]
#[rustc_const_unstable(feature = "const_ops", issue = "143802")]
const impl Neg for NonZero<isize> {
    type Output = Self;
    #[inline]
    fn neg(self) -> Self { unsafe { Self::new_unchecked(self.get().neg()) } }
}
#[stable(feature = "signed_nonzero_neg", since = "1.71.0")]
#[rustc_const_unstable(feature = "const_ops", issue = "143802")]
const impl Neg for &NonZero<isize> {
    type Output = <NonZero<isize> as Neg>::Output;
    #[inline]
    fn neg(self) -> <NonZero<isize> as Neg>::Output { Neg::neg(*self) }
}nonzero_integer! {
3080    Self = NonZeroIsize,
3081    Primitive = signed isize,
3082    UnsignedPrimitive = usize,
3083    rot = 12,
3084    rot_op = "0xaa00000000006e1",
3085    rot_result = "0x6e10aa",
3086    swap_op = "0x1234567890123456",
3087    swapped = "0x5634129078563412",
3088    reversed = "0x6a2c48091e6a2c48",
3089}