1mod test;
4
5mod r#impl;
6
7use crate::{
8 Array,
9 Uint,
10};
11use crate::compat::{
12 CloneToUninit,
13 ConstParamTy_,
14 Freeze,
15 NumBufferTrait,
16 Step,
17 StructuralPartialEq,
18 Thin,
19 ToOwned,
20 ToString,
21 TrustedStep,
22 UseCloned,
23};
24
25use core::any::Any;
26use core::convert::Infallible;
27use core::fmt::{
28 Binary,
29 Debug,
30 Display,
31 LowerExp,
32 LowerHex,
33 Octal,
34 UpperExp,
35 UpperHex,
36};
37use core::hash::Hash;
38use core::iter::{Product, Sum};
39use core::num::ParseIntError;
40use core::ops::{
41 Add,
42 AddAssign,
43 BitAnd,
44 BitAndAssign,
45 BitOr,
46 BitOrAssign,
47 BitXor,
48 BitXorAssign,
49 Div,
50 DivAssign,
51 Mul,
52 MulAssign,
53 Neg,
54 Not,
55 Rem,
56 RemAssign,
57 Shl,
58 ShlAssign,
59 Shr,
60 ShrAssign,
61 Sub,
62 SubAssign,
63};
64use core::panic::{RefUnwindSafe, UnwindSafe};
65use core::str::FromStr;
66
67pub unsafe trait Int
79where
80 Self:
81 crate::seal::Int
82 + 'static
83 + Any
84 + Binary
85 + CloneToUninit
86 + ConstParamTy_
87 + Copy
88 + Debug
89 + Default
90 + Display
91 + Eq
92 + Freeze
93 + From<bool>
94 + From<i8>
95 + FromStr
96 + Hash
97 + LowerExp
98 + LowerHex
99 + NumBufferTrait
100 + Octal
101 + Ord
102 + PartialEq
103 + PartialOrd
104 + Product
105 + RefUnwindSafe
106 + Send
107 + Step
108 + StructuralPartialEq
109 + Sum
110 + Sync
111 + Thin
112 + ToOwned
113 + ToString
114 + TrustedStep
115 + TryFrom<bool, Error = Infallible>
116 + TryFrom<i128>
117 + TryFrom<i16>
118 + TryFrom<i32>
119 + TryFrom<i64>
120 + TryFrom<i8, Error = Infallible>
121 + TryFrom<isize>
122 + TryFrom<u128>
123 + TryFrom<u16>
124 + TryFrom<u32>
125 + TryFrom<u64>
126 + TryFrom<u8>
127 + TryFrom<usize>
128 + TryInto<i128>
129 + TryInto<i16>
130 + TryInto<i32>
131 + TryInto<i64>
132 + TryInto<i8>
133 + TryInto<isize>
134 + TryInto<u128>
135 + TryInto<u16>
136 + TryInto<u32>
137 + TryInto<u64>
138 + TryInto<u8>
139 + TryInto<usize>
140 + Unpin
141 + UnwindSafe
142 + UpperExp
143 + UpperHex
144 + UseCloned
145 + Add< Output = Self>
147 + BitAnd< Output = Self>
148 + BitOr< Output = Self>
149 + BitXor< Output = Self>
150 + Div< Output = Self>
151 + Mul< Output = Self>
152 + Neg< Output = Self>
153 + Not< Output = Self>
154 + Rem< Output = Self>
155 + Shl< Output = Self>
156 + Shl< u8, Output = Self>
157 + Shl< u16, Output = Self>
158 + Shl< u32, Output = Self>
159 + Shl< u64, Output = Self>
160 + Shl< u128, Output = Self>
161 + Shl< usize, Output = Self>
162 + Shl< i8, Output = Self>
163 + Shl< i16, Output = Self>
164 + Shl< i32, Output = Self>
165 + Shl< i64, Output = Self>
166 + Shl< i128, Output = Self>
167 + Shl< isize, Output = Self>
168 + Shr< Output = Self>
169 + Shr< u8, Output = Self>
170 + Shr< u16, Output = Self>
171 + Shr< u32, Output = Self>
172 + Shr< u64, Output = Self>
173 + Shr< u128, Output = Self>
174 + Shr< usize, Output = Self>
175 + Shr< i8, Output = Self>
176 + Shr< i16, Output = Self>
177 + Shr< i32, Output = Self>
178 + Shr< i64, Output = Self>
179 + Shr< i128, Output = Self>
180 + Shr< isize, Output = Self>
181 + Sub< Output = Self>
182 + AddAssign
184 + BitAndAssign
185 + BitOrAssign
186 + BitXorAssign
187 + DivAssign
188 + MulAssign
189 + RemAssign
190 + ShlAssign
191 + ShlAssign<u8>
192 + ShlAssign<u16>
193 + ShlAssign<u32>
194 + ShlAssign<u64>
195 + ShlAssign<u128>
196 + ShlAssign<usize>
197 + ShlAssign<i8>
198 + ShlAssign<i16>
199 + ShlAssign<i32>
200 + ShlAssign<i64>
201 + ShlAssign<i128>
202 + ShlAssign<isize>
203 + ShrAssign
204 + ShrAssign<u8>
205 + ShrAssign<u16>
206 + ShrAssign<u32>
207 + ShrAssign<u64>
208 + ShrAssign<u128>
209 + ShrAssign<usize>
210 + ShrAssign<i8>
211 + ShrAssign<i16>
212 + ShrAssign<i32>
213 + ShrAssign<i64>
214 + ShrAssign<i128>
215 + ShrAssign<isize>
216 + SubAssign,
217{
218 type Uint: Uint<
220 Int = Self,
221 Bytes = Self::Bytes,
222 >;
223
224 type Bytes:
226 Array<Scalar = u8>
227 + 'static
228 + Any
229 + CloneToUninit
230 + ConstParamTy_
231 + Copy
232 + Debug
233 + Eq
234 + Freeze
235 + Hash
236 + Ord
237 + PartialEq
238 + PartialEq<[u8]>
239 + PartialOrd
240 + RefUnwindSafe
241 + Send
242 + Sync
243 + ToOwned
244 + Unpin
245 + UnwindSafe;
246
247 const BITS: u32;
249
250 const MIN: Self;
252
253 const MAX: Self;
255
256 const ZERO: Self;
269
270 const ONE: Self;
283
284 #[must_use]
286 fn from_le(value: Self) -> Self;
287
288 #[must_use]
290 fn from_be(value: Self) -> Self;
291
292 #[must_use]
294 fn from_ne_bytes(bytes: Self::Bytes) -> Self;
295
296 #[must_use]
298 fn from_le_bytes(bytes: Self::Bytes) -> Self;
299
300 #[must_use]
302 fn from_be_bytes(bytes: Self::Bytes) -> Self;
303
304 fn from_str_radix(s: &str, radix: u32) -> Result<Self, ParseIntError>;
306
307 #[cfg(feature = "nightly_backports")]
309 #[cfg_attr(feature = "unstable_docs", doc(cfg(feature = "nightly_backports")))]
310 #[must_use]
311 fn widening_mul(self, rhs: Self) -> (Self::Uint, Self);
312
313 #[cfg(feature = "nightly_backports")]
315 #[cfg_attr(feature = "unstable_docs", doc(cfg(feature = "nightly_backports")))]
316 #[must_use]
317 fn div_floor(self, rhs: Self) -> Self;
318
319 #[must_use]
321 fn div_euclid(self, rhs: Self) -> Self;
322
323 #[cfg(feature = "nightly_backports")]
325 #[cfg_attr(feature = "unstable_docs", doc(cfg(feature = "nightly_backports")))]
326 #[must_use]
327 fn exact_div(self, rhs: Self) -> Self;
328
329 #[must_use]
331 fn rem_euclid(self, rhs: Self) -> Self;
332
333 #[cfg(feature = "nightly_backports")]
335 #[cfg_attr(feature = "unstable_docs", doc(cfg(feature = "nightly_backports")))]
336 #[must_use]
337 fn exact_shl(self, rhs: u32) -> Option<Self>;
338
339 #[cfg(feature = "nightly_backports")]
341 #[cfg_attr(feature = "unstable_docs", doc(cfg(feature = "nightly_backports")))]
342 #[must_use]
343 fn exact_shr(self, rhs: u32) -> Option<Self>;
344
345 #[must_use]
347 fn rotate_left(self, rhs: u32) -> Self;
348
349 #[must_use]
351 fn rotate_right(self, rhs: u32) -> Self;
352
353 #[must_use]
355 fn swap_bytes(self) -> Self;
356
357 #[must_use]
359 fn reverse_bits(self) -> Self;
360
361 #[must_use]
363 fn abs(self) -> Self;
364
365 #[must_use]
367 fn unsigned_abs(self) -> Self::Uint;
368
369 #[must_use]
371 fn pow(self, exp: u32) -> Self;
372
373 #[must_use]
375 fn isqrt(self) -> Self;
376
377 #[must_use]
379 fn ilog(self, base: Self) -> u32;
380
381 #[must_use]
383 fn ilog2(self) -> u32;
384
385 #[must_use]
387 fn ilog10(self) -> u32;
388
389 #[must_use]
391 fn abs_diff(self, rhs: Self) -> Self::Uint;
392
393 #[must_use]
395 fn midpoint(self, rhs: Self) -> Self;
396
397 #[cfg(feature = "nightly_backports")]
399 #[cfg_attr(feature = "unstable_docs", doc(cfg(feature = "nightly_backports")))]
400 #[must_use]
401 fn next_multiple_of(self, rhs: Self) -> Self;
402
403 #[cfg(feature = "nightly_backports")]
405 #[cfg_attr(feature = "unstable_docs", doc(cfg(feature = "nightly_backports")))]
406 #[must_use]
407 fn isolate_lowest_one(self) -> Self;
408
409 #[cfg(feature = "nightly_backports")]
411 #[cfg_attr(feature = "unstable_docs", doc(cfg(feature = "nightly_backports")))]
412 #[must_use]
413 fn isolate_highest_one(self) -> Self;
414
415 #[cfg(feature = "nightly_backports")]
417 #[cfg_attr(feature = "unstable_docs", doc(cfg(feature = "nightly_backports")))]
418 #[must_use]
419 fn lowest_one(self) -> Option<u32>;
420
421 #[cfg(feature = "nightly_backports")]
423 #[cfg_attr(feature = "unstable_docs", doc(cfg(feature = "nightly_backports")))]
424 #[must_use]
425 fn highest_one(self) -> Option<u32>;
426
427 #[must_use]
429 fn count_zeros(self) -> u32;
430
431 #[must_use]
433 fn count_ones(self) -> u32;
434
435 #[must_use]
437 fn leading_zeros(self) -> u32;
438
439 #[must_use]
441 fn leading_ones(self) -> u32;
442
443 #[must_use]
445 fn trailing_zeros(self) -> u32;
446
447 #[must_use]
449 fn trailing_ones(self) -> u32;
450
451 #[must_use]
453 fn signum(self) -> Self;
454
455 #[must_use]
457 fn is_negative(self) -> bool;
458
459 #[must_use]
461 fn is_positive(self) -> bool;
462
463 #[cfg(feature = "nightly_backports")]
465 #[cfg_attr(feature = "unstable_docs", doc(cfg(feature = "nightly_backports")))]
466 #[must_use]
467 fn is_multiple_of(self, rhs: Self) -> bool;
468
469 #[must_use]
471 fn checked_add(self, rhs: Self) -> Option<Self>;
472
473 #[must_use]
475 fn checked_add_unsigned(self, rhs: Self::Uint) -> Option<Self>;
476
477 #[must_use]
479 fn checked_sub(self, rhs: Self) -> Option<Self>;
480
481 #[must_use]
483 fn checked_sub_unsigned(self, rhs: Self::Uint) -> Option<Self>;
484
485 #[must_use]
487 fn checked_mul(self, rhs: Self) -> Option<Self>;
488
489 #[must_use]
491 fn checked_div(self, rhs: Self) -> Option<Self>;
492
493 #[must_use]
495 fn checked_div_euclid(self, rhs: Self) -> Option<Self>;
496
497 #[cfg(feature = "nightly_backports")]
499 #[cfg_attr(feature = "unstable_docs", doc(cfg(feature = "nightly_backports")))]
500 #[must_use]
501 fn checked_exact_div(self, rhs: Self) -> Option<Self>;
502
503 #[must_use]
505 fn checked_rem(self, rhs: Self) -> Option<Self>;
506
507 #[must_use]
509 fn checked_rem_euclid(self, rhs: Self) -> Option<Self>;
510
511 #[must_use]
513 fn checked_shl(self, rhs: u32) -> Option<Self>;
514
515 #[must_use]
517 fn checked_shr(self, rhs: u32) -> Option<Self>;
518
519 #[must_use]
521 fn checked_neg(self) -> Option<Self>;
522
523 #[must_use]
525 fn checked_abs(self) -> Option<Self>;
526
527 #[must_use]
529 fn checked_pow(self, exp: u32) -> Option<Self>;
530
531 #[must_use]
533 fn checked_ilog(self, base: Self) -> Option<u32>;
534
535 #[must_use]
537 fn checked_ilog2(self) -> Option<u32>;
538
539 #[must_use]
541 fn checked_ilog10(self) -> Option<u32>;
542
543 #[cfg(feature = "nightly_backports")]
545 #[must_use]
546 fn checked_next_multiple_of(self, rhs: Self) -> Option<Self>;
547
548 #[must_use]
550 fn strict_add(self, rhs: Self) -> Self;
551
552 #[must_use]
554 fn strict_add_unsigned(self, rhs: Self::Uint) -> Self;
555
556 #[must_use]
558 fn strict_sub(self, rhs: Self) -> Self;
559
560 #[must_use]
562 fn strict_sub_unsigned(self, rhs: Self::Uint) -> Self;
563
564 #[must_use]
566 fn strict_mul(self, rhs: Self) -> Self;
567
568 #[must_use]
570 fn strict_div(self, rhs: Self) -> Self;
571
572 #[must_use]
574 fn strict_div_euclid(self, rhs: Self) -> Self;
575
576 #[must_use]
578 fn strict_rem(self, rhs: Self) -> Self;
579
580 #[must_use]
582 fn strict_rem_euclid(self, rhs: Self) -> Self;
583
584 #[must_use]
586 fn strict_shl(self, rhs: u32) -> Self;
587
588 #[must_use]
590 fn strict_shr(self, rhs: u32) -> Self;
591
592 #[must_use]
594 fn strict_neg(self) -> Self;
595
596 #[must_use]
598 fn strict_abs(self) -> Self;
599
600 #[must_use]
602 fn strict_pow(self, rhs: u32) -> Self;
603
604 #[expect(clippy::missing_safety_doc)]
606 #[must_use]
607 unsafe fn unchecked_add(self, rhs: Self) -> Self;
608
609 #[cfg(feature = "nightly_backports")]
611 #[cfg_attr(feature = "unstable_docs", doc(cfg(feature = "nightly_backports")))]
612 #[expect(clippy::missing_safety_doc)]
613 #[must_use]
614 unsafe fn unchecked_exact_div(self, rhs: Self) -> Self;
615
616 #[expect(clippy::missing_safety_doc)]
618 #[must_use]
619 unsafe fn unchecked_sub(self, rhs: Self) -> Self;
620
621 #[expect(clippy::missing_safety_doc)]
623 #[must_use]
624 unsafe fn unchecked_mul(self, rhs: Self) -> Self;
625
626 #[cfg(feature = "nightly_backports")]
628 #[cfg_attr(feature = "unstable_docs", doc(cfg(feature = "nightly_backports")))]
629 #[expect(clippy::missing_safety_doc)]
630 #[must_use]
631 unsafe fn unchecked_shl(self, rhs: u32) -> Self;
632
633 #[cfg(feature = "nightly_backports")]
635 #[cfg_attr(feature = "unstable_docs", doc(cfg(feature = "nightly_backports")))]
636 #[expect(clippy::missing_safety_doc)]
637 #[must_use]
638 unsafe fn unchecked_shr(self, rhs: u32) -> Self;
639
640 #[cfg(feature = "nightly_backports")]
642 #[cfg_attr(feature = "unstable_docs", doc(cfg(feature = "nightly_backports")))]
643 #[expect(clippy::missing_safety_doc)]
644 #[must_use]
645 unsafe fn unchecked_exact_shl(self, rhs: u32) -> Self;
646
647 #[cfg(feature = "nightly_backports")]
649 #[cfg_attr(feature = "unstable_docs", doc(cfg(feature = "nightly_backports")))]
650 #[expect(clippy::missing_safety_doc)]
651 #[must_use]
652 unsafe fn unchecked_exact_shr(self, rhs: u32) -> Self;
653
654 #[cfg(feature = "nightly_backports")]
656 #[cfg_attr(feature = "unstable_docs", doc(cfg(feature = "nightly_backports")))]
657 #[expect(clippy::missing_safety_doc)]
658 #[must_use]
659 unsafe fn unchecked_neg(self) -> Self;
660
661 #[must_use]
663 fn overflowing_add(self, rhs: Self) -> (Self, bool);
664
665 #[must_use]
667 fn overflowing_add_unsigned(self, rhs: Self::Uint) -> (Self, bool);
668
669 #[must_use]
671 fn overflowing_sub(self, rhs: Self) -> (Self, bool);
672
673 #[must_use]
675 fn overflowing_sub_unsigned(self, rhs: Self::Uint) -> (Self, bool);
676
677 #[must_use]
679 fn overflowing_mul(self, rhs: Self) -> (Self, bool);
680
681 #[must_use]
683 fn overflowing_div(self, rhs: Self) -> (Self, bool);
684
685 #[must_use]
687 fn overflowing_div_euclid(self, rhs: Self) -> (Self, bool);
688
689 #[must_use]
691 fn overflowing_rem(self, rhs: Self) -> (Self, bool);
692
693 #[must_use]
695 fn overflowing_rem_euclid(self, rhs: Self) -> (Self, bool);
696
697 #[must_use]
699 fn overflowing_shl(self, rhs: u32) -> (Self, bool);
700
701 #[must_use]
703 fn overflowing_shr(self, rhs: u32) -> (Self, bool);
704
705 #[must_use]
707 fn overflowing_neg(self) -> (Self, bool);
708
709 #[must_use]
711 fn overflowing_abs(self) -> (Self, bool);
712
713 #[must_use]
715 fn overflowing_pow(self, exp: u32) -> (Self, bool);
716
717 #[cfg(feature = "nightly_backports")]
719 #[cfg_attr(feature = "unstable_docs", doc(cfg(feature = "nightly_backports")))]
720 #[must_use]
721 fn carrying_add(self, rhs: Self, carry: bool) -> (Self, bool);
722
723 #[cfg(feature = "nightly_backports")]
725 #[cfg_attr(feature = "unstable_docs", doc(cfg(feature = "nightly_backports")))]
726 #[must_use]
727 fn carrying_mul(self, rhs: Self, carry: Self) -> (Self::Uint, Self);
728
729 #[cfg(feature = "nightly_backports")]
731 #[cfg_attr(feature = "unstable_docs", doc(cfg(feature = "nightly_backports")))]
732 #[must_use]
733 fn carrying_mul_add(self, mul: Self, add: Self, carry: Self) -> (Self::Uint, Self);
734
735 #[cfg(feature = "nightly_backports")]
737 #[cfg_attr(feature = "unstable_docs", doc(cfg(feature = "nightly_backports")))]
738 #[must_use]
739 fn borrowing_sub(self, rhs: Self, borrow: bool) -> (Self, bool);
740
741 #[must_use]
743 fn wrapping_add(self, rhs: Self) -> Self;
744
745 #[must_use]
747 fn wrapping_add_unsigned(self, rhs: Self::Uint) -> Self;
748
749 #[must_use]
751 fn wrapping_sub(self, rhs: Self) -> Self;
752
753 #[must_use]
755 fn wrapping_sub_unsigned(self, rhs: Self::Uint) -> Self;
756
757 #[must_use]
759 fn wrapping_mul(self, rhs: Self) -> Self;
760
761 #[must_use]
763 fn wrapping_div(self, rhs: Self) -> Self;
764
765 #[must_use]
767 fn wrapping_div_euclid(self, rhs: Self) -> Self;
768
769 #[must_use]
771 fn wrapping_rem(self, rhs: Self) -> Self;
772
773 #[must_use]
775 fn wrapping_rem_euclid(self, rhs: Self) -> Self;
776
777 #[must_use]
779 fn wrapping_shl(self, rhs: u32) -> Self;
780
781 #[must_use]
783 fn wrapping_shr(self, rhs: u32) -> Self;
784
785 #[must_use]
787 fn wrapping_neg(self) -> Self;
788
789 #[must_use]
791 fn wrapping_abs(self) -> Self;
792
793 #[must_use]
795 fn wrapping_pow(self, exp: u32) -> Self;
796
797 #[must_use]
799 fn saturating_add(self, rhs: Self) -> Self;
800
801 #[must_use]
803 fn saturating_add_unsigned(self, rhs: Self::Uint) -> Self;
804
805 #[must_use]
807 fn saturating_sub(self, rhs: Self) -> Self;
808
809 #[must_use]
811 fn saturating_sub_unsigned(self, rhs: Self::Uint) -> Self;
812
813 #[must_use]
815 fn saturating_mul(self, rhs: Self) -> Self;
816
817 #[must_use]
819 fn saturating_div(self, rhs: Self) -> Self;
820
821 #[must_use]
823 fn saturating_neg(self) -> Self;
824
825 #[must_use]
827 fn saturating_abs(self) -> Self;
828
829 #[must_use]
831 fn saturating_pow(self, exp: u32) -> Self;
832
833 #[must_use]
835 fn unbounded_shl(self, rhs: u32) -> Self;
836
837 #[must_use]
839 fn unbounded_shr(self, rhs: u32) -> Self;
840
841 #[must_use]
843 fn cast_unsigned(self) -> Self::Uint;
844
845 #[must_use]
847 fn to_le(self) -> Self;
848
849 #[must_use]
851 fn to_be(self) -> Self;
852
853 #[must_use]
855 fn to_ne_bytes(self) -> Self::Bytes;
856
857 #[must_use]
859 fn to_le_bytes(self) -> Self::Bytes;
860
861 #[must_use]
863 fn to_be_bytes(self) -> Self::Bytes;
864}