1use core::fmt::NumBuffer;
2use core::num::{NonZero, ParseIntError, TryFromIntError};
3
4use crate::{PrimitiveError, PrimitiveNumber, PrimitiveNumberRef};
5
6trait Sealed {}
7
8pub trait PrimitiveInteger:
43 PrimitiveNumber
44 + core::cmp::Eq
45 + core::cmp::Ord
46 + core::convert::From<Self::NonZero>
47 + core::convert::TryFrom<i8, Error: PrimitiveError>
48 + core::convert::TryFrom<i16, Error: PrimitiveError>
49 + core::convert::TryFrom<i32, Error: PrimitiveError>
50 + core::convert::TryFrom<i64, Error: PrimitiveError>
51 + core::convert::TryFrom<i128, Error: PrimitiveError>
52 + core::convert::TryFrom<isize, Error: PrimitiveError>
53 + core::convert::TryFrom<u8, Error: PrimitiveError>
54 + core::convert::TryFrom<u16, Error: PrimitiveError>
55 + core::convert::TryFrom<u32, Error: PrimitiveError>
56 + core::convert::TryFrom<u64, Error: PrimitiveError>
57 + core::convert::TryFrom<u128, Error: PrimitiveError>
58 + core::convert::TryFrom<usize, Error: PrimitiveError>
59 + core::convert::TryInto<Self::NonZero, Error = TryFromIntError>
60 + core::convert::TryInto<i8, Error: PrimitiveError>
61 + core::convert::TryInto<i16, Error: PrimitiveError>
62 + core::convert::TryInto<i32, Error: PrimitiveError>
63 + core::convert::TryInto<i64, Error: PrimitiveError>
64 + core::convert::TryInto<i128, Error: PrimitiveError>
65 + core::convert::TryInto<isize, Error: PrimitiveError>
66 + core::convert::TryInto<u8, Error: PrimitiveError>
67 + core::convert::TryInto<u16, Error: PrimitiveError>
68 + core::convert::TryInto<u32, Error: PrimitiveError>
69 + core::convert::TryInto<u64, Error: PrimitiveError>
70 + core::convert::TryInto<u128, Error: PrimitiveError>
71 + core::convert::TryInto<usize, Error: PrimitiveError>
72 + core::fmt::Binary
73 + core::fmt::LowerHex
74 + core::fmt::Octal
75 + core::fmt::UpperHex
76 + core::hash::Hash
77 + core::ops::BitAnd<Self, Output = Self>
78 + core::ops::BitAndAssign<Self>
79 + core::ops::BitOr<Self, Output = Self>
80 + core::ops::BitOr<Self::NonZero, Output = Self::NonZero>
81 + core::ops::BitOrAssign<Self>
82 + core::ops::BitXor<Self, Output = Self>
83 + core::ops::BitXorAssign<Self>
84 + core::ops::Not<Output = Self>
85 + core::ops::Shl<Self, Output = Self>
86 + core::ops::Shl<i8, Output = Self>
87 + core::ops::Shl<i16, Output = Self>
88 + core::ops::Shl<i32, Output = Self>
89 + core::ops::Shl<i64, Output = Self>
90 + core::ops::Shl<i128, Output = Self>
91 + core::ops::Shl<isize, Output = Self>
92 + core::ops::Shl<u8, Output = Self>
93 + core::ops::Shl<u16, Output = Self>
94 + core::ops::Shl<u32, Output = Self>
95 + core::ops::Shl<u64, Output = Self>
96 + core::ops::Shl<u128, Output = Self>
97 + core::ops::Shl<usize, Output = Self>
98 + core::ops::ShlAssign<Self>
99 + core::ops::ShlAssign<i8>
100 + core::ops::ShlAssign<i16>
101 + core::ops::ShlAssign<i32>
102 + core::ops::ShlAssign<i64>
103 + core::ops::ShlAssign<i128>
104 + core::ops::ShlAssign<isize>
105 + core::ops::ShlAssign<u8>
106 + core::ops::ShlAssign<u16>
107 + core::ops::ShlAssign<u32>
108 + core::ops::ShlAssign<u64>
109 + core::ops::ShlAssign<u128>
110 + core::ops::ShlAssign<usize>
111 + core::ops::Shr<Self, Output = Self>
112 + core::ops::Shr<i8, Output = Self>
113 + core::ops::Shr<i16, Output = Self>
114 + core::ops::Shr<i32, Output = Self>
115 + core::ops::Shr<i64, Output = Self>
116 + core::ops::Shr<i128, Output = Self>
117 + core::ops::Shr<isize, Output = Self>
118 + core::ops::Shr<u8, Output = Self>
119 + core::ops::Shr<u16, Output = Self>
120 + core::ops::Shr<u32, Output = Self>
121 + core::ops::Shr<u64, Output = Self>
122 + core::ops::Shr<u128, Output = Self>
123 + core::ops::Shr<usize, Output = Self>
124 + core::ops::ShrAssign<Self>
125 + core::ops::ShrAssign<i8>
126 + core::ops::ShrAssign<i16>
127 + core::ops::ShrAssign<i32>
128 + core::ops::ShrAssign<i64>
129 + core::ops::ShrAssign<i128>
130 + core::ops::ShrAssign<isize>
131 + core::ops::ShrAssign<u8>
132 + core::ops::ShrAssign<u16>
133 + core::ops::ShrAssign<u32>
134 + core::ops::ShrAssign<u64>
135 + core::ops::ShrAssign<u128>
136 + core::ops::ShrAssign<usize>
137 + core::str::FromStr<Err = ParseIntError>
138 + for<'a> core::ops::BitAnd<&'a Self, Output = Self>
139 + for<'a> core::ops::BitAndAssign<&'a Self>
140 + for<'a> core::ops::BitOr<&'a Self, Output = Self>
141 + for<'a> core::ops::BitOrAssign<&'a Self>
142 + for<'a> core::ops::BitXor<&'a Self, Output = Self>
143 + for<'a> core::ops::BitXorAssign<&'a Self>
144 + for<'a> core::ops::Shl<&'a Self, Output = Self>
145 + for<'a> core::ops::Shl<&'a i8, Output = Self>
146 + for<'a> core::ops::Shl<&'a i16, Output = Self>
147 + for<'a> core::ops::Shl<&'a i32, Output = Self>
148 + for<'a> core::ops::Shl<&'a i64, Output = Self>
149 + for<'a> core::ops::Shl<&'a i128, Output = Self>
150 + for<'a> core::ops::Shl<&'a isize, Output = Self>
151 + for<'a> core::ops::Shl<&'a u8, Output = Self>
152 + for<'a> core::ops::Shl<&'a u16, Output = Self>
153 + for<'a> core::ops::Shl<&'a u32, Output = Self>
154 + for<'a> core::ops::Shl<&'a u64, Output = Self>
155 + for<'a> core::ops::Shl<&'a u128, Output = Self>
156 + for<'a> core::ops::Shl<&'a usize, Output = Self>
157 + for<'a> core::ops::ShlAssign<&'a Self>
158 + for<'a> core::ops::ShlAssign<&'a i8>
159 + for<'a> core::ops::ShlAssign<&'a i16>
160 + for<'a> core::ops::ShlAssign<&'a i32>
161 + for<'a> core::ops::ShlAssign<&'a i64>
162 + for<'a> core::ops::ShlAssign<&'a i128>
163 + for<'a> core::ops::ShlAssign<&'a isize>
164 + for<'a> core::ops::ShlAssign<&'a u8>
165 + for<'a> core::ops::ShlAssign<&'a u16>
166 + for<'a> core::ops::ShlAssign<&'a u32>
167 + for<'a> core::ops::ShlAssign<&'a u64>
168 + for<'a> core::ops::ShlAssign<&'a u128>
169 + for<'a> core::ops::ShlAssign<&'a usize>
170 + for<'a> core::ops::Shr<&'a Self, Output = Self>
171 + for<'a> core::ops::Shr<&'a i8, Output = Self>
172 + for<'a> core::ops::Shr<&'a i16, Output = Self>
173 + for<'a> core::ops::Shr<&'a i32, Output = Self>
174 + for<'a> core::ops::Shr<&'a i64, Output = Self>
175 + for<'a> core::ops::Shr<&'a i128, Output = Self>
176 + for<'a> core::ops::Shr<&'a isize, Output = Self>
177 + for<'a> core::ops::Shr<&'a u8, Output = Self>
178 + for<'a> core::ops::Shr<&'a u16, Output = Self>
179 + for<'a> core::ops::Shr<&'a u32, Output = Self>
180 + for<'a> core::ops::Shr<&'a u64, Output = Self>
181 + for<'a> core::ops::Shr<&'a u128, Output = Self>
182 + for<'a> core::ops::Shr<&'a usize, Output = Self>
183 + for<'a> core::ops::ShrAssign<&'a Self>
184 + for<'a> core::ops::ShrAssign<&'a i8>
185 + for<'a> core::ops::ShrAssign<&'a i16>
186 + for<'a> core::ops::ShrAssign<&'a i32>
187 + for<'a> core::ops::ShrAssign<&'a i64>
188 + for<'a> core::ops::ShrAssign<&'a i128>
189 + for<'a> core::ops::ShrAssign<&'a isize>
190 + for<'a> core::ops::ShrAssign<&'a u8>
191 + for<'a> core::ops::ShrAssign<&'a u16>
192 + for<'a> core::ops::ShrAssign<&'a u32>
193 + for<'a> core::ops::ShrAssign<&'a u64>
194 + for<'a> core::ops::ShrAssign<&'a u128>
195 + for<'a> core::ops::ShrAssign<&'a usize>
196{
197 type NonZero: NonZeroPrimitiveInteger<Integer = Self>;
201
202 type NumBuffer: PrimitiveNumBuffer;
206
207 const BITS: u32;
209
210 const MAX: Self;
212
213 const MIN: Self;
215
216 fn checked_add(self, rhs: Self) -> Option<Self>;
218
219 fn checked_div(self, rhs: Self) -> Option<Self>;
222
223 fn checked_div_euclid(self, rhs: Self) -> Option<Self>;
226
227 fn checked_ilog(self, base: Self) -> Option<u32>;
230
231 fn checked_ilog10(self) -> Option<u32>;
234
235 fn checked_ilog2(self) -> Option<u32>;
238
239 fn checked_mul(self, rhs: Self) -> Option<Self>;
242
243 fn checked_neg(self) -> Option<Self>;
246
247 fn checked_pow(self, exp: u32) -> Option<Self>;
249
250 fn checked_rem(self, rhs: Self) -> Option<Self>;
253
254 fn checked_rem_euclid(self, rhs: Self) -> Option<Self>;
257
258 fn checked_shl(self, rhs: u32) -> Option<Self>;
261
262 fn checked_shr(self, rhs: u32) -> Option<Self>;
265
266 fn checked_sub(self, rhs: Self) -> Option<Self>;
268
269 fn count_ones(self) -> u32;
271
272 fn count_zeros(self) -> u32;
274
275 fn div_euclid(self, rhs: Self) -> Self;
279
280 fn format_into(self, buf: &mut Self::NumBuffer) -> &str;
282
283 fn from_be(value: Self) -> Self;
285
286 fn from_le(value: Self) -> Self;
288
289 fn from_str_radix(src: &str, radix: u32) -> Result<Self, ParseIntError>;
291
292 fn highest_one(self) -> Option<u32>;
294
295 fn ilog(self, base: Self) -> u32;
297
298 fn ilog10(self) -> u32;
300
301 fn ilog2(self) -> u32;
303
304 fn isolate_highest_one(self) -> Self;
306
307 fn isolate_lowest_one(self) -> Self;
309
310 fn isqrt(self) -> Self;
312
313 fn leading_ones(self) -> u32;
315
316 fn leading_zeros(self) -> u32;
318
319 fn lowest_one(self) -> Option<u32>;
321
322 fn overflowing_add(self, rhs: Self) -> (Self, bool);
325
326 fn overflowing_div(self, rhs: Self) -> (Self, bool);
329
330 fn overflowing_div_euclid(self, rhs: Self) -> (Self, bool);
333
334 fn overflowing_mul(self, rhs: Self) -> (Self, bool);
337
338 fn overflowing_neg(self) -> (Self, bool);
341
342 fn overflowing_pow(self, exp: u32) -> (Self, bool);
345
346 fn overflowing_rem(self, rhs: Self) -> (Self, bool);
349
350 fn overflowing_rem_euclid(self, rhs: Self) -> (Self, bool);
354
355 fn overflowing_shl(self, rhs: u32) -> (Self, bool);
359
360 fn overflowing_shr(self, rhs: u32) -> (Self, bool);
364
365 fn overflowing_sub(self, rhs: Self) -> (Self, bool);
368
369 fn pow(self, exp: u32) -> Self;
371
372 fn rem_euclid(self, rhs: Self) -> Self;
376
377 fn reverse_bits(self) -> Self;
379
380 fn rotate_left(self, n: u32) -> Self;
383
384 fn rotate_right(self, n: u32) -> Self;
387
388 fn saturating_add(self, rhs: Self) -> Self;
391
392 fn saturating_div(self, rhs: Self) -> Self;
395
396 fn saturating_mul(self, rhs: Self) -> Self;
399
400 fn saturating_pow(self, exp: u32) -> Self;
403
404 fn saturating_sub(self, rhs: Self) -> Self;
407
408 fn strict_add(self, rhs: Self) -> Self;
410
411 fn strict_div(self, rhs: Self) -> Self;
413
414 fn strict_div_euclid(self, rhs: Self) -> Self;
416
417 fn strict_mul(self, rhs: Self) -> Self;
419
420 fn strict_neg(self) -> Self;
423
424 fn strict_pow(self, exp: u32) -> Self;
426
427 fn strict_rem(self, rhs: Self) -> Self;
430
431 fn strict_rem_euclid(self, rhs: Self) -> Self;
434
435 fn strict_shl(self, rhs: u32) -> Self;
438
439 fn strict_shr(self, rhs: u32) -> Self;
442
443 fn strict_sub(self, rhs: Self) -> Self;
445
446 fn swap_bytes(self) -> Self;
448
449 fn to_be(self) -> Self;
451
452 fn to_le(self) -> Self;
454
455 fn trailing_ones(self) -> u32;
457
458 fn trailing_zeros(self) -> u32;
460
461 fn unbounded_shl(self, rhs: u32) -> Self;
463
464 fn unbounded_shr(self, rhs: u32) -> Self;
466
467 fn wrapping_add(self, rhs: Self) -> Self;
470
471 fn wrapping_div(self, rhs: Self) -> Self;
474
475 fn wrapping_div_euclid(self, rhs: Self) -> Self;
478
479 fn wrapping_mul(self, rhs: Self) -> Self;
482
483 fn wrapping_neg(self) -> Self;
485
486 fn wrapping_pow(self, exp: u32) -> Self;
489
490 fn wrapping_rem(self, rhs: Self) -> Self;
493
494 fn wrapping_rem_euclid(self, rhs: Self) -> Self;
497
498 fn wrapping_shl(self, rhs: u32) -> Self;
501
502 fn wrapping_shr(self, rhs: u32) -> Self;
505
506 fn wrapping_sub(self, rhs: Self) -> Self;
509
510 unsafe fn unchecked_add(self, rhs: Self) -> Self;
517
518 unsafe fn unchecked_mul(self, rhs: Self) -> Self;
525
526 unsafe fn unchecked_shl(self, rhs: u32) -> Self;
534
535 unsafe fn unchecked_shr(self, rhs: u32) -> Self;
543
544 unsafe fn unchecked_sub(self, rhs: Self) -> Self;
551}
552
553pub trait PrimitiveIntegerRef<T>:
558 PrimitiveNumberRef<T>
559 + core::cmp::Eq
560 + core::cmp::Ord
561 + core::fmt::Binary
562 + core::fmt::LowerHex
563 + core::fmt::Octal
564 + core::fmt::UpperHex
565 + core::hash::Hash
566 + core::ops::BitAnd<T, Output = T>
567 + core::ops::BitOr<T, Output = T>
568 + core::ops::BitXor<T, Output = T>
569 + core::ops::Not<Output = T>
570 + core::ops::Shl<T, Output = T>
571 + core::ops::Shl<i8, Output = T>
572 + core::ops::Shl<i16, Output = T>
573 + core::ops::Shl<i32, Output = T>
574 + core::ops::Shl<i64, Output = T>
575 + core::ops::Shl<i128, Output = T>
576 + core::ops::Shl<isize, Output = T>
577 + core::ops::Shl<u8, Output = T>
578 + core::ops::Shl<u16, Output = T>
579 + core::ops::Shl<u32, Output = T>
580 + core::ops::Shl<u64, Output = T>
581 + core::ops::Shl<u128, Output = T>
582 + core::ops::Shl<usize, Output = T>
583 + core::ops::Shr<T, Output = T>
584 + core::ops::Shr<i8, Output = T>
585 + core::ops::Shr<i16, Output = T>
586 + core::ops::Shr<i32, Output = T>
587 + core::ops::Shr<i64, Output = T>
588 + core::ops::Shr<i128, Output = T>
589 + core::ops::Shr<isize, Output = T>
590 + core::ops::Shr<u8, Output = T>
591 + core::ops::Shr<u16, Output = T>
592 + core::ops::Shr<u32, Output = T>
593 + core::ops::Shr<u64, Output = T>
594 + core::ops::Shr<u128, Output = T>
595 + core::ops::Shr<usize, Output = T>
596 + for<'a> core::ops::BitAnd<&'a T, Output = T>
597 + for<'a> core::ops::BitOr<&'a T, Output = T>
598 + for<'a> core::ops::BitXor<&'a T, Output = T>
599 + for<'a> core::ops::Shl<&'a T, Output = T>
600 + for<'a> core::ops::Shl<&'a i8, Output = T>
601 + for<'a> core::ops::Shl<&'a i16, Output = T>
602 + for<'a> core::ops::Shl<&'a i32, Output = T>
603 + for<'a> core::ops::Shl<&'a i64, Output = T>
604 + for<'a> core::ops::Shl<&'a i128, Output = T>
605 + for<'a> core::ops::Shl<&'a isize, Output = T>
606 + for<'a> core::ops::Shl<&'a u8, Output = T>
607 + for<'a> core::ops::Shl<&'a u16, Output = T>
608 + for<'a> core::ops::Shl<&'a u32, Output = T>
609 + for<'a> core::ops::Shl<&'a u64, Output = T>
610 + for<'a> core::ops::Shl<&'a u128, Output = T>
611 + for<'a> core::ops::Shl<&'a usize, Output = T>
612 + for<'a> core::ops::Shr<&'a T, Output = T>
613 + for<'a> core::ops::Shr<&'a i8, Output = T>
614 + for<'a> core::ops::Shr<&'a i16, Output = T>
615 + for<'a> core::ops::Shr<&'a i32, Output = T>
616 + for<'a> core::ops::Shr<&'a i64, Output = T>
617 + for<'a> core::ops::Shr<&'a i128, Output = T>
618 + for<'a> core::ops::Shr<&'a isize, Output = T>
619 + for<'a> core::ops::Shr<&'a u8, Output = T>
620 + for<'a> core::ops::Shr<&'a u16, Output = T>
621 + for<'a> core::ops::Shr<&'a u32, Output = T>
622 + for<'a> core::ops::Shr<&'a u64, Output = T>
623 + for<'a> core::ops::Shr<&'a u128, Output = T>
624 + for<'a> core::ops::Shr<&'a usize, Output = T>
625{
626}
627
628#[expect(private_bounds)]
653pub trait NonZeroPrimitiveInteger:
654 'static
655 + Sealed
656 + core::cmp::Eq
657 + core::cmp::Ord
658 + core::convert::Into<Self::Integer>
659 + core::convert::TryFrom<Self::Integer, Error = TryFromIntError>
660 + core::convert::TryFrom<NonZero<i8>, Error: PrimitiveError>
661 + core::convert::TryFrom<NonZero<i16>, Error: PrimitiveError>
662 + core::convert::TryFrom<NonZero<i32>, Error: PrimitiveError>
663 + core::convert::TryFrom<NonZero<i64>, Error: PrimitiveError>
664 + core::convert::TryFrom<NonZero<i128>, Error: PrimitiveError>
665 + core::convert::TryFrom<NonZero<isize>, Error: PrimitiveError>
666 + core::convert::TryFrom<NonZero<u8>, Error: PrimitiveError>
667 + core::convert::TryFrom<NonZero<u16>, Error: PrimitiveError>
668 + core::convert::TryFrom<NonZero<u32>, Error: PrimitiveError>
669 + core::convert::TryFrom<NonZero<u64>, Error: PrimitiveError>
670 + core::convert::TryFrom<NonZero<u128>, Error: PrimitiveError>
671 + core::convert::TryFrom<NonZero<usize>, Error: PrimitiveError>
672 + core::convert::TryInto<NonZero<i8>, Error: PrimitiveError>
673 + core::convert::TryInto<NonZero<i16>, Error: PrimitiveError>
674 + core::convert::TryInto<NonZero<i32>, Error: PrimitiveError>
675 + core::convert::TryInto<NonZero<i64>, Error: PrimitiveError>
676 + core::convert::TryInto<NonZero<i128>, Error: PrimitiveError>
677 + core::convert::TryInto<NonZero<isize>, Error: PrimitiveError>
678 + core::convert::TryInto<NonZero<u8>, Error: PrimitiveError>
679 + core::convert::TryInto<NonZero<u16>, Error: PrimitiveError>
680 + core::convert::TryInto<NonZero<u32>, Error: PrimitiveError>
681 + core::convert::TryInto<NonZero<u64>, Error: PrimitiveError>
682 + core::convert::TryInto<NonZero<u128>, Error: PrimitiveError>
683 + core::convert::TryInto<NonZero<usize>, Error: PrimitiveError>
684 + core::fmt::Binary
685 + core::fmt::Debug
686 + core::fmt::Display
687 + core::fmt::LowerExp
688 + core::fmt::LowerHex
689 + core::fmt::Octal
690 + core::fmt::UpperExp
691 + core::fmt::UpperHex
692 + core::hash::Hash
693 + core::marker::Copy
694 + core::marker::Send
695 + core::marker::Sync
696 + core::marker::Unpin
697 + core::ops::BitOr<Self, Output = Self>
698 + core::ops::BitOr<Self::Integer, Output = Self>
699 + core::ops::BitOrAssign<Self>
700 + core::ops::BitOrAssign<Self::Integer>
701 + core::panic::RefUnwindSafe
702 + core::panic::UnwindSafe
703 + core::str::FromStr<Err = ParseIntError>
704{
705 type Integer: PrimitiveInteger<NonZero = Self>;
709
710 const BITS: u32;
712
713 const MAX: Self;
715
716 const MIN: Self;
718
719 fn checked_mul(self, other: Self) -> Option<Self>;
721
722 fn checked_pow(self, other: u32) -> Option<Self>;
724
725 fn count_ones(self) -> NonZero<u32>;
727
728 fn from_str_radix(src: &str, radix: u32) -> Result<Self, ParseIntError>;
730
731 fn get(self) -> Self::Integer;
733
734 fn highest_one(self) -> u32;
736
737 fn isolate_highest_one(self) -> Self;
739
740 fn isolate_lowest_one(self) -> Self;
742
743 fn leading_zeros(self) -> u32;
745
746 fn lowest_one(self) -> u32;
748
749 fn new(n: Self::Integer) -> Option<Self>;
751
752 fn saturating_mul(self, other: Self) -> Self;
755
756 fn saturating_pow(self, other: u32) -> Self;
759
760 fn trailing_zeros(self) -> u32;
762
763 unsafe fn new_unchecked(n: Self::Integer) -> Self;
770}
771
772#[expect(private_bounds)]
807pub trait PrimitiveNumBuffer:
808 'static
809 + Sealed
810 + core::fmt::Debug
811 + core::marker::Send
812 + core::marker::Sized
813 + core::marker::Sync
814 + core::marker::Unpin
815 + core::panic::RefUnwindSafe
816 + core::panic::UnwindSafe
817{
818 fn new() -> Self;
820}
821
822macro_rules! impl_integer {
823 ($($Integer:ident),*) => {$(
824 impl PrimitiveInteger for $Integer {
825 type NonZero = NonZero<Self>;
826 type NumBuffer = NumBuffer<Self>;
827
828 use_consts!(Self::{
829 BITS: u32,
830 MAX: Self,
831 MIN: Self,
832 });
833
834 forward! {
835 fn from_be(value: Self) -> Self;
836 fn from_le(value: Self) -> Self;
837 fn from_str_radix(src: &str, radix: u32) -> Result<Self, ParseIntError>;
838 }
839 forward! {
840 fn checked_add(self, rhs: Self) -> Option<Self>;
841 fn checked_div(self, rhs: Self) -> Option<Self>;
842 fn checked_div_euclid(self, rhs: Self) -> Option<Self>;
843 fn checked_ilog(self, base: Self) -> Option<u32>;
844 fn checked_ilog10(self) -> Option<u32>;
845 fn checked_ilog2(self) -> Option<u32>;
846 fn checked_mul(self, rhs: Self) -> Option<Self>;
847 fn checked_neg(self) -> Option<Self>;
848 fn checked_pow(self, exp: u32) -> Option<Self>;
849 fn checked_rem(self, rhs: Self) -> Option<Self>;
850 fn checked_rem_euclid(self, rhs: Self) -> Option<Self>;
851 fn checked_shl(self, rhs: u32) -> Option<Self>;
852 fn checked_shr(self, rhs: u32) -> Option<Self>;
853 fn checked_sub(self, rhs: Self) -> Option<Self>;
854 fn count_ones(self) -> u32;
855 fn count_zeros(self) -> u32;
856 fn div_euclid(self, rhs: Self) -> Self;
857 fn format_into(self, buf: &mut Self::NumBuffer) -> &str;
858 fn highest_one(self) -> Option<u32>;
859 fn ilog(self, base: Self) -> u32;
860 fn ilog10(self) -> u32;
861 fn ilog2(self) -> u32;
862 fn isolate_highest_one(self) -> Self;
863 fn isolate_lowest_one(self) -> Self;
864 fn isqrt(self) -> Self;
865 fn leading_ones(self) -> u32;
866 fn leading_zeros(self) -> u32;
867 fn lowest_one(self) -> Option<u32>;
868 fn overflowing_add(self, rhs: Self) -> (Self, bool);
869 fn overflowing_div(self, rhs: Self) -> (Self, bool);
870 fn overflowing_div_euclid(self, rhs: Self) -> (Self, bool);
871 fn overflowing_mul(self, rhs: Self) -> (Self, bool);
872 fn overflowing_neg(self) -> (Self, bool);
873 fn overflowing_pow(self, exp: u32) -> (Self, bool);
874 fn overflowing_rem(self, rhs: Self) -> (Self, bool);
875 fn overflowing_rem_euclid(self, rhs: Self) -> (Self, bool);
876 fn overflowing_shl(self, rhs: u32) -> (Self, bool);
877 fn overflowing_shr(self, rhs: u32) -> (Self, bool);
878 fn overflowing_sub(self, rhs: Self) -> (Self, bool);
879 fn pow(self, exp: u32) -> Self;
880 fn rem_euclid(self, rhs: Self) -> Self;
881 fn reverse_bits(self) -> Self;
882 fn rotate_left(self, n: u32) -> Self;
883 fn rotate_right(self, n: u32) -> Self;
884 fn saturating_add(self, rhs: Self) -> Self;
885 fn saturating_div(self, rhs: Self) -> Self;
886 fn saturating_mul(self, rhs: Self) -> Self;
887 fn saturating_pow(self, exp: u32) -> Self;
888 fn saturating_sub(self, rhs: Self) -> Self;
889 fn strict_add(self, rhs: Self) -> Self;
890 fn strict_div(self, rhs: Self) -> Self;
891 fn strict_div_euclid(self, rhs: Self) -> Self;
892 fn strict_mul(self, rhs: Self) -> Self;
893 fn strict_neg(self) -> Self;
894 fn strict_pow(self, exp: u32) -> Self;
895 fn strict_rem(self, rhs: Self) -> Self;
896 fn strict_rem_euclid(self, rhs: Self) -> Self;
897 fn strict_shl(self, rhs: u32) -> Self;
898 fn strict_shr(self, rhs: u32) -> Self;
899 fn strict_sub(self, rhs: Self) -> Self;
900 fn swap_bytes(self) -> Self;
901 fn to_be(self) -> Self;
902 fn to_le(self) -> Self;
903 fn trailing_ones(self) -> u32;
904 fn trailing_zeros(self) -> u32;
905 fn unbounded_shl(self, rhs: u32) -> Self;
906 fn unbounded_shr(self, rhs: u32) -> Self;
907 fn wrapping_add(self, rhs: Self) -> Self;
908 fn wrapping_div(self, rhs: Self) -> Self;
909 fn wrapping_div_euclid(self, rhs: Self) -> Self;
910 fn wrapping_mul(self, rhs: Self) -> Self;
911 fn wrapping_neg(self) -> Self;
912 fn wrapping_pow(self, exp: u32) -> Self;
913 fn wrapping_rem(self, rhs: Self) -> Self;
914 fn wrapping_rem_euclid(self, rhs: Self) -> Self;
915 fn wrapping_shl(self, rhs: u32) -> Self;
916 fn wrapping_shr(self, rhs: u32) -> Self;
917 fn wrapping_sub(self, rhs: Self) -> Self;
918 }
919 forward! {
920 unsafe fn unchecked_add(self, rhs: Self) -> Self;
921 unsafe fn unchecked_mul(self, rhs: Self) -> Self;
922 unsafe fn unchecked_shl(self, rhs: u32) -> Self;
923 unsafe fn unchecked_shr(self, rhs: u32) -> Self;
924 unsafe fn unchecked_sub(self, rhs: Self) -> Self;
925 }
926 }
927
928 impl PrimitiveIntegerRef<$Integer> for &$Integer {}
929
930 impl Sealed for NonZero<$Integer> {}
931
932 impl NonZeroPrimitiveInteger for NonZero<$Integer> {
933 type Integer = $Integer;
934
935 use_consts!(Self::{
936 BITS: u32,
937 MAX: Self,
938 MIN: Self,
939 });
940
941 forward! {
942 fn from_str_radix(src: &str, radix: u32) -> Result<Self, ParseIntError>;
943 fn new(n: Self::Integer) -> Option<Self>;
944 }
945 forward! {
946 fn checked_mul(self, other: Self) -> Option<Self>;
947 fn checked_pow(self, other: u32) -> Option<Self>;
948 fn count_ones(self) -> NonZero<u32>;
949 fn get(self) -> Self::Integer;
950 fn highest_one(self) -> u32;
951 fn isolate_highest_one(self) -> Self;
952 fn isolate_lowest_one(self) -> Self;
953 fn leading_zeros(self) -> u32;
954 fn lowest_one(self) -> u32;
955 fn saturating_mul(self, other: Self) -> Self;
956 fn saturating_pow(self, other: u32) -> Self;
957 fn trailing_zeros(self) -> u32;
958 }
959 forward! {
960 unsafe fn new_unchecked(n: Self::Integer) -> Self;
961 }
962 }
963
964 impl Sealed for NumBuffer<$Integer> {}
965
966 impl PrimitiveNumBuffer for NumBuffer<$Integer> {
967 forward! {
968 fn new() -> Self;
969 }
970 }
971 )*}
972}
973
974impl_integer!(i8, i16, i32, i64, i128, isize);
975impl_integer!(u8, u16, u32, u64, u128, usize);