Skip to main content

cadd/
ops.rs

1// Code generated by cadd_generator. DO NOT EDIT.
2
3#[cfg(feature = "std")]
4use std::time::{Instant, SystemTime};
5use {
6    crate::{Error, MaybeParens},
7    alloc::format,
8    core::{num::NonZero, time::Duration},
9};
10///Checked addition: computes `a + b`, returning an error if overflow occured.
11///
12///See also: [module documentation](self).
13pub trait Cadd: Sized {
14    #[expect(missing_docs, reason = "no need for doc")]
15    type Other;
16    #[expect(missing_docs, reason = "no need for doc")]
17    type Output;
18    #[expect(missing_docs, reason = "no need for doc")]
19    type Error;
20    ///Checked addition: computes `a + b`, returning an error if overflow occured.
21    ///
22    ///Wrapper for `checked_add`.
23    fn cadd(self, other: Self::Other) -> Result<Self::Output, Self::Error>;
24    ///Checked addition assigement: executes `self += other`, returning an error if overflow occured.
25    ///
26    ///Wrapper for `checked_add`.
27    fn cadd_assign(&mut self, other: Self::Other) -> Result<(), Self::Error>;
28}
29///Checked addition: computes `a + b`, returning an error if overflow occured.
30///
31///Wrapper for `checked_add`.
32///
33///See also: [module documentation](self).
34#[doc(alias = "checked_add")]
35#[inline]
36pub fn cadd<T>(a: T, b: T::Other) -> Result<T::Output, T::Error>
37where
38    T: Cadd,
39{
40    a.cadd(b)
41}
42impl Cadd for NonZero<u8> {
43    type Other = u8;
44    type Output = NonZero<u8>;
45    type Error = Error;
46    ///Checked addition: computes `a + b`, returning an error if overflow occured.
47    ///
48    ///Wrapper for [`NonZero<u8>::checked_add`].
49    #[inline]
50    fn cadd(self, other: u8) -> Result<NonZero<u8>, Error> {
51        self.checked_add(other).ok_or_else(|| {
52            Error::new(format!(
53                "failed to compute {:?} + {:?}: {} overflow",
54                self,
55                MaybeParens(other),
56                "NonZero<u8>"
57            ))
58        })
59    }
60    #[inline]
61    ///Checked addition assigement: executes `self += other`, returning an error if overflow occured.
62    ///
63    ///Wrapper for [`NonZero<u8>::checked_add`].
64    fn cadd_assign(&mut self, other: u8) -> Result<(), Self::Error> {
65        *self = self.cadd(other)?;
66        Ok(())
67    }
68}
69impl Cadd for NonZero<u16> {
70    type Other = u16;
71    type Output = NonZero<u16>;
72    type Error = Error;
73    ///Checked addition: computes `a + b`, returning an error if overflow occured.
74    ///
75    ///Wrapper for [`NonZero<u16>::checked_add`].
76    #[inline]
77    fn cadd(self, other: u16) -> Result<NonZero<u16>, Error> {
78        self.checked_add(other).ok_or_else(|| {
79            Error::new(format!(
80                "failed to compute {:?} + {:?}: {} overflow",
81                self,
82                MaybeParens(other),
83                "NonZero<u16>"
84            ))
85        })
86    }
87    #[inline]
88    ///Checked addition assigement: executes `self += other`, returning an error if overflow occured.
89    ///
90    ///Wrapper for [`NonZero<u16>::checked_add`].
91    fn cadd_assign(&mut self, other: u16) -> Result<(), Self::Error> {
92        *self = self.cadd(other)?;
93        Ok(())
94    }
95}
96impl Cadd for NonZero<u32> {
97    type Other = u32;
98    type Output = NonZero<u32>;
99    type Error = Error;
100    ///Checked addition: computes `a + b`, returning an error if overflow occured.
101    ///
102    ///Wrapper for [`NonZero<u32>::checked_add`].
103    #[inline]
104    fn cadd(self, other: u32) -> Result<NonZero<u32>, Error> {
105        self.checked_add(other).ok_or_else(|| {
106            Error::new(format!(
107                "failed to compute {:?} + {:?}: {} overflow",
108                self,
109                MaybeParens(other),
110                "NonZero<u32>"
111            ))
112        })
113    }
114    #[inline]
115    ///Checked addition assigement: executes `self += other`, returning an error if overflow occured.
116    ///
117    ///Wrapper for [`NonZero<u32>::checked_add`].
118    fn cadd_assign(&mut self, other: u32) -> Result<(), Self::Error> {
119        *self = self.cadd(other)?;
120        Ok(())
121    }
122}
123impl Cadd for NonZero<u64> {
124    type Other = u64;
125    type Output = NonZero<u64>;
126    type Error = Error;
127    ///Checked addition: computes `a + b`, returning an error if overflow occured.
128    ///
129    ///Wrapper for [`NonZero<u64>::checked_add`].
130    #[inline]
131    fn cadd(self, other: u64) -> Result<NonZero<u64>, Error> {
132        self.checked_add(other).ok_or_else(|| {
133            Error::new(format!(
134                "failed to compute {:?} + {:?}: {} overflow",
135                self,
136                MaybeParens(other),
137                "NonZero<u64>"
138            ))
139        })
140    }
141    #[inline]
142    ///Checked addition assigement: executes `self += other`, returning an error if overflow occured.
143    ///
144    ///Wrapper for [`NonZero<u64>::checked_add`].
145    fn cadd_assign(&mut self, other: u64) -> Result<(), Self::Error> {
146        *self = self.cadd(other)?;
147        Ok(())
148    }
149}
150impl Cadd for NonZero<u128> {
151    type Other = u128;
152    type Output = NonZero<u128>;
153    type Error = Error;
154    ///Checked addition: computes `a + b`, returning an error if overflow occured.
155    ///
156    ///Wrapper for [`NonZero<u128>::checked_add`].
157    #[inline]
158    fn cadd(self, other: u128) -> Result<NonZero<u128>, Error> {
159        self.checked_add(other).ok_or_else(|| {
160            Error::new(format!(
161                "failed to compute {:?} + {:?}: {} overflow",
162                self,
163                MaybeParens(other),
164                "NonZero<u128>"
165            ))
166        })
167    }
168    #[inline]
169    ///Checked addition assigement: executes `self += other`, returning an error if overflow occured.
170    ///
171    ///Wrapper for [`NonZero<u128>::checked_add`].
172    fn cadd_assign(&mut self, other: u128) -> Result<(), Self::Error> {
173        *self = self.cadd(other)?;
174        Ok(())
175    }
176}
177impl Cadd for NonZero<usize> {
178    type Other = usize;
179    type Output = NonZero<usize>;
180    type Error = Error;
181    ///Checked addition: computes `a + b`, returning an error if overflow occured.
182    ///
183    ///Wrapper for [`NonZero<usize>::checked_add`].
184    #[inline]
185    fn cadd(self, other: usize) -> Result<NonZero<usize>, Error> {
186        self.checked_add(other).ok_or_else(|| {
187            Error::new(format!(
188                "failed to compute {:?} + {:?}: {} overflow",
189                self,
190                MaybeParens(other),
191                "NonZero<usize>"
192            ))
193        })
194    }
195    #[inline]
196    ///Checked addition assigement: executes `self += other`, returning an error if overflow occured.
197    ///
198    ///Wrapper for [`NonZero<usize>::checked_add`].
199    fn cadd_assign(&mut self, other: usize) -> Result<(), Self::Error> {
200        *self = self.cadd(other)?;
201        Ok(())
202    }
203}
204impl Cadd for i8 {
205    type Other = i8;
206    type Output = i8;
207    type Error = Error;
208    ///Checked addition: computes `a + b`, returning an error if overflow occured.
209    ///
210    ///Wrapper for [`i8::checked_add`].
211    #[inline]
212    fn cadd(self, other: i8) -> Result<i8, Error> {
213        self.checked_add(other).ok_or_else(|| {
214            Error::new(format!(
215                "failed to compute {:?} + {:?}: {} overflow",
216                self,
217                MaybeParens(other),
218                "i8"
219            ))
220        })
221    }
222    #[inline]
223    ///Checked addition assigement: executes `self += other`, returning an error if overflow occured.
224    ///
225    ///Wrapper for [`i8::checked_add`].
226    fn cadd_assign(&mut self, other: i8) -> Result<(), Self::Error> {
227        *self = self.cadd(other)?;
228        Ok(())
229    }
230}
231impl Cadd for i16 {
232    type Other = i16;
233    type Output = i16;
234    type Error = Error;
235    ///Checked addition: computes `a + b`, returning an error if overflow occured.
236    ///
237    ///Wrapper for [`i16::checked_add`].
238    #[inline]
239    fn cadd(self, other: i16) -> Result<i16, Error> {
240        self.checked_add(other).ok_or_else(|| {
241            Error::new(format!(
242                "failed to compute {:?} + {:?}: {} overflow",
243                self,
244                MaybeParens(other),
245                "i16"
246            ))
247        })
248    }
249    #[inline]
250    ///Checked addition assigement: executes `self += other`, returning an error if overflow occured.
251    ///
252    ///Wrapper for [`i16::checked_add`].
253    fn cadd_assign(&mut self, other: i16) -> Result<(), Self::Error> {
254        *self = self.cadd(other)?;
255        Ok(())
256    }
257}
258impl Cadd for i32 {
259    type Other = i32;
260    type Output = i32;
261    type Error = Error;
262    ///Checked addition: computes `a + b`, returning an error if overflow occured.
263    ///
264    ///Wrapper for [`i32::checked_add`].
265    #[inline]
266    fn cadd(self, other: i32) -> Result<i32, Error> {
267        self.checked_add(other).ok_or_else(|| {
268            Error::new(format!(
269                "failed to compute {:?} + {:?}: {} overflow",
270                self,
271                MaybeParens(other),
272                "i32"
273            ))
274        })
275    }
276    #[inline]
277    ///Checked addition assigement: executes `self += other`, returning an error if overflow occured.
278    ///
279    ///Wrapper for [`i32::checked_add`].
280    fn cadd_assign(&mut self, other: i32) -> Result<(), Self::Error> {
281        *self = self.cadd(other)?;
282        Ok(())
283    }
284}
285impl Cadd for i64 {
286    type Other = i64;
287    type Output = i64;
288    type Error = Error;
289    ///Checked addition: computes `a + b`, returning an error if overflow occured.
290    ///
291    ///Wrapper for [`i64::checked_add`].
292    #[inline]
293    fn cadd(self, other: i64) -> Result<i64, Error> {
294        self.checked_add(other).ok_or_else(|| {
295            Error::new(format!(
296                "failed to compute {:?} + {:?}: {} overflow",
297                self,
298                MaybeParens(other),
299                "i64"
300            ))
301        })
302    }
303    #[inline]
304    ///Checked addition assigement: executes `self += other`, returning an error if overflow occured.
305    ///
306    ///Wrapper for [`i64::checked_add`].
307    fn cadd_assign(&mut self, other: i64) -> Result<(), Self::Error> {
308        *self = self.cadd(other)?;
309        Ok(())
310    }
311}
312impl Cadd for i128 {
313    type Other = i128;
314    type Output = i128;
315    type Error = Error;
316    ///Checked addition: computes `a + b`, returning an error if overflow occured.
317    ///
318    ///Wrapper for [`i128::checked_add`].
319    #[inline]
320    fn cadd(self, other: i128) -> Result<i128, Error> {
321        self.checked_add(other).ok_or_else(|| {
322            Error::new(format!(
323                "failed to compute {:?} + {:?}: {} overflow",
324                self,
325                MaybeParens(other),
326                "i128"
327            ))
328        })
329    }
330    #[inline]
331    ///Checked addition assigement: executes `self += other`, returning an error if overflow occured.
332    ///
333    ///Wrapper for [`i128::checked_add`].
334    fn cadd_assign(&mut self, other: i128) -> Result<(), Self::Error> {
335        *self = self.cadd(other)?;
336        Ok(())
337    }
338}
339impl Cadd for isize {
340    type Other = isize;
341    type Output = isize;
342    type Error = Error;
343    ///Checked addition: computes `a + b`, returning an error if overflow occured.
344    ///
345    ///Wrapper for [`isize::checked_add`].
346    #[inline]
347    fn cadd(self, other: isize) -> Result<isize, Error> {
348        self.checked_add(other).ok_or_else(|| {
349            Error::new(format!(
350                "failed to compute {:?} + {:?}: {} overflow",
351                self,
352                MaybeParens(other),
353                "isize"
354            ))
355        })
356    }
357    #[inline]
358    ///Checked addition assigement: executes `self += other`, returning an error if overflow occured.
359    ///
360    ///Wrapper for [`isize::checked_add`].
361    fn cadd_assign(&mut self, other: isize) -> Result<(), Self::Error> {
362        *self = self.cadd(other)?;
363        Ok(())
364    }
365}
366impl Cadd for u8 {
367    type Other = u8;
368    type Output = u8;
369    type Error = Error;
370    ///Checked addition: computes `a + b`, returning an error if overflow occured.
371    ///
372    ///Wrapper for [`u8::checked_add`].
373    #[inline]
374    fn cadd(self, other: u8) -> Result<u8, Error> {
375        self.checked_add(other).ok_or_else(|| {
376            Error::new(format!(
377                "failed to compute {:?} + {:?}: {} overflow",
378                self,
379                MaybeParens(other),
380                "u8"
381            ))
382        })
383    }
384    #[inline]
385    ///Checked addition assigement: executes `self += other`, returning an error if overflow occured.
386    ///
387    ///Wrapper for [`u8::checked_add`].
388    fn cadd_assign(&mut self, other: u8) -> Result<(), Self::Error> {
389        *self = self.cadd(other)?;
390        Ok(())
391    }
392}
393impl Cadd for u16 {
394    type Other = u16;
395    type Output = u16;
396    type Error = Error;
397    ///Checked addition: computes `a + b`, returning an error if overflow occured.
398    ///
399    ///Wrapper for [`u16::checked_add`].
400    #[inline]
401    fn cadd(self, other: u16) -> Result<u16, Error> {
402        self.checked_add(other).ok_or_else(|| {
403            Error::new(format!(
404                "failed to compute {:?} + {:?}: {} overflow",
405                self,
406                MaybeParens(other),
407                "u16"
408            ))
409        })
410    }
411    #[inline]
412    ///Checked addition assigement: executes `self += other`, returning an error if overflow occured.
413    ///
414    ///Wrapper for [`u16::checked_add`].
415    fn cadd_assign(&mut self, other: u16) -> Result<(), Self::Error> {
416        *self = self.cadd(other)?;
417        Ok(())
418    }
419}
420impl Cadd for u32 {
421    type Other = u32;
422    type Output = u32;
423    type Error = Error;
424    ///Checked addition: computes `a + b`, returning an error if overflow occured.
425    ///
426    ///Wrapper for [`u32::checked_add`].
427    #[inline]
428    fn cadd(self, other: u32) -> Result<u32, Error> {
429        self.checked_add(other).ok_or_else(|| {
430            Error::new(format!(
431                "failed to compute {:?} + {:?}: {} overflow",
432                self,
433                MaybeParens(other),
434                "u32"
435            ))
436        })
437    }
438    #[inline]
439    ///Checked addition assigement: executes `self += other`, returning an error if overflow occured.
440    ///
441    ///Wrapper for [`u32::checked_add`].
442    fn cadd_assign(&mut self, other: u32) -> Result<(), Self::Error> {
443        *self = self.cadd(other)?;
444        Ok(())
445    }
446}
447impl Cadd for u64 {
448    type Other = u64;
449    type Output = u64;
450    type Error = Error;
451    ///Checked addition: computes `a + b`, returning an error if overflow occured.
452    ///
453    ///Wrapper for [`u64::checked_add`].
454    #[inline]
455    fn cadd(self, other: u64) -> Result<u64, Error> {
456        self.checked_add(other).ok_or_else(|| {
457            Error::new(format!(
458                "failed to compute {:?} + {:?}: {} overflow",
459                self,
460                MaybeParens(other),
461                "u64"
462            ))
463        })
464    }
465    #[inline]
466    ///Checked addition assigement: executes `self += other`, returning an error if overflow occured.
467    ///
468    ///Wrapper for [`u64::checked_add`].
469    fn cadd_assign(&mut self, other: u64) -> Result<(), Self::Error> {
470        *self = self.cadd(other)?;
471        Ok(())
472    }
473}
474impl Cadd for u128 {
475    type Other = u128;
476    type Output = u128;
477    type Error = Error;
478    ///Checked addition: computes `a + b`, returning an error if overflow occured.
479    ///
480    ///Wrapper for [`u128::checked_add`].
481    #[inline]
482    fn cadd(self, other: u128) -> Result<u128, Error> {
483        self.checked_add(other).ok_or_else(|| {
484            Error::new(format!(
485                "failed to compute {:?} + {:?}: {} overflow",
486                self,
487                MaybeParens(other),
488                "u128"
489            ))
490        })
491    }
492    #[inline]
493    ///Checked addition assigement: executes `self += other`, returning an error if overflow occured.
494    ///
495    ///Wrapper for [`u128::checked_add`].
496    fn cadd_assign(&mut self, other: u128) -> Result<(), Self::Error> {
497        *self = self.cadd(other)?;
498        Ok(())
499    }
500}
501impl Cadd for usize {
502    type Other = usize;
503    type Output = usize;
504    type Error = Error;
505    ///Checked addition: computes `a + b`, returning an error if overflow occured.
506    ///
507    ///Wrapper for [`usize::checked_add`].
508    #[inline]
509    fn cadd(self, other: usize) -> Result<usize, Error> {
510        self.checked_add(other).ok_or_else(|| {
511            Error::new(format!(
512                "failed to compute {:?} + {:?}: {} overflow",
513                self,
514                MaybeParens(other),
515                "usize"
516            ))
517        })
518    }
519    #[inline]
520    ///Checked addition assigement: executes `self += other`, returning an error if overflow occured.
521    ///
522    ///Wrapper for [`usize::checked_add`].
523    fn cadd_assign(&mut self, other: usize) -> Result<(), Self::Error> {
524        *self = self.cadd(other)?;
525        Ok(())
526    }
527}
528impl Cadd for Duration {
529    type Other = Duration;
530    type Output = Duration;
531    type Error = Error;
532    ///Checked addition: computes `a + b`, returning an error if overflow occured.
533    ///
534    ///Wrapper for [`Duration::checked_add`].
535    #[inline]
536    fn cadd(self, other: Duration) -> Result<Duration, Error> {
537        self.checked_add(other).ok_or_else(|| {
538            Error::new(format!(
539                "failed to compute {:?} + {:?}: {} overflow",
540                self,
541                MaybeParens(other),
542                "Duration"
543            ))
544        })
545    }
546    #[inline]
547    ///Checked addition assigement: executes `self += other`, returning an error if overflow occured.
548    ///
549    ///Wrapper for [`Duration::checked_add`].
550    fn cadd_assign(&mut self, other: Duration) -> Result<(), Self::Error> {
551        *self = self.cadd(other)?;
552        Ok(())
553    }
554}
555#[cfg(feature = "std")]
556impl Cadd for Instant {
557    type Other = Duration;
558    type Output = Instant;
559    type Error = Error;
560    ///Checked addition: computes `a + b`, returning an error if overflow occured.
561    ///
562    ///Wrapper for [`Instant::checked_add`].
563    #[inline]
564    fn cadd(self, other: Duration) -> Result<Instant, Error> {
565        self.checked_add(other).ok_or_else(|| {
566            Error::new(format!(
567                "failed to compute {:?} + {:?}: {} overflow",
568                self,
569                MaybeParens(other),
570                "Instant"
571            ))
572        })
573    }
574    #[inline]
575    ///Checked addition assigement: executes `self += other`, returning an error if overflow occured.
576    ///
577    ///Wrapper for [`Instant::checked_add`].
578    fn cadd_assign(&mut self, other: Duration) -> Result<(), Self::Error> {
579        *self = self.cadd(other)?;
580        Ok(())
581    }
582}
583#[cfg(feature = "std")]
584impl Cadd for SystemTime {
585    type Other = Duration;
586    type Output = SystemTime;
587    type Error = Error;
588    ///Checked addition: computes `a + b`, returning an error if overflow occured.
589    ///
590    ///Wrapper for [`SystemTime::checked_add`].
591    #[inline]
592    fn cadd(self, other: Duration) -> Result<SystemTime, Error> {
593        self.checked_add(other).ok_or_else(|| {
594            Error::new(format!(
595                "failed to compute {:?} + {:?}: {} overflow",
596                self,
597                MaybeParens(other),
598                "SystemTime"
599            ))
600        })
601    }
602    #[inline]
603    ///Checked addition assigement: executes `self += other`, returning an error if overflow occured.
604    ///
605    ///Wrapper for [`SystemTime::checked_add`].
606    fn cadd_assign(&mut self, other: Duration) -> Result<(), Self::Error> {
607        *self = self.cadd(other)?;
608        Ok(())
609    }
610}
611///Checked addition: computes `add_unsigned(a, b)`, returning an error if overflow occured.
612///
613///See also: [module documentation](self).
614pub trait CaddUnsigned: Sized {
615    #[expect(missing_docs, reason = "no need for doc")]
616    type Other;
617    #[expect(missing_docs, reason = "no need for doc")]
618    type Output;
619    #[expect(missing_docs, reason = "no need for doc")]
620    type Error;
621    ///Checked addition: computes `add_unsigned(a, b)`, returning an error if overflow occured.
622    ///
623    ///Wrapper for `checked_add_unsigned`.
624    fn cadd_unsigned(self, other: Self::Other) -> Result<Self::Output, Self::Error>;
625}
626///Checked addition: computes `add_unsigned(a, b)`, returning an error if overflow occured.
627///
628///Wrapper for `checked_add_unsigned`.
629///
630///See also: [module documentation](self).
631#[doc(alias = "checked_add_unsigned")]
632#[inline]
633pub fn cadd_unsigned<T>(a: T, b: T::Other) -> Result<T::Output, T::Error>
634where
635    T: CaddUnsigned,
636{
637    a.cadd_unsigned(b)
638}
639impl CaddUnsigned for i8 {
640    type Other = u8;
641    type Output = i8;
642    type Error = Error;
643    ///Checked addition: computes `add_unsigned(a, b)`, returning an error if overflow occured.
644    ///
645    ///Wrapper for [`i8::checked_add_unsigned`].
646    #[inline]
647    fn cadd_unsigned(self, other: u8) -> Result<i8, Error> {
648        self.checked_add_unsigned(other).ok_or_else(|| {
649            Error::new(format!(
650                "failed to compute add_unsigned({:?}, {:?}): {} overflow",
651                self, other, "i8"
652            ))
653        })
654    }
655}
656impl CaddUnsigned for i16 {
657    type Other = u16;
658    type Output = i16;
659    type Error = Error;
660    ///Checked addition: computes `add_unsigned(a, b)`, returning an error if overflow occured.
661    ///
662    ///Wrapper for [`i16::checked_add_unsigned`].
663    #[inline]
664    fn cadd_unsigned(self, other: u16) -> Result<i16, Error> {
665        self.checked_add_unsigned(other).ok_or_else(|| {
666            Error::new(format!(
667                "failed to compute add_unsigned({:?}, {:?}): {} overflow",
668                self, other, "i16"
669            ))
670        })
671    }
672}
673impl CaddUnsigned for i32 {
674    type Other = u32;
675    type Output = i32;
676    type Error = Error;
677    ///Checked addition: computes `add_unsigned(a, b)`, returning an error if overflow occured.
678    ///
679    ///Wrapper for [`i32::checked_add_unsigned`].
680    #[inline]
681    fn cadd_unsigned(self, other: u32) -> Result<i32, Error> {
682        self.checked_add_unsigned(other).ok_or_else(|| {
683            Error::new(format!(
684                "failed to compute add_unsigned({:?}, {:?}): {} overflow",
685                self, other, "i32"
686            ))
687        })
688    }
689}
690impl CaddUnsigned for i64 {
691    type Other = u64;
692    type Output = i64;
693    type Error = Error;
694    ///Checked addition: computes `add_unsigned(a, b)`, returning an error if overflow occured.
695    ///
696    ///Wrapper for [`i64::checked_add_unsigned`].
697    #[inline]
698    fn cadd_unsigned(self, other: u64) -> Result<i64, Error> {
699        self.checked_add_unsigned(other).ok_or_else(|| {
700            Error::new(format!(
701                "failed to compute add_unsigned({:?}, {:?}): {} overflow",
702                self, other, "i64"
703            ))
704        })
705    }
706}
707impl CaddUnsigned for i128 {
708    type Other = u128;
709    type Output = i128;
710    type Error = Error;
711    ///Checked addition: computes `add_unsigned(a, b)`, returning an error if overflow occured.
712    ///
713    ///Wrapper for [`i128::checked_add_unsigned`].
714    #[inline]
715    fn cadd_unsigned(self, other: u128) -> Result<i128, Error> {
716        self.checked_add_unsigned(other).ok_or_else(|| {
717            Error::new(format!(
718                "failed to compute add_unsigned({:?}, {:?}): {} overflow",
719                self, other, "i128"
720            ))
721        })
722    }
723}
724impl CaddUnsigned for isize {
725    type Other = usize;
726    type Output = isize;
727    type Error = Error;
728    ///Checked addition: computes `add_unsigned(a, b)`, returning an error if overflow occured.
729    ///
730    ///Wrapper for [`isize::checked_add_unsigned`].
731    #[inline]
732    fn cadd_unsigned(self, other: usize) -> Result<isize, Error> {
733        self.checked_add_unsigned(other).ok_or_else(|| {
734            Error::new(format!(
735                "failed to compute add_unsigned({:?}, {:?}): {} overflow",
736                self, other, "isize"
737            ))
738        })
739    }
740}
741///Checked addition: computes `add_signed(a, b)`, returning an error if overflow occured.
742///
743///See also: [module documentation](self).
744pub trait CaddSigned: Sized {
745    #[expect(missing_docs, reason = "no need for doc")]
746    type Other;
747    #[expect(missing_docs, reason = "no need for doc")]
748    type Output;
749    #[expect(missing_docs, reason = "no need for doc")]
750    type Error;
751    ///Checked addition: computes `add_signed(a, b)`, returning an error if overflow occured.
752    ///
753    ///Wrapper for `checked_add_signed`.
754    fn cadd_signed(self, other: Self::Other) -> Result<Self::Output, Self::Error>;
755}
756///Checked addition: computes `add_signed(a, b)`, returning an error if overflow occured.
757///
758///Wrapper for `checked_add_signed`.
759///
760///See also: [module documentation](self).
761#[doc(alias = "checked_add_signed")]
762#[inline]
763pub fn cadd_signed<T>(a: T, b: T::Other) -> Result<T::Output, T::Error>
764where
765    T: CaddSigned,
766{
767    a.cadd_signed(b)
768}
769impl CaddSigned for u8 {
770    type Other = i8;
771    type Output = u8;
772    type Error = Error;
773    ///Checked addition: computes `add_signed(a, b)`, returning an error if overflow occured.
774    ///
775    ///Wrapper for [`u8::checked_add_signed`].
776    #[inline]
777    fn cadd_signed(self, other: i8) -> Result<u8, Error> {
778        self.checked_add_signed(other).ok_or_else(|| {
779            Error::new(format!(
780                "failed to compute add_signed({:?}, {:?}): {} overflow",
781                self, other, "u8"
782            ))
783        })
784    }
785}
786impl CaddSigned for u16 {
787    type Other = i16;
788    type Output = u16;
789    type Error = Error;
790    ///Checked addition: computes `add_signed(a, b)`, returning an error if overflow occured.
791    ///
792    ///Wrapper for [`u16::checked_add_signed`].
793    #[inline]
794    fn cadd_signed(self, other: i16) -> Result<u16, Error> {
795        self.checked_add_signed(other).ok_or_else(|| {
796            Error::new(format!(
797                "failed to compute add_signed({:?}, {:?}): {} overflow",
798                self, other, "u16"
799            ))
800        })
801    }
802}
803impl CaddSigned for u32 {
804    type Other = i32;
805    type Output = u32;
806    type Error = Error;
807    ///Checked addition: computes `add_signed(a, b)`, returning an error if overflow occured.
808    ///
809    ///Wrapper for [`u32::checked_add_signed`].
810    #[inline]
811    fn cadd_signed(self, other: i32) -> Result<u32, Error> {
812        self.checked_add_signed(other).ok_or_else(|| {
813            Error::new(format!(
814                "failed to compute add_signed({:?}, {:?}): {} overflow",
815                self, other, "u32"
816            ))
817        })
818    }
819}
820impl CaddSigned for u64 {
821    type Other = i64;
822    type Output = u64;
823    type Error = Error;
824    ///Checked addition: computes `add_signed(a, b)`, returning an error if overflow occured.
825    ///
826    ///Wrapper for [`u64::checked_add_signed`].
827    #[inline]
828    fn cadd_signed(self, other: i64) -> Result<u64, Error> {
829        self.checked_add_signed(other).ok_or_else(|| {
830            Error::new(format!(
831                "failed to compute add_signed({:?}, {:?}): {} overflow",
832                self, other, "u64"
833            ))
834        })
835    }
836}
837impl CaddSigned for u128 {
838    type Other = i128;
839    type Output = u128;
840    type Error = Error;
841    ///Checked addition: computes `add_signed(a, b)`, returning an error if overflow occured.
842    ///
843    ///Wrapper for [`u128::checked_add_signed`].
844    #[inline]
845    fn cadd_signed(self, other: i128) -> Result<u128, Error> {
846        self.checked_add_signed(other).ok_or_else(|| {
847            Error::new(format!(
848                "failed to compute add_signed({:?}, {:?}): {} overflow",
849                self, other, "u128"
850            ))
851        })
852    }
853}
854impl CaddSigned for usize {
855    type Other = isize;
856    type Output = usize;
857    type Error = Error;
858    ///Checked addition: computes `add_signed(a, b)`, returning an error if overflow occured.
859    ///
860    ///Wrapper for [`usize::checked_add_signed`].
861    #[inline]
862    fn cadd_signed(self, other: isize) -> Result<usize, Error> {
863        self.checked_add_signed(other).ok_or_else(|| {
864            Error::new(format!(
865                "failed to compute add_signed({:?}, {:?}): {} overflow",
866                self, other, "usize"
867            ))
868        })
869    }
870}
871///Checked subtraction:  computes `a - b`, returning an error if overflow occured.
872///
873///See also: [module documentation](self).
874pub trait Csub: Sized {
875    #[expect(missing_docs, reason = "no need for doc")]
876    type Other;
877    #[expect(missing_docs, reason = "no need for doc")]
878    type Output;
879    #[expect(missing_docs, reason = "no need for doc")]
880    type Error;
881    ///Checked subtraction:  computes `a - b`, returning an error if overflow occured.
882    ///
883    ///Wrapper for `checked_sub`.
884    fn csub(self, other: Self::Other) -> Result<Self::Output, Self::Error>;
885    ///Checked subtraction assigement:  executes `self -= other`, returning an error if overflow occured.
886    ///
887    ///Wrapper for `checked_sub`.
888    fn csub_assign(&mut self, other: Self::Other) -> Result<(), Self::Error>;
889}
890///Checked subtraction:  computes `a - b`, returning an error if overflow occured.
891///
892///Wrapper for `checked_sub`.
893///
894///See also: [module documentation](self).
895#[doc(alias = "checked_sub")]
896#[inline]
897pub fn csub<T>(a: T, b: T::Other) -> Result<T::Output, T::Error>
898where
899    T: Csub,
900{
901    a.csub(b)
902}
903impl Csub for i8 {
904    type Other = i8;
905    type Output = i8;
906    type Error = Error;
907    ///Checked subtraction:  computes `a - b`, returning an error if overflow occured.
908    ///
909    ///Wrapper for [`i8::checked_sub`].
910    #[inline]
911    fn csub(self, other: i8) -> Result<i8, Error> {
912        self.checked_sub(other).ok_or_else(|| {
913            Error::new(format!(
914                "failed to compute {:?} - {:?}: {} overflow",
915                self,
916                MaybeParens(other),
917                "i8"
918            ))
919        })
920    }
921    #[inline]
922    ///Checked subtraction assigement:  executes `self -= other`, returning an error if overflow occured.
923    ///
924    ///Wrapper for [`i8::checked_sub`].
925    fn csub_assign(&mut self, other: i8) -> Result<(), Self::Error> {
926        *self = self.csub(other)?;
927        Ok(())
928    }
929}
930impl Csub for i16 {
931    type Other = i16;
932    type Output = i16;
933    type Error = Error;
934    ///Checked subtraction:  computes `a - b`, returning an error if overflow occured.
935    ///
936    ///Wrapper for [`i16::checked_sub`].
937    #[inline]
938    fn csub(self, other: i16) -> Result<i16, Error> {
939        self.checked_sub(other).ok_or_else(|| {
940            Error::new(format!(
941                "failed to compute {:?} - {:?}: {} overflow",
942                self,
943                MaybeParens(other),
944                "i16"
945            ))
946        })
947    }
948    #[inline]
949    ///Checked subtraction assigement:  executes `self -= other`, returning an error if overflow occured.
950    ///
951    ///Wrapper for [`i16::checked_sub`].
952    fn csub_assign(&mut self, other: i16) -> Result<(), Self::Error> {
953        *self = self.csub(other)?;
954        Ok(())
955    }
956}
957impl Csub for i32 {
958    type Other = i32;
959    type Output = i32;
960    type Error = Error;
961    ///Checked subtraction:  computes `a - b`, returning an error if overflow occured.
962    ///
963    ///Wrapper for [`i32::checked_sub`].
964    #[inline]
965    fn csub(self, other: i32) -> Result<i32, Error> {
966        self.checked_sub(other).ok_or_else(|| {
967            Error::new(format!(
968                "failed to compute {:?} - {:?}: {} overflow",
969                self,
970                MaybeParens(other),
971                "i32"
972            ))
973        })
974    }
975    #[inline]
976    ///Checked subtraction assigement:  executes `self -= other`, returning an error if overflow occured.
977    ///
978    ///Wrapper for [`i32::checked_sub`].
979    fn csub_assign(&mut self, other: i32) -> Result<(), Self::Error> {
980        *self = self.csub(other)?;
981        Ok(())
982    }
983}
984impl Csub for i64 {
985    type Other = i64;
986    type Output = i64;
987    type Error = Error;
988    ///Checked subtraction:  computes `a - b`, returning an error if overflow occured.
989    ///
990    ///Wrapper for [`i64::checked_sub`].
991    #[inline]
992    fn csub(self, other: i64) -> Result<i64, Error> {
993        self.checked_sub(other).ok_or_else(|| {
994            Error::new(format!(
995                "failed to compute {:?} - {:?}: {} overflow",
996                self,
997                MaybeParens(other),
998                "i64"
999            ))
1000        })
1001    }
1002    #[inline]
1003    ///Checked subtraction assigement:  executes `self -= other`, returning an error if overflow occured.
1004    ///
1005    ///Wrapper for [`i64::checked_sub`].
1006    fn csub_assign(&mut self, other: i64) -> Result<(), Self::Error> {
1007        *self = self.csub(other)?;
1008        Ok(())
1009    }
1010}
1011impl Csub for i128 {
1012    type Other = i128;
1013    type Output = i128;
1014    type Error = Error;
1015    ///Checked subtraction:  computes `a - b`, returning an error if overflow occured.
1016    ///
1017    ///Wrapper for [`i128::checked_sub`].
1018    #[inline]
1019    fn csub(self, other: i128) -> Result<i128, Error> {
1020        self.checked_sub(other).ok_or_else(|| {
1021            Error::new(format!(
1022                "failed to compute {:?} - {:?}: {} overflow",
1023                self,
1024                MaybeParens(other),
1025                "i128"
1026            ))
1027        })
1028    }
1029    #[inline]
1030    ///Checked subtraction assigement:  executes `self -= other`, returning an error if overflow occured.
1031    ///
1032    ///Wrapper for [`i128::checked_sub`].
1033    fn csub_assign(&mut self, other: i128) -> Result<(), Self::Error> {
1034        *self = self.csub(other)?;
1035        Ok(())
1036    }
1037}
1038impl Csub for isize {
1039    type Other = isize;
1040    type Output = isize;
1041    type Error = Error;
1042    ///Checked subtraction:  computes `a - b`, returning an error if overflow occured.
1043    ///
1044    ///Wrapper for [`isize::checked_sub`].
1045    #[inline]
1046    fn csub(self, other: isize) -> Result<isize, Error> {
1047        self.checked_sub(other).ok_or_else(|| {
1048            Error::new(format!(
1049                "failed to compute {:?} - {:?}: {} overflow",
1050                self,
1051                MaybeParens(other),
1052                "isize"
1053            ))
1054        })
1055    }
1056    #[inline]
1057    ///Checked subtraction assigement:  executes `self -= other`, returning an error if overflow occured.
1058    ///
1059    ///Wrapper for [`isize::checked_sub`].
1060    fn csub_assign(&mut self, other: isize) -> Result<(), Self::Error> {
1061        *self = self.csub(other)?;
1062        Ok(())
1063    }
1064}
1065impl Csub for u8 {
1066    type Other = u8;
1067    type Output = u8;
1068    type Error = Error;
1069    ///Checked subtraction:  computes `a - b`, returning an error if overflow occured.
1070    ///
1071    ///Wrapper for [`u8::checked_sub`].
1072    #[inline]
1073    fn csub(self, other: u8) -> Result<u8, Error> {
1074        self.checked_sub(other).ok_or_else(|| {
1075            Error::new(format!(
1076                "failed to compute {:?} - {:?}: {} overflow",
1077                self,
1078                MaybeParens(other),
1079                "u8"
1080            ))
1081        })
1082    }
1083    #[inline]
1084    ///Checked subtraction assigement:  executes `self -= other`, returning an error if overflow occured.
1085    ///
1086    ///Wrapper for [`u8::checked_sub`].
1087    fn csub_assign(&mut self, other: u8) -> Result<(), Self::Error> {
1088        *self = self.csub(other)?;
1089        Ok(())
1090    }
1091}
1092impl Csub for u16 {
1093    type Other = u16;
1094    type Output = u16;
1095    type Error = Error;
1096    ///Checked subtraction:  computes `a - b`, returning an error if overflow occured.
1097    ///
1098    ///Wrapper for [`u16::checked_sub`].
1099    #[inline]
1100    fn csub(self, other: u16) -> Result<u16, Error> {
1101        self.checked_sub(other).ok_or_else(|| {
1102            Error::new(format!(
1103                "failed to compute {:?} - {:?}: {} overflow",
1104                self,
1105                MaybeParens(other),
1106                "u16"
1107            ))
1108        })
1109    }
1110    #[inline]
1111    ///Checked subtraction assigement:  executes `self -= other`, returning an error if overflow occured.
1112    ///
1113    ///Wrapper for [`u16::checked_sub`].
1114    fn csub_assign(&mut self, other: u16) -> Result<(), Self::Error> {
1115        *self = self.csub(other)?;
1116        Ok(())
1117    }
1118}
1119impl Csub for u32 {
1120    type Other = u32;
1121    type Output = u32;
1122    type Error = Error;
1123    ///Checked subtraction:  computes `a - b`, returning an error if overflow occured.
1124    ///
1125    ///Wrapper for [`u32::checked_sub`].
1126    #[inline]
1127    fn csub(self, other: u32) -> Result<u32, Error> {
1128        self.checked_sub(other).ok_or_else(|| {
1129            Error::new(format!(
1130                "failed to compute {:?} - {:?}: {} overflow",
1131                self,
1132                MaybeParens(other),
1133                "u32"
1134            ))
1135        })
1136    }
1137    #[inline]
1138    ///Checked subtraction assigement:  executes `self -= other`, returning an error if overflow occured.
1139    ///
1140    ///Wrapper for [`u32::checked_sub`].
1141    fn csub_assign(&mut self, other: u32) -> Result<(), Self::Error> {
1142        *self = self.csub(other)?;
1143        Ok(())
1144    }
1145}
1146impl Csub for u64 {
1147    type Other = u64;
1148    type Output = u64;
1149    type Error = Error;
1150    ///Checked subtraction:  computes `a - b`, returning an error if overflow occured.
1151    ///
1152    ///Wrapper for [`u64::checked_sub`].
1153    #[inline]
1154    fn csub(self, other: u64) -> Result<u64, Error> {
1155        self.checked_sub(other).ok_or_else(|| {
1156            Error::new(format!(
1157                "failed to compute {:?} - {:?}: {} overflow",
1158                self,
1159                MaybeParens(other),
1160                "u64"
1161            ))
1162        })
1163    }
1164    #[inline]
1165    ///Checked subtraction assigement:  executes `self -= other`, returning an error if overflow occured.
1166    ///
1167    ///Wrapper for [`u64::checked_sub`].
1168    fn csub_assign(&mut self, other: u64) -> Result<(), Self::Error> {
1169        *self = self.csub(other)?;
1170        Ok(())
1171    }
1172}
1173impl Csub for u128 {
1174    type Other = u128;
1175    type Output = u128;
1176    type Error = Error;
1177    ///Checked subtraction:  computes `a - b`, returning an error if overflow occured.
1178    ///
1179    ///Wrapper for [`u128::checked_sub`].
1180    #[inline]
1181    fn csub(self, other: u128) -> Result<u128, Error> {
1182        self.checked_sub(other).ok_or_else(|| {
1183            Error::new(format!(
1184                "failed to compute {:?} - {:?}: {} overflow",
1185                self,
1186                MaybeParens(other),
1187                "u128"
1188            ))
1189        })
1190    }
1191    #[inline]
1192    ///Checked subtraction assigement:  executes `self -= other`, returning an error if overflow occured.
1193    ///
1194    ///Wrapper for [`u128::checked_sub`].
1195    fn csub_assign(&mut self, other: u128) -> Result<(), Self::Error> {
1196        *self = self.csub(other)?;
1197        Ok(())
1198    }
1199}
1200impl Csub for usize {
1201    type Other = usize;
1202    type Output = usize;
1203    type Error = Error;
1204    ///Checked subtraction:  computes `a - b`, returning an error if overflow occured.
1205    ///
1206    ///Wrapper for [`usize::checked_sub`].
1207    #[inline]
1208    fn csub(self, other: usize) -> Result<usize, Error> {
1209        self.checked_sub(other).ok_or_else(|| {
1210            Error::new(format!(
1211                "failed to compute {:?} - {:?}: {} overflow",
1212                self,
1213                MaybeParens(other),
1214                "usize"
1215            ))
1216        })
1217    }
1218    #[inline]
1219    ///Checked subtraction assigement:  executes `self -= other`, returning an error if overflow occured.
1220    ///
1221    ///Wrapper for [`usize::checked_sub`].
1222    fn csub_assign(&mut self, other: usize) -> Result<(), Self::Error> {
1223        *self = self.csub(other)?;
1224        Ok(())
1225    }
1226}
1227impl Csub for Duration {
1228    type Other = Duration;
1229    type Output = Duration;
1230    type Error = Error;
1231    ///Checked subtraction:  computes `a - b`, returning an error if overflow occured.
1232    ///
1233    ///Wrapper for [`Duration::checked_sub`].
1234    #[inline]
1235    fn csub(self, other: Duration) -> Result<Duration, Error> {
1236        self.checked_sub(other).ok_or_else(|| {
1237            Error::new(format!(
1238                "failed to compute {:?} - {:?}: {} overflow",
1239                self,
1240                MaybeParens(other),
1241                "Duration"
1242            ))
1243        })
1244    }
1245    #[inline]
1246    ///Checked subtraction assigement:  executes `self -= other`, returning an error if overflow occured.
1247    ///
1248    ///Wrapper for [`Duration::checked_sub`].
1249    fn csub_assign(&mut self, other: Duration) -> Result<(), Self::Error> {
1250        *self = self.csub(other)?;
1251        Ok(())
1252    }
1253}
1254#[cfg(feature = "std")]
1255impl Csub for Instant {
1256    type Other = Duration;
1257    type Output = Instant;
1258    type Error = Error;
1259    ///Checked subtraction:  computes `a - b`, returning an error if overflow occured.
1260    ///
1261    ///Wrapper for [`Instant::checked_sub`].
1262    #[inline]
1263    fn csub(self, other: Duration) -> Result<Instant, Error> {
1264        self.checked_sub(other).ok_or_else(|| {
1265            Error::new(format!(
1266                "failed to compute {:?} - {:?}: {} overflow",
1267                self,
1268                MaybeParens(other),
1269                "Instant"
1270            ))
1271        })
1272    }
1273    #[inline]
1274    ///Checked subtraction assigement:  executes `self -= other`, returning an error if overflow occured.
1275    ///
1276    ///Wrapper for [`Instant::checked_sub`].
1277    fn csub_assign(&mut self, other: Duration) -> Result<(), Self::Error> {
1278        *self = self.csub(other)?;
1279        Ok(())
1280    }
1281}
1282#[cfg(feature = "std")]
1283impl Csub for SystemTime {
1284    type Other = Duration;
1285    type Output = SystemTime;
1286    type Error = Error;
1287    ///Checked subtraction:  computes `a - b`, returning an error if overflow occured.
1288    ///
1289    ///Wrapper for [`SystemTime::checked_sub`].
1290    #[inline]
1291    fn csub(self, other: Duration) -> Result<SystemTime, Error> {
1292        self.checked_sub(other).ok_or_else(|| {
1293            Error::new(format!(
1294                "failed to compute {:?} - {:?}: {} overflow",
1295                self,
1296                MaybeParens(other),
1297                "SystemTime"
1298            ))
1299        })
1300    }
1301    #[inline]
1302    ///Checked subtraction assigement:  executes `self -= other`, returning an error if overflow occured.
1303    ///
1304    ///Wrapper for [`SystemTime::checked_sub`].
1305    fn csub_assign(&mut self, other: Duration) -> Result<(), Self::Error> {
1306        *self = self.csub(other)?;
1307        Ok(())
1308    }
1309}
1310///Checked subtraction:  computes `sub_unsigned(a, b)`, returning an error if overflow occured.
1311///
1312///See also: [module documentation](self).
1313pub trait CsubUnsigned: Sized {
1314    #[expect(missing_docs, reason = "no need for doc")]
1315    type Other;
1316    #[expect(missing_docs, reason = "no need for doc")]
1317    type Output;
1318    #[expect(missing_docs, reason = "no need for doc")]
1319    type Error;
1320    ///Checked subtraction:  computes `sub_unsigned(a, b)`, returning an error if overflow occured.
1321    ///
1322    ///Wrapper for `checked_sub_unsigned`.
1323    fn csub_unsigned(self, other: Self::Other) -> Result<Self::Output, Self::Error>;
1324}
1325///Checked subtraction:  computes `sub_unsigned(a, b)`, returning an error if overflow occured.
1326///
1327///Wrapper for `checked_sub_unsigned`.
1328///
1329///See also: [module documentation](self).
1330#[doc(alias = "checked_sub_unsigned")]
1331#[inline]
1332pub fn csub_unsigned<T>(a: T, b: T::Other) -> Result<T::Output, T::Error>
1333where
1334    T: CsubUnsigned,
1335{
1336    a.csub_unsigned(b)
1337}
1338impl CsubUnsigned for i8 {
1339    type Other = u8;
1340    type Output = i8;
1341    type Error = Error;
1342    ///Checked subtraction:  computes `sub_unsigned(a, b)`, returning an error if overflow occured.
1343    ///
1344    ///Wrapper for [`i8::checked_sub_unsigned`].
1345    #[inline]
1346    fn csub_unsigned(self, other: u8) -> Result<i8, Error> {
1347        self.checked_sub_unsigned(other).ok_or_else(|| {
1348            Error::new(format!(
1349                "failed to compute sub_unsigned({:?}, {:?}): {} overflow",
1350                self, other, "i8"
1351            ))
1352        })
1353    }
1354}
1355impl CsubUnsigned for i16 {
1356    type Other = u16;
1357    type Output = i16;
1358    type Error = Error;
1359    ///Checked subtraction:  computes `sub_unsigned(a, b)`, returning an error if overflow occured.
1360    ///
1361    ///Wrapper for [`i16::checked_sub_unsigned`].
1362    #[inline]
1363    fn csub_unsigned(self, other: u16) -> Result<i16, Error> {
1364        self.checked_sub_unsigned(other).ok_or_else(|| {
1365            Error::new(format!(
1366                "failed to compute sub_unsigned({:?}, {:?}): {} overflow",
1367                self, other, "i16"
1368            ))
1369        })
1370    }
1371}
1372impl CsubUnsigned for i32 {
1373    type Other = u32;
1374    type Output = i32;
1375    type Error = Error;
1376    ///Checked subtraction:  computes `sub_unsigned(a, b)`, returning an error if overflow occured.
1377    ///
1378    ///Wrapper for [`i32::checked_sub_unsigned`].
1379    #[inline]
1380    fn csub_unsigned(self, other: u32) -> Result<i32, Error> {
1381        self.checked_sub_unsigned(other).ok_or_else(|| {
1382            Error::new(format!(
1383                "failed to compute sub_unsigned({:?}, {:?}): {} overflow",
1384                self, other, "i32"
1385            ))
1386        })
1387    }
1388}
1389impl CsubUnsigned for i64 {
1390    type Other = u64;
1391    type Output = i64;
1392    type Error = Error;
1393    ///Checked subtraction:  computes `sub_unsigned(a, b)`, returning an error if overflow occured.
1394    ///
1395    ///Wrapper for [`i64::checked_sub_unsigned`].
1396    #[inline]
1397    fn csub_unsigned(self, other: u64) -> Result<i64, Error> {
1398        self.checked_sub_unsigned(other).ok_or_else(|| {
1399            Error::new(format!(
1400                "failed to compute sub_unsigned({:?}, {:?}): {} overflow",
1401                self, other, "i64"
1402            ))
1403        })
1404    }
1405}
1406impl CsubUnsigned for i128 {
1407    type Other = u128;
1408    type Output = i128;
1409    type Error = Error;
1410    ///Checked subtraction:  computes `sub_unsigned(a, b)`, returning an error if overflow occured.
1411    ///
1412    ///Wrapper for [`i128::checked_sub_unsigned`].
1413    #[inline]
1414    fn csub_unsigned(self, other: u128) -> Result<i128, Error> {
1415        self.checked_sub_unsigned(other).ok_or_else(|| {
1416            Error::new(format!(
1417                "failed to compute sub_unsigned({:?}, {:?}): {} overflow",
1418                self, other, "i128"
1419            ))
1420        })
1421    }
1422}
1423impl CsubUnsigned for isize {
1424    type Other = usize;
1425    type Output = isize;
1426    type Error = Error;
1427    ///Checked subtraction:  computes `sub_unsigned(a, b)`, returning an error if overflow occured.
1428    ///
1429    ///Wrapper for [`isize::checked_sub_unsigned`].
1430    #[inline]
1431    fn csub_unsigned(self, other: usize) -> Result<isize, Error> {
1432        self.checked_sub_unsigned(other).ok_or_else(|| {
1433            Error::new(format!(
1434                "failed to compute sub_unsigned({:?}, {:?}): {} overflow",
1435                self, other, "isize"
1436            ))
1437        })
1438    }
1439}
1440///Checked subtraction:  computes `sub_signed(a, b)`, returning an error if overflow occured.
1441///
1442///See also: [module documentation](self).
1443pub trait CsubSigned: Sized {
1444    #[expect(missing_docs, reason = "no need for doc")]
1445    type Other;
1446    #[expect(missing_docs, reason = "no need for doc")]
1447    type Output;
1448    #[expect(missing_docs, reason = "no need for doc")]
1449    type Error;
1450    ///Checked subtraction:  computes `sub_signed(a, b)`, returning an error if overflow occured.
1451    ///
1452    ///Wrapper for `checked_sub_signed`.
1453    fn csub_signed(self, other: Self::Other) -> Result<Self::Output, Self::Error>;
1454}
1455///Checked subtraction:  computes `sub_signed(a, b)`, returning an error if overflow occured.
1456///
1457///Wrapper for `checked_sub_signed`.
1458///
1459///See also: [module documentation](self).
1460#[doc(alias = "checked_sub_signed")]
1461#[inline]
1462pub fn csub_signed<T>(a: T, b: T::Other) -> Result<T::Output, T::Error>
1463where
1464    T: CsubSigned,
1465{
1466    a.csub_signed(b)
1467}
1468impl CsubSigned for u8 {
1469    type Other = i8;
1470    type Output = u8;
1471    type Error = Error;
1472    ///Checked subtraction:  computes `sub_signed(a, b)`, returning an error if overflow occured.
1473    ///
1474    ///Wrapper for [`u8::checked_sub_signed`].
1475    #[inline]
1476    fn csub_signed(self, other: i8) -> Result<u8, Error> {
1477        self.checked_sub_signed(other).ok_or_else(|| {
1478            Error::new(format!(
1479                "failed to compute sub_signed({:?}, {:?}): {} overflow",
1480                self, other, "u8"
1481            ))
1482        })
1483    }
1484}
1485impl CsubSigned for u16 {
1486    type Other = i16;
1487    type Output = u16;
1488    type Error = Error;
1489    ///Checked subtraction:  computes `sub_signed(a, b)`, returning an error if overflow occured.
1490    ///
1491    ///Wrapper for [`u16::checked_sub_signed`].
1492    #[inline]
1493    fn csub_signed(self, other: i16) -> Result<u16, Error> {
1494        self.checked_sub_signed(other).ok_or_else(|| {
1495            Error::new(format!(
1496                "failed to compute sub_signed({:?}, {:?}): {} overflow",
1497                self, other, "u16"
1498            ))
1499        })
1500    }
1501}
1502impl CsubSigned for u32 {
1503    type Other = i32;
1504    type Output = u32;
1505    type Error = Error;
1506    ///Checked subtraction:  computes `sub_signed(a, b)`, returning an error if overflow occured.
1507    ///
1508    ///Wrapper for [`u32::checked_sub_signed`].
1509    #[inline]
1510    fn csub_signed(self, other: i32) -> Result<u32, Error> {
1511        self.checked_sub_signed(other).ok_or_else(|| {
1512            Error::new(format!(
1513                "failed to compute sub_signed({:?}, {:?}): {} overflow",
1514                self, other, "u32"
1515            ))
1516        })
1517    }
1518}
1519impl CsubSigned for u64 {
1520    type Other = i64;
1521    type Output = u64;
1522    type Error = Error;
1523    ///Checked subtraction:  computes `sub_signed(a, b)`, returning an error if overflow occured.
1524    ///
1525    ///Wrapper for [`u64::checked_sub_signed`].
1526    #[inline]
1527    fn csub_signed(self, other: i64) -> Result<u64, Error> {
1528        self.checked_sub_signed(other).ok_or_else(|| {
1529            Error::new(format!(
1530                "failed to compute sub_signed({:?}, {:?}): {} overflow",
1531                self, other, "u64"
1532            ))
1533        })
1534    }
1535}
1536impl CsubSigned for u128 {
1537    type Other = i128;
1538    type Output = u128;
1539    type Error = Error;
1540    ///Checked subtraction:  computes `sub_signed(a, b)`, returning an error if overflow occured.
1541    ///
1542    ///Wrapper for [`u128::checked_sub_signed`].
1543    #[inline]
1544    fn csub_signed(self, other: i128) -> Result<u128, Error> {
1545        self.checked_sub_signed(other).ok_or_else(|| {
1546            Error::new(format!(
1547                "failed to compute sub_signed({:?}, {:?}): {} overflow",
1548                self, other, "u128"
1549            ))
1550        })
1551    }
1552}
1553impl CsubSigned for usize {
1554    type Other = isize;
1555    type Output = usize;
1556    type Error = Error;
1557    ///Checked subtraction:  computes `sub_signed(a, b)`, returning an error if overflow occured.
1558    ///
1559    ///Wrapper for [`usize::checked_sub_signed`].
1560    #[inline]
1561    fn csub_signed(self, other: isize) -> Result<usize, Error> {
1562        self.checked_sub_signed(other).ok_or_else(|| {
1563            Error::new(format!(
1564                "failed to compute sub_signed({:?}, {:?}): {} overflow",
1565                self, other, "usize"
1566            ))
1567        })
1568    }
1569}
1570///Checked subtraction:  computes `signed_diff(a, b)`, returning an error if overflow occured.
1571///
1572///See also: [module documentation](self).
1573pub trait CsignedDiff: Sized {
1574    #[expect(missing_docs, reason = "no need for doc")]
1575    type Other;
1576    #[expect(missing_docs, reason = "no need for doc")]
1577    type Output;
1578    #[expect(missing_docs, reason = "no need for doc")]
1579    type Error;
1580    ///Checked subtraction:  computes `signed_diff(a, b)`, returning an error if overflow occured.
1581    ///
1582    ///Wrapper for `checked_signed_diff`.
1583    fn csigned_diff(self, other: Self::Other) -> Result<Self::Output, Self::Error>;
1584}
1585///Checked subtraction:  computes `signed_diff(a, b)`, returning an error if overflow occured.
1586///
1587///Wrapper for `checked_signed_diff`.
1588///
1589///See also: [module documentation](self).
1590#[doc(alias = "checked_signed_diff")]
1591#[inline]
1592pub fn csigned_diff<T>(a: T, b: T::Other) -> Result<T::Output, T::Error>
1593where
1594    T: CsignedDiff,
1595{
1596    a.csigned_diff(b)
1597}
1598impl CsignedDiff for u8 {
1599    type Other = u8;
1600    type Output = i8;
1601    type Error = Error;
1602    ///Checked subtraction:  computes `signed_diff(a, b)`, returning an error if overflow occured.
1603    ///
1604    ///Wrapper for [`u8::checked_signed_diff`].
1605    #[inline]
1606    fn csigned_diff(self, other: u8) -> Result<i8, Error> {
1607        self.checked_signed_diff(other).ok_or_else(|| {
1608            Error::new(format!(
1609                "failed to compute signed_diff({:?}, {:?}): {} overflow",
1610                self, other, "i8"
1611            ))
1612        })
1613    }
1614}
1615impl CsignedDiff for u16 {
1616    type Other = u16;
1617    type Output = i16;
1618    type Error = Error;
1619    ///Checked subtraction:  computes `signed_diff(a, b)`, returning an error if overflow occured.
1620    ///
1621    ///Wrapper for [`u16::checked_signed_diff`].
1622    #[inline]
1623    fn csigned_diff(self, other: u16) -> Result<i16, Error> {
1624        self.checked_signed_diff(other).ok_or_else(|| {
1625            Error::new(format!(
1626                "failed to compute signed_diff({:?}, {:?}): {} overflow",
1627                self, other, "i16"
1628            ))
1629        })
1630    }
1631}
1632impl CsignedDiff for u32 {
1633    type Other = u32;
1634    type Output = i32;
1635    type Error = Error;
1636    ///Checked subtraction:  computes `signed_diff(a, b)`, returning an error if overflow occured.
1637    ///
1638    ///Wrapper for [`u32::checked_signed_diff`].
1639    #[inline]
1640    fn csigned_diff(self, other: u32) -> Result<i32, Error> {
1641        self.checked_signed_diff(other).ok_or_else(|| {
1642            Error::new(format!(
1643                "failed to compute signed_diff({:?}, {:?}): {} overflow",
1644                self, other, "i32"
1645            ))
1646        })
1647    }
1648}
1649impl CsignedDiff for u64 {
1650    type Other = u64;
1651    type Output = i64;
1652    type Error = Error;
1653    ///Checked subtraction:  computes `signed_diff(a, b)`, returning an error if overflow occured.
1654    ///
1655    ///Wrapper for [`u64::checked_signed_diff`].
1656    #[inline]
1657    fn csigned_diff(self, other: u64) -> Result<i64, Error> {
1658        self.checked_signed_diff(other).ok_or_else(|| {
1659            Error::new(format!(
1660                "failed to compute signed_diff({:?}, {:?}): {} overflow",
1661                self, other, "i64"
1662            ))
1663        })
1664    }
1665}
1666impl CsignedDiff for u128 {
1667    type Other = u128;
1668    type Output = i128;
1669    type Error = Error;
1670    ///Checked subtraction:  computes `signed_diff(a, b)`, returning an error if overflow occured.
1671    ///
1672    ///Wrapper for [`u128::checked_signed_diff`].
1673    #[inline]
1674    fn csigned_diff(self, other: u128) -> Result<i128, Error> {
1675        self.checked_signed_diff(other).ok_or_else(|| {
1676            Error::new(format!(
1677                "failed to compute signed_diff({:?}, {:?}): {} overflow",
1678                self, other, "i128"
1679            ))
1680        })
1681    }
1682}
1683impl CsignedDiff for usize {
1684    type Other = usize;
1685    type Output = isize;
1686    type Error = Error;
1687    ///Checked subtraction:  computes `signed_diff(a, b)`, returning an error if overflow occured.
1688    ///
1689    ///Wrapper for [`usize::checked_signed_diff`].
1690    #[inline]
1691    fn csigned_diff(self, other: usize) -> Result<isize, Error> {
1692        self.checked_signed_diff(other).ok_or_else(|| {
1693            Error::new(format!(
1694                "failed to compute signed_diff({:?}, {:?}): {} overflow",
1695                self, other, "isize"
1696            ))
1697        })
1698    }
1699}
1700///Checked negation: computes `-value`, returning an error if overflow occured.
1701///
1702///See also: [module documentation](self).
1703pub trait Cneg: Sized {
1704    #[expect(missing_docs, reason = "no need for doc")]
1705    type Output;
1706    #[expect(missing_docs, reason = "no need for doc")]
1707    type Error;
1708    ///Checked negation: computes `-value`, returning an error if overflow occured.
1709    ///
1710    ///Wrapper for `checked_neg`.
1711    fn cneg(self) -> Result<Self::Output, Self::Error>;
1712}
1713///Checked negation: computes `-value`, returning an error if overflow occured.
1714///
1715///Wrapper for `checked_neg`.
1716#[doc(alias = "checked_neg")]
1717#[inline]
1718pub fn cneg<T>(value: T) -> Result<T::Output, T::Error>
1719where
1720    T: Cneg,
1721{
1722    Cneg::cneg(value)
1723}
1724impl Cneg for NonZero<i8> {
1725    type Output = NonZero<i8>;
1726    type Error = Error;
1727    ///Checked negation: computes `-value`, returning an error if overflow occured.
1728    ///
1729    ///Wrapper for [`NonZero<i8>::checked_neg`].
1730    #[inline]
1731    fn cneg(self) -> Result<NonZero<i8>, Error> {
1732        self.checked_neg().ok_or_else(|| {
1733            Error::new(format!(
1734                "failed to compute -({:?}): {} overflow",
1735                self, "NonZero<i8>"
1736            ))
1737        })
1738    }
1739}
1740impl Cneg for NonZero<i16> {
1741    type Output = NonZero<i16>;
1742    type Error = Error;
1743    ///Checked negation: computes `-value`, returning an error if overflow occured.
1744    ///
1745    ///Wrapper for [`NonZero<i16>::checked_neg`].
1746    #[inline]
1747    fn cneg(self) -> Result<NonZero<i16>, Error> {
1748        self.checked_neg().ok_or_else(|| {
1749            Error::new(format!(
1750                "failed to compute -({:?}): {} overflow",
1751                self, "NonZero<i16>"
1752            ))
1753        })
1754    }
1755}
1756impl Cneg for NonZero<i32> {
1757    type Output = NonZero<i32>;
1758    type Error = Error;
1759    ///Checked negation: computes `-value`, returning an error if overflow occured.
1760    ///
1761    ///Wrapper for [`NonZero<i32>::checked_neg`].
1762    #[inline]
1763    fn cneg(self) -> Result<NonZero<i32>, Error> {
1764        self.checked_neg().ok_or_else(|| {
1765            Error::new(format!(
1766                "failed to compute -({:?}): {} overflow",
1767                self, "NonZero<i32>"
1768            ))
1769        })
1770    }
1771}
1772impl Cneg for NonZero<i64> {
1773    type Output = NonZero<i64>;
1774    type Error = Error;
1775    ///Checked negation: computes `-value`, returning an error if overflow occured.
1776    ///
1777    ///Wrapper for [`NonZero<i64>::checked_neg`].
1778    #[inline]
1779    fn cneg(self) -> Result<NonZero<i64>, Error> {
1780        self.checked_neg().ok_or_else(|| {
1781            Error::new(format!(
1782                "failed to compute -({:?}): {} overflow",
1783                self, "NonZero<i64>"
1784            ))
1785        })
1786    }
1787}
1788impl Cneg for NonZero<i128> {
1789    type Output = NonZero<i128>;
1790    type Error = Error;
1791    ///Checked negation: computes `-value`, returning an error if overflow occured.
1792    ///
1793    ///Wrapper for [`NonZero<i128>::checked_neg`].
1794    #[inline]
1795    fn cneg(self) -> Result<NonZero<i128>, Error> {
1796        self.checked_neg().ok_or_else(|| {
1797            Error::new(format!(
1798                "failed to compute -({:?}): {} overflow",
1799                self, "NonZero<i128>"
1800            ))
1801        })
1802    }
1803}
1804impl Cneg for NonZero<isize> {
1805    type Output = NonZero<isize>;
1806    type Error = Error;
1807    ///Checked negation: computes `-value`, returning an error if overflow occured.
1808    ///
1809    ///Wrapper for [`NonZero<isize>::checked_neg`].
1810    #[inline]
1811    fn cneg(self) -> Result<NonZero<isize>, Error> {
1812        self.checked_neg().ok_or_else(|| {
1813            Error::new(format!(
1814                "failed to compute -({:?}): {} overflow",
1815                self, "NonZero<isize>"
1816            ))
1817        })
1818    }
1819}
1820impl Cneg for i8 {
1821    type Output = i8;
1822    type Error = Error;
1823    ///Checked negation: computes `-value`, returning an error if overflow occured.
1824    ///
1825    ///Wrapper for [`i8::checked_neg`].
1826    #[inline]
1827    fn cneg(self) -> Result<i8, Error> {
1828        self.checked_neg().ok_or_else(|| {
1829            Error::new(format!(
1830                "failed to compute -({:?}): {} overflow",
1831                self, "i8"
1832            ))
1833        })
1834    }
1835}
1836impl Cneg for i16 {
1837    type Output = i16;
1838    type Error = Error;
1839    ///Checked negation: computes `-value`, returning an error if overflow occured.
1840    ///
1841    ///Wrapper for [`i16::checked_neg`].
1842    #[inline]
1843    fn cneg(self) -> Result<i16, Error> {
1844        self.checked_neg().ok_or_else(|| {
1845            Error::new(format!(
1846                "failed to compute -({:?}): {} overflow",
1847                self, "i16"
1848            ))
1849        })
1850    }
1851}
1852impl Cneg for i32 {
1853    type Output = i32;
1854    type Error = Error;
1855    ///Checked negation: computes `-value`, returning an error if overflow occured.
1856    ///
1857    ///Wrapper for [`i32::checked_neg`].
1858    #[inline]
1859    fn cneg(self) -> Result<i32, Error> {
1860        self.checked_neg().ok_or_else(|| {
1861            Error::new(format!(
1862                "failed to compute -({:?}): {} overflow",
1863                self, "i32"
1864            ))
1865        })
1866    }
1867}
1868impl Cneg for i64 {
1869    type Output = i64;
1870    type Error = Error;
1871    ///Checked negation: computes `-value`, returning an error if overflow occured.
1872    ///
1873    ///Wrapper for [`i64::checked_neg`].
1874    #[inline]
1875    fn cneg(self) -> Result<i64, Error> {
1876        self.checked_neg().ok_or_else(|| {
1877            Error::new(format!(
1878                "failed to compute -({:?}): {} overflow",
1879                self, "i64"
1880            ))
1881        })
1882    }
1883}
1884impl Cneg for i128 {
1885    type Output = i128;
1886    type Error = Error;
1887    ///Checked negation: computes `-value`, returning an error if overflow occured.
1888    ///
1889    ///Wrapper for [`i128::checked_neg`].
1890    #[inline]
1891    fn cneg(self) -> Result<i128, Error> {
1892        self.checked_neg().ok_or_else(|| {
1893            Error::new(format!(
1894                "failed to compute -({:?}): {} overflow",
1895                self, "i128"
1896            ))
1897        })
1898    }
1899}
1900impl Cneg for isize {
1901    type Output = isize;
1902    type Error = Error;
1903    ///Checked negation: computes `-value`, returning an error if overflow occured.
1904    ///
1905    ///Wrapper for [`isize::checked_neg`].
1906    #[inline]
1907    fn cneg(self) -> Result<isize, Error> {
1908        self.checked_neg().ok_or_else(|| {
1909            Error::new(format!(
1910                "failed to compute -({:?}): {} overflow",
1911                self, "isize"
1912            ))
1913        })
1914    }
1915}
1916impl Cneg for u8 {
1917    type Output = u8;
1918    type Error = Error;
1919    ///Checked negation: computes `-value`, returning an error if overflow occured.
1920    ///
1921    ///Wrapper for [`u8::checked_neg`].
1922    #[inline]
1923    fn cneg(self) -> Result<u8, Error> {
1924        self.checked_neg().ok_or_else(|| {
1925            Error::new(format!(
1926                "failed to compute -({:?}): {} overflow",
1927                self, "u8"
1928            ))
1929        })
1930    }
1931}
1932impl Cneg for u16 {
1933    type Output = u16;
1934    type Error = Error;
1935    ///Checked negation: computes `-value`, returning an error if overflow occured.
1936    ///
1937    ///Wrapper for [`u16::checked_neg`].
1938    #[inline]
1939    fn cneg(self) -> Result<u16, Error> {
1940        self.checked_neg().ok_or_else(|| {
1941            Error::new(format!(
1942                "failed to compute -({:?}): {} overflow",
1943                self, "u16"
1944            ))
1945        })
1946    }
1947}
1948impl Cneg for u32 {
1949    type Output = u32;
1950    type Error = Error;
1951    ///Checked negation: computes `-value`, returning an error if overflow occured.
1952    ///
1953    ///Wrapper for [`u32::checked_neg`].
1954    #[inline]
1955    fn cneg(self) -> Result<u32, Error> {
1956        self.checked_neg().ok_or_else(|| {
1957            Error::new(format!(
1958                "failed to compute -({:?}): {} overflow",
1959                self, "u32"
1960            ))
1961        })
1962    }
1963}
1964impl Cneg for u64 {
1965    type Output = u64;
1966    type Error = Error;
1967    ///Checked negation: computes `-value`, returning an error if overflow occured.
1968    ///
1969    ///Wrapper for [`u64::checked_neg`].
1970    #[inline]
1971    fn cneg(self) -> Result<u64, Error> {
1972        self.checked_neg().ok_or_else(|| {
1973            Error::new(format!(
1974                "failed to compute -({:?}): {} overflow",
1975                self, "u64"
1976            ))
1977        })
1978    }
1979}
1980impl Cneg for u128 {
1981    type Output = u128;
1982    type Error = Error;
1983    ///Checked negation: computes `-value`, returning an error if overflow occured.
1984    ///
1985    ///Wrapper for [`u128::checked_neg`].
1986    #[inline]
1987    fn cneg(self) -> Result<u128, Error> {
1988        self.checked_neg().ok_or_else(|| {
1989            Error::new(format!(
1990                "failed to compute -({:?}): {} overflow",
1991                self, "u128"
1992            ))
1993        })
1994    }
1995}
1996impl Cneg for usize {
1997    type Output = usize;
1998    type Error = Error;
1999    ///Checked negation: computes `-value`, returning an error if overflow occured.
2000    ///
2001    ///Wrapper for [`usize::checked_neg`].
2002    #[inline]
2003    fn cneg(self) -> Result<usize, Error> {
2004        self.checked_neg().ok_or_else(|| {
2005            Error::new(format!(
2006                "failed to compute -({:?}): {} overflow",
2007                self, "usize"
2008            ))
2009        })
2010    }
2011}
2012///Checked multiplication: computes `a * b`, returning an error if overflow occured.
2013///
2014///See also: [module documentation](self).
2015pub trait Cmul: Sized {
2016    #[expect(missing_docs, reason = "no need for doc")]
2017    type Other;
2018    #[expect(missing_docs, reason = "no need for doc")]
2019    type Output;
2020    #[expect(missing_docs, reason = "no need for doc")]
2021    type Error;
2022    ///Checked multiplication: computes `a * b`, returning an error if overflow occured.
2023    ///
2024    ///Wrapper for `checked_mul`.
2025    fn cmul(self, other: Self::Other) -> Result<Self::Output, Self::Error>;
2026    ///Checked multiplication assigement: executes `self *= other`, returning an error if overflow occured.
2027    ///
2028    ///Wrapper for `checked_mul`.
2029    fn cmul_assign(&mut self, other: Self::Other) -> Result<(), Self::Error>;
2030}
2031///Checked multiplication: computes `a * b`, returning an error if overflow occured.
2032///
2033///Wrapper for `checked_mul`.
2034///
2035///See also: [module documentation](self).
2036#[doc(alias = "checked_mul")]
2037#[inline]
2038pub fn cmul<T>(a: T, b: T::Other) -> Result<T::Output, T::Error>
2039where
2040    T: Cmul,
2041{
2042    a.cmul(b)
2043}
2044impl Cmul for NonZero<u8> {
2045    type Other = NonZero<u8>;
2046    type Output = NonZero<u8>;
2047    type Error = Error;
2048    ///Checked multiplication: computes `a * b`, returning an error if overflow occured.
2049    ///
2050    ///Wrapper for [`NonZero<u8>::checked_mul`].
2051    #[inline]
2052    fn cmul(self, other: NonZero<u8>) -> Result<NonZero<u8>, Error> {
2053        self.checked_mul(other).ok_or_else(|| {
2054            Error::new(format!(
2055                "failed to compute {:?} * {:?}: {} overflow",
2056                self,
2057                MaybeParens(other),
2058                "NonZero<u8>"
2059            ))
2060        })
2061    }
2062    #[inline]
2063    ///Checked multiplication assigement: executes `self *= other`, returning an error if overflow occured.
2064    ///
2065    ///Wrapper for [`NonZero<u8>::checked_mul`].
2066    fn cmul_assign(&mut self, other: NonZero<u8>) -> Result<(), Self::Error> {
2067        *self = self.cmul(other)?;
2068        Ok(())
2069    }
2070}
2071impl Cmul for NonZero<u16> {
2072    type Other = NonZero<u16>;
2073    type Output = NonZero<u16>;
2074    type Error = Error;
2075    ///Checked multiplication: computes `a * b`, returning an error if overflow occured.
2076    ///
2077    ///Wrapper for [`NonZero<u16>::checked_mul`].
2078    #[inline]
2079    fn cmul(self, other: NonZero<u16>) -> Result<NonZero<u16>, Error> {
2080        self.checked_mul(other).ok_or_else(|| {
2081            Error::new(format!(
2082                "failed to compute {:?} * {:?}: {} overflow",
2083                self,
2084                MaybeParens(other),
2085                "NonZero<u16>"
2086            ))
2087        })
2088    }
2089    #[inline]
2090    ///Checked multiplication assigement: executes `self *= other`, returning an error if overflow occured.
2091    ///
2092    ///Wrapper for [`NonZero<u16>::checked_mul`].
2093    fn cmul_assign(&mut self, other: NonZero<u16>) -> Result<(), Self::Error> {
2094        *self = self.cmul(other)?;
2095        Ok(())
2096    }
2097}
2098impl Cmul for NonZero<u32> {
2099    type Other = NonZero<u32>;
2100    type Output = NonZero<u32>;
2101    type Error = Error;
2102    ///Checked multiplication: computes `a * b`, returning an error if overflow occured.
2103    ///
2104    ///Wrapper for [`NonZero<u32>::checked_mul`].
2105    #[inline]
2106    fn cmul(self, other: NonZero<u32>) -> Result<NonZero<u32>, Error> {
2107        self.checked_mul(other).ok_or_else(|| {
2108            Error::new(format!(
2109                "failed to compute {:?} * {:?}: {} overflow",
2110                self,
2111                MaybeParens(other),
2112                "NonZero<u32>"
2113            ))
2114        })
2115    }
2116    #[inline]
2117    ///Checked multiplication assigement: executes `self *= other`, returning an error if overflow occured.
2118    ///
2119    ///Wrapper for [`NonZero<u32>::checked_mul`].
2120    fn cmul_assign(&mut self, other: NonZero<u32>) -> Result<(), Self::Error> {
2121        *self = self.cmul(other)?;
2122        Ok(())
2123    }
2124}
2125impl Cmul for NonZero<u64> {
2126    type Other = NonZero<u64>;
2127    type Output = NonZero<u64>;
2128    type Error = Error;
2129    ///Checked multiplication: computes `a * b`, returning an error if overflow occured.
2130    ///
2131    ///Wrapper for [`NonZero<u64>::checked_mul`].
2132    #[inline]
2133    fn cmul(self, other: NonZero<u64>) -> Result<NonZero<u64>, Error> {
2134        self.checked_mul(other).ok_or_else(|| {
2135            Error::new(format!(
2136                "failed to compute {:?} * {:?}: {} overflow",
2137                self,
2138                MaybeParens(other),
2139                "NonZero<u64>"
2140            ))
2141        })
2142    }
2143    #[inline]
2144    ///Checked multiplication assigement: executes `self *= other`, returning an error if overflow occured.
2145    ///
2146    ///Wrapper for [`NonZero<u64>::checked_mul`].
2147    fn cmul_assign(&mut self, other: NonZero<u64>) -> Result<(), Self::Error> {
2148        *self = self.cmul(other)?;
2149        Ok(())
2150    }
2151}
2152impl Cmul for NonZero<u128> {
2153    type Other = NonZero<u128>;
2154    type Output = NonZero<u128>;
2155    type Error = Error;
2156    ///Checked multiplication: computes `a * b`, returning an error if overflow occured.
2157    ///
2158    ///Wrapper for [`NonZero<u128>::checked_mul`].
2159    #[inline]
2160    fn cmul(self, other: NonZero<u128>) -> Result<NonZero<u128>, Error> {
2161        self.checked_mul(other).ok_or_else(|| {
2162            Error::new(format!(
2163                "failed to compute {:?} * {:?}: {} overflow",
2164                self,
2165                MaybeParens(other),
2166                "NonZero<u128>"
2167            ))
2168        })
2169    }
2170    #[inline]
2171    ///Checked multiplication assigement: executes `self *= other`, returning an error if overflow occured.
2172    ///
2173    ///Wrapper for [`NonZero<u128>::checked_mul`].
2174    fn cmul_assign(&mut self, other: NonZero<u128>) -> Result<(), Self::Error> {
2175        *self = self.cmul(other)?;
2176        Ok(())
2177    }
2178}
2179impl Cmul for NonZero<usize> {
2180    type Other = NonZero<usize>;
2181    type Output = NonZero<usize>;
2182    type Error = Error;
2183    ///Checked multiplication: computes `a * b`, returning an error if overflow occured.
2184    ///
2185    ///Wrapper for [`NonZero<usize>::checked_mul`].
2186    #[inline]
2187    fn cmul(self, other: NonZero<usize>) -> Result<NonZero<usize>, Error> {
2188        self.checked_mul(other).ok_or_else(|| {
2189            Error::new(format!(
2190                "failed to compute {:?} * {:?}: {} overflow",
2191                self,
2192                MaybeParens(other),
2193                "NonZero<usize>"
2194            ))
2195        })
2196    }
2197    #[inline]
2198    ///Checked multiplication assigement: executes `self *= other`, returning an error if overflow occured.
2199    ///
2200    ///Wrapper for [`NonZero<usize>::checked_mul`].
2201    fn cmul_assign(&mut self, other: NonZero<usize>) -> Result<(), Self::Error> {
2202        *self = self.cmul(other)?;
2203        Ok(())
2204    }
2205}
2206impl Cmul for NonZero<i8> {
2207    type Other = NonZero<i8>;
2208    type Output = NonZero<i8>;
2209    type Error = Error;
2210    ///Checked multiplication: computes `a * b`, returning an error if overflow occured.
2211    ///
2212    ///Wrapper for [`NonZero<i8>::checked_mul`].
2213    #[inline]
2214    fn cmul(self, other: NonZero<i8>) -> Result<NonZero<i8>, Error> {
2215        self.checked_mul(other).ok_or_else(|| {
2216            Error::new(format!(
2217                "failed to compute {:?} * {:?}: {} overflow",
2218                self,
2219                MaybeParens(other),
2220                "NonZero<i8>"
2221            ))
2222        })
2223    }
2224    #[inline]
2225    ///Checked multiplication assigement: executes `self *= other`, returning an error if overflow occured.
2226    ///
2227    ///Wrapper for [`NonZero<i8>::checked_mul`].
2228    fn cmul_assign(&mut self, other: NonZero<i8>) -> Result<(), Self::Error> {
2229        *self = self.cmul(other)?;
2230        Ok(())
2231    }
2232}
2233impl Cmul for NonZero<i16> {
2234    type Other = NonZero<i16>;
2235    type Output = NonZero<i16>;
2236    type Error = Error;
2237    ///Checked multiplication: computes `a * b`, returning an error if overflow occured.
2238    ///
2239    ///Wrapper for [`NonZero<i16>::checked_mul`].
2240    #[inline]
2241    fn cmul(self, other: NonZero<i16>) -> Result<NonZero<i16>, Error> {
2242        self.checked_mul(other).ok_or_else(|| {
2243            Error::new(format!(
2244                "failed to compute {:?} * {:?}: {} overflow",
2245                self,
2246                MaybeParens(other),
2247                "NonZero<i16>"
2248            ))
2249        })
2250    }
2251    #[inline]
2252    ///Checked multiplication assigement: executes `self *= other`, returning an error if overflow occured.
2253    ///
2254    ///Wrapper for [`NonZero<i16>::checked_mul`].
2255    fn cmul_assign(&mut self, other: NonZero<i16>) -> Result<(), Self::Error> {
2256        *self = self.cmul(other)?;
2257        Ok(())
2258    }
2259}
2260impl Cmul for NonZero<i32> {
2261    type Other = NonZero<i32>;
2262    type Output = NonZero<i32>;
2263    type Error = Error;
2264    ///Checked multiplication: computes `a * b`, returning an error if overflow occured.
2265    ///
2266    ///Wrapper for [`NonZero<i32>::checked_mul`].
2267    #[inline]
2268    fn cmul(self, other: NonZero<i32>) -> Result<NonZero<i32>, Error> {
2269        self.checked_mul(other).ok_or_else(|| {
2270            Error::new(format!(
2271                "failed to compute {:?} * {:?}: {} overflow",
2272                self,
2273                MaybeParens(other),
2274                "NonZero<i32>"
2275            ))
2276        })
2277    }
2278    #[inline]
2279    ///Checked multiplication assigement: executes `self *= other`, returning an error if overflow occured.
2280    ///
2281    ///Wrapper for [`NonZero<i32>::checked_mul`].
2282    fn cmul_assign(&mut self, other: NonZero<i32>) -> Result<(), Self::Error> {
2283        *self = self.cmul(other)?;
2284        Ok(())
2285    }
2286}
2287impl Cmul for NonZero<i64> {
2288    type Other = NonZero<i64>;
2289    type Output = NonZero<i64>;
2290    type Error = Error;
2291    ///Checked multiplication: computes `a * b`, returning an error if overflow occured.
2292    ///
2293    ///Wrapper for [`NonZero<i64>::checked_mul`].
2294    #[inline]
2295    fn cmul(self, other: NonZero<i64>) -> Result<NonZero<i64>, Error> {
2296        self.checked_mul(other).ok_or_else(|| {
2297            Error::new(format!(
2298                "failed to compute {:?} * {:?}: {} overflow",
2299                self,
2300                MaybeParens(other),
2301                "NonZero<i64>"
2302            ))
2303        })
2304    }
2305    #[inline]
2306    ///Checked multiplication assigement: executes `self *= other`, returning an error if overflow occured.
2307    ///
2308    ///Wrapper for [`NonZero<i64>::checked_mul`].
2309    fn cmul_assign(&mut self, other: NonZero<i64>) -> Result<(), Self::Error> {
2310        *self = self.cmul(other)?;
2311        Ok(())
2312    }
2313}
2314impl Cmul for NonZero<i128> {
2315    type Other = NonZero<i128>;
2316    type Output = NonZero<i128>;
2317    type Error = Error;
2318    ///Checked multiplication: computes `a * b`, returning an error if overflow occured.
2319    ///
2320    ///Wrapper for [`NonZero<i128>::checked_mul`].
2321    #[inline]
2322    fn cmul(self, other: NonZero<i128>) -> Result<NonZero<i128>, Error> {
2323        self.checked_mul(other).ok_or_else(|| {
2324            Error::new(format!(
2325                "failed to compute {:?} * {:?}: {} overflow",
2326                self,
2327                MaybeParens(other),
2328                "NonZero<i128>"
2329            ))
2330        })
2331    }
2332    #[inline]
2333    ///Checked multiplication assigement: executes `self *= other`, returning an error if overflow occured.
2334    ///
2335    ///Wrapper for [`NonZero<i128>::checked_mul`].
2336    fn cmul_assign(&mut self, other: NonZero<i128>) -> Result<(), Self::Error> {
2337        *self = self.cmul(other)?;
2338        Ok(())
2339    }
2340}
2341impl Cmul for NonZero<isize> {
2342    type Other = NonZero<isize>;
2343    type Output = NonZero<isize>;
2344    type Error = Error;
2345    ///Checked multiplication: computes `a * b`, returning an error if overflow occured.
2346    ///
2347    ///Wrapper for [`NonZero<isize>::checked_mul`].
2348    #[inline]
2349    fn cmul(self, other: NonZero<isize>) -> Result<NonZero<isize>, Error> {
2350        self.checked_mul(other).ok_or_else(|| {
2351            Error::new(format!(
2352                "failed to compute {:?} * {:?}: {} overflow",
2353                self,
2354                MaybeParens(other),
2355                "NonZero<isize>"
2356            ))
2357        })
2358    }
2359    #[inline]
2360    ///Checked multiplication assigement: executes `self *= other`, returning an error if overflow occured.
2361    ///
2362    ///Wrapper for [`NonZero<isize>::checked_mul`].
2363    fn cmul_assign(&mut self, other: NonZero<isize>) -> Result<(), Self::Error> {
2364        *self = self.cmul(other)?;
2365        Ok(())
2366    }
2367}
2368impl Cmul for i8 {
2369    type Other = i8;
2370    type Output = i8;
2371    type Error = Error;
2372    ///Checked multiplication: computes `a * b`, returning an error if overflow occured.
2373    ///
2374    ///Wrapper for [`i8::checked_mul`].
2375    #[inline]
2376    fn cmul(self, other: i8) -> Result<i8, Error> {
2377        self.checked_mul(other).ok_or_else(|| {
2378            Error::new(format!(
2379                "failed to compute {:?} * {:?}: {} overflow",
2380                self,
2381                MaybeParens(other),
2382                "i8"
2383            ))
2384        })
2385    }
2386    #[inline]
2387    ///Checked multiplication assigement: executes `self *= other`, returning an error if overflow occured.
2388    ///
2389    ///Wrapper for [`i8::checked_mul`].
2390    fn cmul_assign(&mut self, other: i8) -> Result<(), Self::Error> {
2391        *self = self.cmul(other)?;
2392        Ok(())
2393    }
2394}
2395impl Cmul for i16 {
2396    type Other = i16;
2397    type Output = i16;
2398    type Error = Error;
2399    ///Checked multiplication: computes `a * b`, returning an error if overflow occured.
2400    ///
2401    ///Wrapper for [`i16::checked_mul`].
2402    #[inline]
2403    fn cmul(self, other: i16) -> Result<i16, Error> {
2404        self.checked_mul(other).ok_or_else(|| {
2405            Error::new(format!(
2406                "failed to compute {:?} * {:?}: {} overflow",
2407                self,
2408                MaybeParens(other),
2409                "i16"
2410            ))
2411        })
2412    }
2413    #[inline]
2414    ///Checked multiplication assigement: executes `self *= other`, returning an error if overflow occured.
2415    ///
2416    ///Wrapper for [`i16::checked_mul`].
2417    fn cmul_assign(&mut self, other: i16) -> Result<(), Self::Error> {
2418        *self = self.cmul(other)?;
2419        Ok(())
2420    }
2421}
2422impl Cmul for i32 {
2423    type Other = i32;
2424    type Output = i32;
2425    type Error = Error;
2426    ///Checked multiplication: computes `a * b`, returning an error if overflow occured.
2427    ///
2428    ///Wrapper for [`i32::checked_mul`].
2429    #[inline]
2430    fn cmul(self, other: i32) -> Result<i32, Error> {
2431        self.checked_mul(other).ok_or_else(|| {
2432            Error::new(format!(
2433                "failed to compute {:?} * {:?}: {} overflow",
2434                self,
2435                MaybeParens(other),
2436                "i32"
2437            ))
2438        })
2439    }
2440    #[inline]
2441    ///Checked multiplication assigement: executes `self *= other`, returning an error if overflow occured.
2442    ///
2443    ///Wrapper for [`i32::checked_mul`].
2444    fn cmul_assign(&mut self, other: i32) -> Result<(), Self::Error> {
2445        *self = self.cmul(other)?;
2446        Ok(())
2447    }
2448}
2449impl Cmul for i64 {
2450    type Other = i64;
2451    type Output = i64;
2452    type Error = Error;
2453    ///Checked multiplication: computes `a * b`, returning an error if overflow occured.
2454    ///
2455    ///Wrapper for [`i64::checked_mul`].
2456    #[inline]
2457    fn cmul(self, other: i64) -> Result<i64, Error> {
2458        self.checked_mul(other).ok_or_else(|| {
2459            Error::new(format!(
2460                "failed to compute {:?} * {:?}: {} overflow",
2461                self,
2462                MaybeParens(other),
2463                "i64"
2464            ))
2465        })
2466    }
2467    #[inline]
2468    ///Checked multiplication assigement: executes `self *= other`, returning an error if overflow occured.
2469    ///
2470    ///Wrapper for [`i64::checked_mul`].
2471    fn cmul_assign(&mut self, other: i64) -> Result<(), Self::Error> {
2472        *self = self.cmul(other)?;
2473        Ok(())
2474    }
2475}
2476impl Cmul for i128 {
2477    type Other = i128;
2478    type Output = i128;
2479    type Error = Error;
2480    ///Checked multiplication: computes `a * b`, returning an error if overflow occured.
2481    ///
2482    ///Wrapper for [`i128::checked_mul`].
2483    #[inline]
2484    fn cmul(self, other: i128) -> Result<i128, Error> {
2485        self.checked_mul(other).ok_or_else(|| {
2486            Error::new(format!(
2487                "failed to compute {:?} * {:?}: {} overflow",
2488                self,
2489                MaybeParens(other),
2490                "i128"
2491            ))
2492        })
2493    }
2494    #[inline]
2495    ///Checked multiplication assigement: executes `self *= other`, returning an error if overflow occured.
2496    ///
2497    ///Wrapper for [`i128::checked_mul`].
2498    fn cmul_assign(&mut self, other: i128) -> Result<(), Self::Error> {
2499        *self = self.cmul(other)?;
2500        Ok(())
2501    }
2502}
2503impl Cmul for isize {
2504    type Other = isize;
2505    type Output = isize;
2506    type Error = Error;
2507    ///Checked multiplication: computes `a * b`, returning an error if overflow occured.
2508    ///
2509    ///Wrapper for [`isize::checked_mul`].
2510    #[inline]
2511    fn cmul(self, other: isize) -> Result<isize, Error> {
2512        self.checked_mul(other).ok_or_else(|| {
2513            Error::new(format!(
2514                "failed to compute {:?} * {:?}: {} overflow",
2515                self,
2516                MaybeParens(other),
2517                "isize"
2518            ))
2519        })
2520    }
2521    #[inline]
2522    ///Checked multiplication assigement: executes `self *= other`, returning an error if overflow occured.
2523    ///
2524    ///Wrapper for [`isize::checked_mul`].
2525    fn cmul_assign(&mut self, other: isize) -> Result<(), Self::Error> {
2526        *self = self.cmul(other)?;
2527        Ok(())
2528    }
2529}
2530impl Cmul for u8 {
2531    type Other = u8;
2532    type Output = u8;
2533    type Error = Error;
2534    ///Checked multiplication: computes `a * b`, returning an error if overflow occured.
2535    ///
2536    ///Wrapper for [`u8::checked_mul`].
2537    #[inline]
2538    fn cmul(self, other: u8) -> Result<u8, Error> {
2539        self.checked_mul(other).ok_or_else(|| {
2540            Error::new(format!(
2541                "failed to compute {:?} * {:?}: {} overflow",
2542                self,
2543                MaybeParens(other),
2544                "u8"
2545            ))
2546        })
2547    }
2548    #[inline]
2549    ///Checked multiplication assigement: executes `self *= other`, returning an error if overflow occured.
2550    ///
2551    ///Wrapper for [`u8::checked_mul`].
2552    fn cmul_assign(&mut self, other: u8) -> Result<(), Self::Error> {
2553        *self = self.cmul(other)?;
2554        Ok(())
2555    }
2556}
2557impl Cmul for u16 {
2558    type Other = u16;
2559    type Output = u16;
2560    type Error = Error;
2561    ///Checked multiplication: computes `a * b`, returning an error if overflow occured.
2562    ///
2563    ///Wrapper for [`u16::checked_mul`].
2564    #[inline]
2565    fn cmul(self, other: u16) -> Result<u16, Error> {
2566        self.checked_mul(other).ok_or_else(|| {
2567            Error::new(format!(
2568                "failed to compute {:?} * {:?}: {} overflow",
2569                self,
2570                MaybeParens(other),
2571                "u16"
2572            ))
2573        })
2574    }
2575    #[inline]
2576    ///Checked multiplication assigement: executes `self *= other`, returning an error if overflow occured.
2577    ///
2578    ///Wrapper for [`u16::checked_mul`].
2579    fn cmul_assign(&mut self, other: u16) -> Result<(), Self::Error> {
2580        *self = self.cmul(other)?;
2581        Ok(())
2582    }
2583}
2584impl Cmul for u32 {
2585    type Other = u32;
2586    type Output = u32;
2587    type Error = Error;
2588    ///Checked multiplication: computes `a * b`, returning an error if overflow occured.
2589    ///
2590    ///Wrapper for [`u32::checked_mul`].
2591    #[inline]
2592    fn cmul(self, other: u32) -> Result<u32, Error> {
2593        self.checked_mul(other).ok_or_else(|| {
2594            Error::new(format!(
2595                "failed to compute {:?} * {:?}: {} overflow",
2596                self,
2597                MaybeParens(other),
2598                "u32"
2599            ))
2600        })
2601    }
2602    #[inline]
2603    ///Checked multiplication assigement: executes `self *= other`, returning an error if overflow occured.
2604    ///
2605    ///Wrapper for [`u32::checked_mul`].
2606    fn cmul_assign(&mut self, other: u32) -> Result<(), Self::Error> {
2607        *self = self.cmul(other)?;
2608        Ok(())
2609    }
2610}
2611impl Cmul for u64 {
2612    type Other = u64;
2613    type Output = u64;
2614    type Error = Error;
2615    ///Checked multiplication: computes `a * b`, returning an error if overflow occured.
2616    ///
2617    ///Wrapper for [`u64::checked_mul`].
2618    #[inline]
2619    fn cmul(self, other: u64) -> Result<u64, Error> {
2620        self.checked_mul(other).ok_or_else(|| {
2621            Error::new(format!(
2622                "failed to compute {:?} * {:?}: {} overflow",
2623                self,
2624                MaybeParens(other),
2625                "u64"
2626            ))
2627        })
2628    }
2629    #[inline]
2630    ///Checked multiplication assigement: executes `self *= other`, returning an error if overflow occured.
2631    ///
2632    ///Wrapper for [`u64::checked_mul`].
2633    fn cmul_assign(&mut self, other: u64) -> Result<(), Self::Error> {
2634        *self = self.cmul(other)?;
2635        Ok(())
2636    }
2637}
2638impl Cmul for u128 {
2639    type Other = u128;
2640    type Output = u128;
2641    type Error = Error;
2642    ///Checked multiplication: computes `a * b`, returning an error if overflow occured.
2643    ///
2644    ///Wrapper for [`u128::checked_mul`].
2645    #[inline]
2646    fn cmul(self, other: u128) -> Result<u128, Error> {
2647        self.checked_mul(other).ok_or_else(|| {
2648            Error::new(format!(
2649                "failed to compute {:?} * {:?}: {} overflow",
2650                self,
2651                MaybeParens(other),
2652                "u128"
2653            ))
2654        })
2655    }
2656    #[inline]
2657    ///Checked multiplication assigement: executes `self *= other`, returning an error if overflow occured.
2658    ///
2659    ///Wrapper for [`u128::checked_mul`].
2660    fn cmul_assign(&mut self, other: u128) -> Result<(), Self::Error> {
2661        *self = self.cmul(other)?;
2662        Ok(())
2663    }
2664}
2665impl Cmul for usize {
2666    type Other = usize;
2667    type Output = usize;
2668    type Error = Error;
2669    ///Checked multiplication: computes `a * b`, returning an error if overflow occured.
2670    ///
2671    ///Wrapper for [`usize::checked_mul`].
2672    #[inline]
2673    fn cmul(self, other: usize) -> Result<usize, Error> {
2674        self.checked_mul(other).ok_or_else(|| {
2675            Error::new(format!(
2676                "failed to compute {:?} * {:?}: {} overflow",
2677                self,
2678                MaybeParens(other),
2679                "usize"
2680            ))
2681        })
2682    }
2683    #[inline]
2684    ///Checked multiplication assigement: executes `self *= other`, returning an error if overflow occured.
2685    ///
2686    ///Wrapper for [`usize::checked_mul`].
2687    fn cmul_assign(&mut self, other: usize) -> Result<(), Self::Error> {
2688        *self = self.cmul(other)?;
2689        Ok(())
2690    }
2691}
2692impl Cmul for Duration {
2693    type Other = u32;
2694    type Output = Duration;
2695    type Error = Error;
2696    ///Checked multiplication: computes `a * b`, returning an error if overflow occured.
2697    ///
2698    ///Wrapper for [`Duration::checked_mul`].
2699    #[inline]
2700    fn cmul(self, other: u32) -> Result<Duration, Error> {
2701        self.checked_mul(other).ok_or_else(|| {
2702            Error::new(format!(
2703                "failed to compute {:?} * {:?}: {} overflow",
2704                self,
2705                MaybeParens(other),
2706                "Duration"
2707            ))
2708        })
2709    }
2710    #[inline]
2711    ///Checked multiplication assigement: executes `self *= other`, returning an error if overflow occured.
2712    ///
2713    ///Wrapper for [`Duration::checked_mul`].
2714    fn cmul_assign(&mut self, other: u32) -> Result<(), Self::Error> {
2715        *self = self.cmul(other)?;
2716        Ok(())
2717    }
2718}
2719///Checked division: computes `value / divisor`, returning an error if overflow occured or if `divisor` is zero.
2720///
2721///See also: [module documentation](self).
2722pub trait Cdiv: Sized {
2723    #[expect(missing_docs, reason = "no need for doc")]
2724    type Divisor;
2725    #[expect(missing_docs, reason = "no need for doc")]
2726    type Output;
2727    #[expect(missing_docs, reason = "no need for doc")]
2728    type Error;
2729    ///Checked division: computes `value / divisor`, returning an error if overflow occured or if `divisor` is zero.
2730    ///
2731    ///Wrapper for `checked_div`.
2732    fn cdiv(self, divisor: Self::Divisor) -> Result<Self::Output, Self::Error>;
2733    ///Checked division assigement: executes `self /= divisor`, returning an error if overflow occured or if `divisor` is zero.
2734    ///
2735    ///Wrapper for `checked_div`.
2736    fn cdiv_assign(&mut self, divisor: Self::Divisor) -> Result<(), Self::Error>;
2737}
2738///Checked division: computes `value / divisor`, returning an error if overflow occured or if `divisor` is zero.
2739///
2740///Wrapper for `checked_div`.
2741///
2742///See also: [module documentation](self).
2743#[doc(alias = "checked_div")]
2744#[inline]
2745pub fn cdiv<T>(value: T, divisor: T::Divisor) -> Result<T::Output, T::Error>
2746where
2747    T: Cdiv,
2748{
2749    value.cdiv(divisor)
2750}
2751impl Cdiv for i8 {
2752    type Divisor = i8;
2753    type Output = i8;
2754    type Error = Error;
2755    ///Checked division: computes `value / divisor`, returning an error if overflow occured or if `divisor` is zero.
2756    ///
2757    ///Wrapper for [`i8::checked_div`].
2758    #[inline]
2759    fn cdiv(self, divisor: i8) -> Result<i8, Error> {
2760        self.checked_div(divisor).ok_or_else(|| {
2761            Error::new({
2762                if divisor == 0 {
2763                    format!(
2764                        "failed to compute {:?} / {:?}: division by zero",
2765                        self,
2766                        MaybeParens(divisor)
2767                    )
2768                } else {
2769                    format!(
2770                        "failed to compute {:?} / {:?}: {} overflow",
2771                        self,
2772                        MaybeParens(divisor),
2773                        "i8"
2774                    )
2775                }
2776            })
2777        })
2778    }
2779    #[inline]
2780    ///Checked division assigement: executes `self /= divisor`, returning an error if overflow occured or if `divisor` is zero.
2781    ///
2782    ///Wrapper for [`i8::checked_div`].
2783    fn cdiv_assign(&mut self, divisor: i8) -> Result<(), Self::Error> {
2784        *self = self.cdiv(divisor)?;
2785        Ok(())
2786    }
2787}
2788impl Cdiv for i16 {
2789    type Divisor = i16;
2790    type Output = i16;
2791    type Error = Error;
2792    ///Checked division: computes `value / divisor`, returning an error if overflow occured or if `divisor` is zero.
2793    ///
2794    ///Wrapper for [`i16::checked_div`].
2795    #[inline]
2796    fn cdiv(self, divisor: i16) -> Result<i16, Error> {
2797        self.checked_div(divisor).ok_or_else(|| {
2798            Error::new({
2799                if divisor == 0 {
2800                    format!(
2801                        "failed to compute {:?} / {:?}: division by zero",
2802                        self,
2803                        MaybeParens(divisor)
2804                    )
2805                } else {
2806                    format!(
2807                        "failed to compute {:?} / {:?}: {} overflow",
2808                        self,
2809                        MaybeParens(divisor),
2810                        "i16"
2811                    )
2812                }
2813            })
2814        })
2815    }
2816    #[inline]
2817    ///Checked division assigement: executes `self /= divisor`, returning an error if overflow occured or if `divisor` is zero.
2818    ///
2819    ///Wrapper for [`i16::checked_div`].
2820    fn cdiv_assign(&mut self, divisor: i16) -> Result<(), Self::Error> {
2821        *self = self.cdiv(divisor)?;
2822        Ok(())
2823    }
2824}
2825impl Cdiv for i32 {
2826    type Divisor = i32;
2827    type Output = i32;
2828    type Error = Error;
2829    ///Checked division: computes `value / divisor`, returning an error if overflow occured or if `divisor` is zero.
2830    ///
2831    ///Wrapper for [`i32::checked_div`].
2832    #[inline]
2833    fn cdiv(self, divisor: i32) -> Result<i32, Error> {
2834        self.checked_div(divisor).ok_or_else(|| {
2835            Error::new({
2836                if divisor == 0 {
2837                    format!(
2838                        "failed to compute {:?} / {:?}: division by zero",
2839                        self,
2840                        MaybeParens(divisor)
2841                    )
2842                } else {
2843                    format!(
2844                        "failed to compute {:?} / {:?}: {} overflow",
2845                        self,
2846                        MaybeParens(divisor),
2847                        "i32"
2848                    )
2849                }
2850            })
2851        })
2852    }
2853    #[inline]
2854    ///Checked division assigement: executes `self /= divisor`, returning an error if overflow occured or if `divisor` is zero.
2855    ///
2856    ///Wrapper for [`i32::checked_div`].
2857    fn cdiv_assign(&mut self, divisor: i32) -> Result<(), Self::Error> {
2858        *self = self.cdiv(divisor)?;
2859        Ok(())
2860    }
2861}
2862impl Cdiv for i64 {
2863    type Divisor = i64;
2864    type Output = i64;
2865    type Error = Error;
2866    ///Checked division: computes `value / divisor`, returning an error if overflow occured or if `divisor` is zero.
2867    ///
2868    ///Wrapper for [`i64::checked_div`].
2869    #[inline]
2870    fn cdiv(self, divisor: i64) -> Result<i64, Error> {
2871        self.checked_div(divisor).ok_or_else(|| {
2872            Error::new({
2873                if divisor == 0 {
2874                    format!(
2875                        "failed to compute {:?} / {:?}: division by zero",
2876                        self,
2877                        MaybeParens(divisor)
2878                    )
2879                } else {
2880                    format!(
2881                        "failed to compute {:?} / {:?}: {} overflow",
2882                        self,
2883                        MaybeParens(divisor),
2884                        "i64"
2885                    )
2886                }
2887            })
2888        })
2889    }
2890    #[inline]
2891    ///Checked division assigement: executes `self /= divisor`, returning an error if overflow occured or if `divisor` is zero.
2892    ///
2893    ///Wrapper for [`i64::checked_div`].
2894    fn cdiv_assign(&mut self, divisor: i64) -> Result<(), Self::Error> {
2895        *self = self.cdiv(divisor)?;
2896        Ok(())
2897    }
2898}
2899impl Cdiv for i128 {
2900    type Divisor = i128;
2901    type Output = i128;
2902    type Error = Error;
2903    ///Checked division: computes `value / divisor`, returning an error if overflow occured or if `divisor` is zero.
2904    ///
2905    ///Wrapper for [`i128::checked_div`].
2906    #[inline]
2907    fn cdiv(self, divisor: i128) -> Result<i128, Error> {
2908        self.checked_div(divisor).ok_or_else(|| {
2909            Error::new({
2910                if divisor == 0 {
2911                    format!(
2912                        "failed to compute {:?} / {:?}: division by zero",
2913                        self,
2914                        MaybeParens(divisor)
2915                    )
2916                } else {
2917                    format!(
2918                        "failed to compute {:?} / {:?}: {} overflow",
2919                        self,
2920                        MaybeParens(divisor),
2921                        "i128"
2922                    )
2923                }
2924            })
2925        })
2926    }
2927    #[inline]
2928    ///Checked division assigement: executes `self /= divisor`, returning an error if overflow occured or if `divisor` is zero.
2929    ///
2930    ///Wrapper for [`i128::checked_div`].
2931    fn cdiv_assign(&mut self, divisor: i128) -> Result<(), Self::Error> {
2932        *self = self.cdiv(divisor)?;
2933        Ok(())
2934    }
2935}
2936impl Cdiv for isize {
2937    type Divisor = isize;
2938    type Output = isize;
2939    type Error = Error;
2940    ///Checked division: computes `value / divisor`, returning an error if overflow occured or if `divisor` is zero.
2941    ///
2942    ///Wrapper for [`isize::checked_div`].
2943    #[inline]
2944    fn cdiv(self, divisor: isize) -> Result<isize, Error> {
2945        self.checked_div(divisor).ok_or_else(|| {
2946            Error::new({
2947                if divisor == 0 {
2948                    format!(
2949                        "failed to compute {:?} / {:?}: division by zero",
2950                        self,
2951                        MaybeParens(divisor)
2952                    )
2953                } else {
2954                    format!(
2955                        "failed to compute {:?} / {:?}: {} overflow",
2956                        self,
2957                        MaybeParens(divisor),
2958                        "isize"
2959                    )
2960                }
2961            })
2962        })
2963    }
2964    #[inline]
2965    ///Checked division assigement: executes `self /= divisor`, returning an error if overflow occured or if `divisor` is zero.
2966    ///
2967    ///Wrapper for [`isize::checked_div`].
2968    fn cdiv_assign(&mut self, divisor: isize) -> Result<(), Self::Error> {
2969        *self = self.cdiv(divisor)?;
2970        Ok(())
2971    }
2972}
2973impl Cdiv for u8 {
2974    type Divisor = u8;
2975    type Output = u8;
2976    type Error = Error;
2977    ///Checked division: computes `value / divisor`, returning an error if overflow occured or if `divisor` is zero.
2978    ///
2979    ///Wrapper for [`u8::checked_div`].
2980    #[inline]
2981    fn cdiv(self, divisor: u8) -> Result<u8, Error> {
2982        self.checked_div(divisor).ok_or_else(|| {
2983            Error::new({
2984                if divisor == 0 {
2985                    format!(
2986                        "failed to compute {:?} / {:?}: division by zero",
2987                        self,
2988                        MaybeParens(divisor)
2989                    )
2990                } else {
2991                    format!(
2992                        "failed to compute {:?} / {:?}: {} overflow",
2993                        self,
2994                        MaybeParens(divisor),
2995                        "u8"
2996                    )
2997                }
2998            })
2999        })
3000    }
3001    #[inline]
3002    ///Checked division assigement: executes `self /= divisor`, returning an error if overflow occured or if `divisor` is zero.
3003    ///
3004    ///Wrapper for [`u8::checked_div`].
3005    fn cdiv_assign(&mut self, divisor: u8) -> Result<(), Self::Error> {
3006        *self = self.cdiv(divisor)?;
3007        Ok(())
3008    }
3009}
3010impl Cdiv for u16 {
3011    type Divisor = u16;
3012    type Output = u16;
3013    type Error = Error;
3014    ///Checked division: computes `value / divisor`, returning an error if overflow occured or if `divisor` is zero.
3015    ///
3016    ///Wrapper for [`u16::checked_div`].
3017    #[inline]
3018    fn cdiv(self, divisor: u16) -> Result<u16, Error> {
3019        self.checked_div(divisor).ok_or_else(|| {
3020            Error::new({
3021                if divisor == 0 {
3022                    format!(
3023                        "failed to compute {:?} / {:?}: division by zero",
3024                        self,
3025                        MaybeParens(divisor)
3026                    )
3027                } else {
3028                    format!(
3029                        "failed to compute {:?} / {:?}: {} overflow",
3030                        self,
3031                        MaybeParens(divisor),
3032                        "u16"
3033                    )
3034                }
3035            })
3036        })
3037    }
3038    #[inline]
3039    ///Checked division assigement: executes `self /= divisor`, returning an error if overflow occured or if `divisor` is zero.
3040    ///
3041    ///Wrapper for [`u16::checked_div`].
3042    fn cdiv_assign(&mut self, divisor: u16) -> Result<(), Self::Error> {
3043        *self = self.cdiv(divisor)?;
3044        Ok(())
3045    }
3046}
3047impl Cdiv for u32 {
3048    type Divisor = u32;
3049    type Output = u32;
3050    type Error = Error;
3051    ///Checked division: computes `value / divisor`, returning an error if overflow occured or if `divisor` is zero.
3052    ///
3053    ///Wrapper for [`u32::checked_div`].
3054    #[inline]
3055    fn cdiv(self, divisor: u32) -> Result<u32, Error> {
3056        self.checked_div(divisor).ok_or_else(|| {
3057            Error::new({
3058                if divisor == 0 {
3059                    format!(
3060                        "failed to compute {:?} / {:?}: division by zero",
3061                        self,
3062                        MaybeParens(divisor)
3063                    )
3064                } else {
3065                    format!(
3066                        "failed to compute {:?} / {:?}: {} overflow",
3067                        self,
3068                        MaybeParens(divisor),
3069                        "u32"
3070                    )
3071                }
3072            })
3073        })
3074    }
3075    #[inline]
3076    ///Checked division assigement: executes `self /= divisor`, returning an error if overflow occured or if `divisor` is zero.
3077    ///
3078    ///Wrapper for [`u32::checked_div`].
3079    fn cdiv_assign(&mut self, divisor: u32) -> Result<(), Self::Error> {
3080        *self = self.cdiv(divisor)?;
3081        Ok(())
3082    }
3083}
3084impl Cdiv for u64 {
3085    type Divisor = u64;
3086    type Output = u64;
3087    type Error = Error;
3088    ///Checked division: computes `value / divisor`, returning an error if overflow occured or if `divisor` is zero.
3089    ///
3090    ///Wrapper for [`u64::checked_div`].
3091    #[inline]
3092    fn cdiv(self, divisor: u64) -> Result<u64, Error> {
3093        self.checked_div(divisor).ok_or_else(|| {
3094            Error::new({
3095                if divisor == 0 {
3096                    format!(
3097                        "failed to compute {:?} / {:?}: division by zero",
3098                        self,
3099                        MaybeParens(divisor)
3100                    )
3101                } else {
3102                    format!(
3103                        "failed to compute {:?} / {:?}: {} overflow",
3104                        self,
3105                        MaybeParens(divisor),
3106                        "u64"
3107                    )
3108                }
3109            })
3110        })
3111    }
3112    #[inline]
3113    ///Checked division assigement: executes `self /= divisor`, returning an error if overflow occured or if `divisor` is zero.
3114    ///
3115    ///Wrapper for [`u64::checked_div`].
3116    fn cdiv_assign(&mut self, divisor: u64) -> Result<(), Self::Error> {
3117        *self = self.cdiv(divisor)?;
3118        Ok(())
3119    }
3120}
3121impl Cdiv for u128 {
3122    type Divisor = u128;
3123    type Output = u128;
3124    type Error = Error;
3125    ///Checked division: computes `value / divisor`, returning an error if overflow occured or if `divisor` is zero.
3126    ///
3127    ///Wrapper for [`u128::checked_div`].
3128    #[inline]
3129    fn cdiv(self, divisor: u128) -> Result<u128, Error> {
3130        self.checked_div(divisor).ok_or_else(|| {
3131            Error::new({
3132                if divisor == 0 {
3133                    format!(
3134                        "failed to compute {:?} / {:?}: division by zero",
3135                        self,
3136                        MaybeParens(divisor)
3137                    )
3138                } else {
3139                    format!(
3140                        "failed to compute {:?} / {:?}: {} overflow",
3141                        self,
3142                        MaybeParens(divisor),
3143                        "u128"
3144                    )
3145                }
3146            })
3147        })
3148    }
3149    #[inline]
3150    ///Checked division assigement: executes `self /= divisor`, returning an error if overflow occured or if `divisor` is zero.
3151    ///
3152    ///Wrapper for [`u128::checked_div`].
3153    fn cdiv_assign(&mut self, divisor: u128) -> Result<(), Self::Error> {
3154        *self = self.cdiv(divisor)?;
3155        Ok(())
3156    }
3157}
3158impl Cdiv for usize {
3159    type Divisor = usize;
3160    type Output = usize;
3161    type Error = Error;
3162    ///Checked division: computes `value / divisor`, returning an error if overflow occured or if `divisor` is zero.
3163    ///
3164    ///Wrapper for [`usize::checked_div`].
3165    #[inline]
3166    fn cdiv(self, divisor: usize) -> Result<usize, Error> {
3167        self.checked_div(divisor).ok_or_else(|| {
3168            Error::new({
3169                if divisor == 0 {
3170                    format!(
3171                        "failed to compute {:?} / {:?}: division by zero",
3172                        self,
3173                        MaybeParens(divisor)
3174                    )
3175                } else {
3176                    format!(
3177                        "failed to compute {:?} / {:?}: {} overflow",
3178                        self,
3179                        MaybeParens(divisor),
3180                        "usize"
3181                    )
3182                }
3183            })
3184        })
3185    }
3186    #[inline]
3187    ///Checked division assigement: executes `self /= divisor`, returning an error if overflow occured or if `divisor` is zero.
3188    ///
3189    ///Wrapper for [`usize::checked_div`].
3190    fn cdiv_assign(&mut self, divisor: usize) -> Result<(), Self::Error> {
3191        *self = self.cdiv(divisor)?;
3192        Ok(())
3193    }
3194}
3195impl Cdiv for Duration {
3196    type Divisor = u32;
3197    type Output = Duration;
3198    type Error = Error;
3199    ///Checked division: computes `value / divisor`, returning an error if overflow occured or if `divisor` is zero.
3200    ///
3201    ///Wrapper for [`Duration::checked_div`].
3202    #[inline]
3203    fn cdiv(self, divisor: u32) -> Result<Duration, Error> {
3204        self.checked_div(divisor).ok_or_else(|| {
3205            Error::new({
3206                if divisor == 0 {
3207                    format!(
3208                        "failed to compute {:?} / {:?}: division by zero",
3209                        self,
3210                        MaybeParens(divisor)
3211                    )
3212                } else {
3213                    format!(
3214                        "failed to compute {:?} / {:?}: {} overflow",
3215                        self,
3216                        MaybeParens(divisor),
3217                        "Duration"
3218                    )
3219                }
3220            })
3221        })
3222    }
3223    #[inline]
3224    ///Checked division assigement: executes `self /= divisor`, returning an error if overflow occured or if `divisor` is zero.
3225    ///
3226    ///Wrapper for [`Duration::checked_div`].
3227    fn cdiv_assign(&mut self, divisor: u32) -> Result<(), Self::Error> {
3228        *self = self.cdiv(divisor)?;
3229        Ok(())
3230    }
3231}
3232///Checked euclidian division: computes `div_euclid(value, divisor)`, returning an error if overflow occured or if `divisor` is zero.
3233///
3234///See also: [module documentation](self).
3235pub trait CdivEuclid: Sized {
3236    #[expect(missing_docs, reason = "no need for doc")]
3237    type Divisor;
3238    #[expect(missing_docs, reason = "no need for doc")]
3239    type Output;
3240    #[expect(missing_docs, reason = "no need for doc")]
3241    type Error;
3242    ///Checked euclidian division: computes `div_euclid(value, divisor)`, returning an error if overflow occured or if `divisor` is zero.
3243    ///
3244    ///Wrapper for `checked_div_euclid`.
3245    fn cdiv_euclid(self, divisor: Self::Divisor) -> Result<Self::Output, Self::Error>;
3246}
3247///Checked euclidian division: computes `div_euclid(value, divisor)`, returning an error if overflow occured or if `divisor` is zero.
3248///
3249///Wrapper for `checked_div_euclid`.
3250///
3251///See also: [module documentation](self).
3252#[doc(alias = "checked_div_euclid")]
3253#[inline]
3254pub fn cdiv_euclid<T>(value: T, divisor: T::Divisor) -> Result<T::Output, T::Error>
3255where
3256    T: CdivEuclid,
3257{
3258    value.cdiv_euclid(divisor)
3259}
3260impl CdivEuclid for i8 {
3261    type Divisor = i8;
3262    type Output = i8;
3263    type Error = Error;
3264    ///Checked euclidian division: computes `div_euclid(value, divisor)`, returning an error if overflow occured or if `divisor` is zero.
3265    ///
3266    ///Wrapper for [`i8::checked_div_euclid`].
3267    #[inline]
3268    fn cdiv_euclid(self, divisor: i8) -> Result<i8, Error> {
3269        self.checked_div_euclid(divisor).ok_or_else(|| {
3270            Error::new({
3271                if divisor == 0 {
3272                    format!(
3273                        "failed to compute div_euclid({:?}, {:?}): division by zero",
3274                        self, divisor
3275                    )
3276                } else {
3277                    format!(
3278                        "failed to compute div_euclid({:?}, {:?}): {} overflow",
3279                        self, divisor, "i8"
3280                    )
3281                }
3282            })
3283        })
3284    }
3285}
3286impl CdivEuclid for i16 {
3287    type Divisor = i16;
3288    type Output = i16;
3289    type Error = Error;
3290    ///Checked euclidian division: computes `div_euclid(value, divisor)`, returning an error if overflow occured or if `divisor` is zero.
3291    ///
3292    ///Wrapper for [`i16::checked_div_euclid`].
3293    #[inline]
3294    fn cdiv_euclid(self, divisor: i16) -> Result<i16, Error> {
3295        self.checked_div_euclid(divisor).ok_or_else(|| {
3296            Error::new({
3297                if divisor == 0 {
3298                    format!(
3299                        "failed to compute div_euclid({:?}, {:?}): division by zero",
3300                        self, divisor
3301                    )
3302                } else {
3303                    format!(
3304                        "failed to compute div_euclid({:?}, {:?}): {} overflow",
3305                        self, divisor, "i16"
3306                    )
3307                }
3308            })
3309        })
3310    }
3311}
3312impl CdivEuclid for i32 {
3313    type Divisor = i32;
3314    type Output = i32;
3315    type Error = Error;
3316    ///Checked euclidian division: computes `div_euclid(value, divisor)`, returning an error if overflow occured or if `divisor` is zero.
3317    ///
3318    ///Wrapper for [`i32::checked_div_euclid`].
3319    #[inline]
3320    fn cdiv_euclid(self, divisor: i32) -> Result<i32, Error> {
3321        self.checked_div_euclid(divisor).ok_or_else(|| {
3322            Error::new({
3323                if divisor == 0 {
3324                    format!(
3325                        "failed to compute div_euclid({:?}, {:?}): division by zero",
3326                        self, divisor
3327                    )
3328                } else {
3329                    format!(
3330                        "failed to compute div_euclid({:?}, {:?}): {} overflow",
3331                        self, divisor, "i32"
3332                    )
3333                }
3334            })
3335        })
3336    }
3337}
3338impl CdivEuclid for i64 {
3339    type Divisor = i64;
3340    type Output = i64;
3341    type Error = Error;
3342    ///Checked euclidian division: computes `div_euclid(value, divisor)`, returning an error if overflow occured or if `divisor` is zero.
3343    ///
3344    ///Wrapper for [`i64::checked_div_euclid`].
3345    #[inline]
3346    fn cdiv_euclid(self, divisor: i64) -> Result<i64, Error> {
3347        self.checked_div_euclid(divisor).ok_or_else(|| {
3348            Error::new({
3349                if divisor == 0 {
3350                    format!(
3351                        "failed to compute div_euclid({:?}, {:?}): division by zero",
3352                        self, divisor
3353                    )
3354                } else {
3355                    format!(
3356                        "failed to compute div_euclid({:?}, {:?}): {} overflow",
3357                        self, divisor, "i64"
3358                    )
3359                }
3360            })
3361        })
3362    }
3363}
3364impl CdivEuclid for i128 {
3365    type Divisor = i128;
3366    type Output = i128;
3367    type Error = Error;
3368    ///Checked euclidian division: computes `div_euclid(value, divisor)`, returning an error if overflow occured or if `divisor` is zero.
3369    ///
3370    ///Wrapper for [`i128::checked_div_euclid`].
3371    #[inline]
3372    fn cdiv_euclid(self, divisor: i128) -> Result<i128, Error> {
3373        self.checked_div_euclid(divisor).ok_or_else(|| {
3374            Error::new({
3375                if divisor == 0 {
3376                    format!(
3377                        "failed to compute div_euclid({:?}, {:?}): division by zero",
3378                        self, divisor
3379                    )
3380                } else {
3381                    format!(
3382                        "failed to compute div_euclid({:?}, {:?}): {} overflow",
3383                        self, divisor, "i128"
3384                    )
3385                }
3386            })
3387        })
3388    }
3389}
3390impl CdivEuclid for isize {
3391    type Divisor = isize;
3392    type Output = isize;
3393    type Error = Error;
3394    ///Checked euclidian division: computes `div_euclid(value, divisor)`, returning an error if overflow occured or if `divisor` is zero.
3395    ///
3396    ///Wrapper for [`isize::checked_div_euclid`].
3397    #[inline]
3398    fn cdiv_euclid(self, divisor: isize) -> Result<isize, Error> {
3399        self.checked_div_euclid(divisor).ok_or_else(|| {
3400            Error::new({
3401                if divisor == 0 {
3402                    format!(
3403                        "failed to compute div_euclid({:?}, {:?}): division by zero",
3404                        self, divisor
3405                    )
3406                } else {
3407                    format!(
3408                        "failed to compute div_euclid({:?}, {:?}): {} overflow",
3409                        self, divisor, "isize"
3410                    )
3411                }
3412            })
3413        })
3414    }
3415}
3416impl CdivEuclid for u8 {
3417    type Divisor = u8;
3418    type Output = u8;
3419    type Error = Error;
3420    ///Checked euclidian division: computes `div_euclid(value, divisor)`, returning an error if overflow occured or if `divisor` is zero.
3421    ///
3422    ///Wrapper for [`u8::checked_div_euclid`].
3423    #[inline]
3424    fn cdiv_euclid(self, divisor: u8) -> Result<u8, Error> {
3425        self.checked_div_euclid(divisor).ok_or_else(|| {
3426            Error::new({
3427                if divisor == 0 {
3428                    format!(
3429                        "failed to compute div_euclid({:?}, {:?}): division by zero",
3430                        self, divisor
3431                    )
3432                } else {
3433                    format!(
3434                        "failed to compute div_euclid({:?}, {:?}): {} overflow",
3435                        self, divisor, "u8"
3436                    )
3437                }
3438            })
3439        })
3440    }
3441}
3442impl CdivEuclid for u16 {
3443    type Divisor = u16;
3444    type Output = u16;
3445    type Error = Error;
3446    ///Checked euclidian division: computes `div_euclid(value, divisor)`, returning an error if overflow occured or if `divisor` is zero.
3447    ///
3448    ///Wrapper for [`u16::checked_div_euclid`].
3449    #[inline]
3450    fn cdiv_euclid(self, divisor: u16) -> Result<u16, Error> {
3451        self.checked_div_euclid(divisor).ok_or_else(|| {
3452            Error::new({
3453                if divisor == 0 {
3454                    format!(
3455                        "failed to compute div_euclid({:?}, {:?}): division by zero",
3456                        self, divisor
3457                    )
3458                } else {
3459                    format!(
3460                        "failed to compute div_euclid({:?}, {:?}): {} overflow",
3461                        self, divisor, "u16"
3462                    )
3463                }
3464            })
3465        })
3466    }
3467}
3468impl CdivEuclid for u32 {
3469    type Divisor = u32;
3470    type Output = u32;
3471    type Error = Error;
3472    ///Checked euclidian division: computes `div_euclid(value, divisor)`, returning an error if overflow occured or if `divisor` is zero.
3473    ///
3474    ///Wrapper for [`u32::checked_div_euclid`].
3475    #[inline]
3476    fn cdiv_euclid(self, divisor: u32) -> Result<u32, Error> {
3477        self.checked_div_euclid(divisor).ok_or_else(|| {
3478            Error::new({
3479                if divisor == 0 {
3480                    format!(
3481                        "failed to compute div_euclid({:?}, {:?}): division by zero",
3482                        self, divisor
3483                    )
3484                } else {
3485                    format!(
3486                        "failed to compute div_euclid({:?}, {:?}): {} overflow",
3487                        self, divisor, "u32"
3488                    )
3489                }
3490            })
3491        })
3492    }
3493}
3494impl CdivEuclid for u64 {
3495    type Divisor = u64;
3496    type Output = u64;
3497    type Error = Error;
3498    ///Checked euclidian division: computes `div_euclid(value, divisor)`, returning an error if overflow occured or if `divisor` is zero.
3499    ///
3500    ///Wrapper for [`u64::checked_div_euclid`].
3501    #[inline]
3502    fn cdiv_euclid(self, divisor: u64) -> Result<u64, Error> {
3503        self.checked_div_euclid(divisor).ok_or_else(|| {
3504            Error::new({
3505                if divisor == 0 {
3506                    format!(
3507                        "failed to compute div_euclid({:?}, {:?}): division by zero",
3508                        self, divisor
3509                    )
3510                } else {
3511                    format!(
3512                        "failed to compute div_euclid({:?}, {:?}): {} overflow",
3513                        self, divisor, "u64"
3514                    )
3515                }
3516            })
3517        })
3518    }
3519}
3520impl CdivEuclid for u128 {
3521    type Divisor = u128;
3522    type Output = u128;
3523    type Error = Error;
3524    ///Checked euclidian division: computes `div_euclid(value, divisor)`, returning an error if overflow occured or if `divisor` is zero.
3525    ///
3526    ///Wrapper for [`u128::checked_div_euclid`].
3527    #[inline]
3528    fn cdiv_euclid(self, divisor: u128) -> Result<u128, Error> {
3529        self.checked_div_euclid(divisor).ok_or_else(|| {
3530            Error::new({
3531                if divisor == 0 {
3532                    format!(
3533                        "failed to compute div_euclid({:?}, {:?}): division by zero",
3534                        self, divisor
3535                    )
3536                } else {
3537                    format!(
3538                        "failed to compute div_euclid({:?}, {:?}): {} overflow",
3539                        self, divisor, "u128"
3540                    )
3541                }
3542            })
3543        })
3544    }
3545}
3546impl CdivEuclid for usize {
3547    type Divisor = usize;
3548    type Output = usize;
3549    type Error = Error;
3550    ///Checked euclidian division: computes `div_euclid(value, divisor)`, returning an error if overflow occured or if `divisor` is zero.
3551    ///
3552    ///Wrapper for [`usize::checked_div_euclid`].
3553    #[inline]
3554    fn cdiv_euclid(self, divisor: usize) -> Result<usize, Error> {
3555        self.checked_div_euclid(divisor).ok_or_else(|| {
3556            Error::new({
3557                if divisor == 0 {
3558                    format!(
3559                        "failed to compute div_euclid({:?}, {:?}): division by zero",
3560                        self, divisor
3561                    )
3562                } else {
3563                    format!(
3564                        "failed to compute div_euclid({:?}, {:?}): {} overflow",
3565                        self, divisor, "usize"
3566                    )
3567                }
3568            })
3569        })
3570    }
3571}
3572///Checked remainder: computes `value % divisor`, returning an error if overflow occured or if `divisor` is zero.
3573///
3574///See also: [module documentation](self).
3575pub trait Crem: Sized {
3576    #[expect(missing_docs, reason = "no need for doc")]
3577    type Divisor;
3578    #[expect(missing_docs, reason = "no need for doc")]
3579    type Output;
3580    #[expect(missing_docs, reason = "no need for doc")]
3581    type Error;
3582    ///Checked remainder: computes `value % divisor`, returning an error if overflow occured or if `divisor` is zero.
3583    ///
3584    ///Wrapper for `checked_rem`.
3585    fn crem(self, divisor: Self::Divisor) -> Result<Self::Output, Self::Error>;
3586    ///Checked remainder assigement: executes `self %= divisor`, returning an error if overflow occured or if `divisor` is zero.
3587    ///
3588    ///Wrapper for `checked_rem`.
3589    fn crem_assign(&mut self, divisor: Self::Divisor) -> Result<(), Self::Error>;
3590}
3591///Checked remainder: computes `value % divisor`, returning an error if overflow occured or if `divisor` is zero.
3592///
3593///Wrapper for `checked_rem`.
3594///
3595///See also: [module documentation](self).
3596#[doc(alias = "checked_rem")]
3597#[inline]
3598pub fn crem<T>(value: T, divisor: T::Divisor) -> Result<T::Output, T::Error>
3599where
3600    T: Crem,
3601{
3602    value.crem(divisor)
3603}
3604impl Crem for i8 {
3605    type Divisor = i8;
3606    type Output = i8;
3607    type Error = Error;
3608    ///Checked remainder: computes `value % divisor`, returning an error if overflow occured or if `divisor` is zero.
3609    ///
3610    ///Wrapper for [`i8::checked_rem`].
3611    #[inline]
3612    fn crem(self, divisor: i8) -> Result<i8, Error> {
3613        self.checked_rem(divisor).ok_or_else(|| {
3614            Error::new({
3615                if divisor == 0 {
3616                    format!(
3617                        "failed to compute {:?} % {:?}: division by zero",
3618                        self,
3619                        MaybeParens(divisor)
3620                    )
3621                } else {
3622                    format!(
3623                        "failed to compute {:?} % {:?}: {} overflow",
3624                        self,
3625                        MaybeParens(divisor),
3626                        "i8"
3627                    )
3628                }
3629            })
3630        })
3631    }
3632    #[inline]
3633    ///Checked remainder assigement: executes `self %= divisor`, returning an error if overflow occured or if `divisor` is zero.
3634    ///
3635    ///Wrapper for [`i8::checked_rem`].
3636    fn crem_assign(&mut self, divisor: i8) -> Result<(), Self::Error> {
3637        *self = self.crem(divisor)?;
3638        Ok(())
3639    }
3640}
3641impl Crem for i16 {
3642    type Divisor = i16;
3643    type Output = i16;
3644    type Error = Error;
3645    ///Checked remainder: computes `value % divisor`, returning an error if overflow occured or if `divisor` is zero.
3646    ///
3647    ///Wrapper for [`i16::checked_rem`].
3648    #[inline]
3649    fn crem(self, divisor: i16) -> Result<i16, Error> {
3650        self.checked_rem(divisor).ok_or_else(|| {
3651            Error::new({
3652                if divisor == 0 {
3653                    format!(
3654                        "failed to compute {:?} % {:?}: division by zero",
3655                        self,
3656                        MaybeParens(divisor)
3657                    )
3658                } else {
3659                    format!(
3660                        "failed to compute {:?} % {:?}: {} overflow",
3661                        self,
3662                        MaybeParens(divisor),
3663                        "i16"
3664                    )
3665                }
3666            })
3667        })
3668    }
3669    #[inline]
3670    ///Checked remainder assigement: executes `self %= divisor`, returning an error if overflow occured or if `divisor` is zero.
3671    ///
3672    ///Wrapper for [`i16::checked_rem`].
3673    fn crem_assign(&mut self, divisor: i16) -> Result<(), Self::Error> {
3674        *self = self.crem(divisor)?;
3675        Ok(())
3676    }
3677}
3678impl Crem for i32 {
3679    type Divisor = i32;
3680    type Output = i32;
3681    type Error = Error;
3682    ///Checked remainder: computes `value % divisor`, returning an error if overflow occured or if `divisor` is zero.
3683    ///
3684    ///Wrapper for [`i32::checked_rem`].
3685    #[inline]
3686    fn crem(self, divisor: i32) -> Result<i32, Error> {
3687        self.checked_rem(divisor).ok_or_else(|| {
3688            Error::new({
3689                if divisor == 0 {
3690                    format!(
3691                        "failed to compute {:?} % {:?}: division by zero",
3692                        self,
3693                        MaybeParens(divisor)
3694                    )
3695                } else {
3696                    format!(
3697                        "failed to compute {:?} % {:?}: {} overflow",
3698                        self,
3699                        MaybeParens(divisor),
3700                        "i32"
3701                    )
3702                }
3703            })
3704        })
3705    }
3706    #[inline]
3707    ///Checked remainder assigement: executes `self %= divisor`, returning an error if overflow occured or if `divisor` is zero.
3708    ///
3709    ///Wrapper for [`i32::checked_rem`].
3710    fn crem_assign(&mut self, divisor: i32) -> Result<(), Self::Error> {
3711        *self = self.crem(divisor)?;
3712        Ok(())
3713    }
3714}
3715impl Crem for i64 {
3716    type Divisor = i64;
3717    type Output = i64;
3718    type Error = Error;
3719    ///Checked remainder: computes `value % divisor`, returning an error if overflow occured or if `divisor` is zero.
3720    ///
3721    ///Wrapper for [`i64::checked_rem`].
3722    #[inline]
3723    fn crem(self, divisor: i64) -> Result<i64, Error> {
3724        self.checked_rem(divisor).ok_or_else(|| {
3725            Error::new({
3726                if divisor == 0 {
3727                    format!(
3728                        "failed to compute {:?} % {:?}: division by zero",
3729                        self,
3730                        MaybeParens(divisor)
3731                    )
3732                } else {
3733                    format!(
3734                        "failed to compute {:?} % {:?}: {} overflow",
3735                        self,
3736                        MaybeParens(divisor),
3737                        "i64"
3738                    )
3739                }
3740            })
3741        })
3742    }
3743    #[inline]
3744    ///Checked remainder assigement: executes `self %= divisor`, returning an error if overflow occured or if `divisor` is zero.
3745    ///
3746    ///Wrapper for [`i64::checked_rem`].
3747    fn crem_assign(&mut self, divisor: i64) -> Result<(), Self::Error> {
3748        *self = self.crem(divisor)?;
3749        Ok(())
3750    }
3751}
3752impl Crem for i128 {
3753    type Divisor = i128;
3754    type Output = i128;
3755    type Error = Error;
3756    ///Checked remainder: computes `value % divisor`, returning an error if overflow occured or if `divisor` is zero.
3757    ///
3758    ///Wrapper for [`i128::checked_rem`].
3759    #[inline]
3760    fn crem(self, divisor: i128) -> Result<i128, Error> {
3761        self.checked_rem(divisor).ok_or_else(|| {
3762            Error::new({
3763                if divisor == 0 {
3764                    format!(
3765                        "failed to compute {:?} % {:?}: division by zero",
3766                        self,
3767                        MaybeParens(divisor)
3768                    )
3769                } else {
3770                    format!(
3771                        "failed to compute {:?} % {:?}: {} overflow",
3772                        self,
3773                        MaybeParens(divisor),
3774                        "i128"
3775                    )
3776                }
3777            })
3778        })
3779    }
3780    #[inline]
3781    ///Checked remainder assigement: executes `self %= divisor`, returning an error if overflow occured or if `divisor` is zero.
3782    ///
3783    ///Wrapper for [`i128::checked_rem`].
3784    fn crem_assign(&mut self, divisor: i128) -> Result<(), Self::Error> {
3785        *self = self.crem(divisor)?;
3786        Ok(())
3787    }
3788}
3789impl Crem for isize {
3790    type Divisor = isize;
3791    type Output = isize;
3792    type Error = Error;
3793    ///Checked remainder: computes `value % divisor`, returning an error if overflow occured or if `divisor` is zero.
3794    ///
3795    ///Wrapper for [`isize::checked_rem`].
3796    #[inline]
3797    fn crem(self, divisor: isize) -> Result<isize, Error> {
3798        self.checked_rem(divisor).ok_or_else(|| {
3799            Error::new({
3800                if divisor == 0 {
3801                    format!(
3802                        "failed to compute {:?} % {:?}: division by zero",
3803                        self,
3804                        MaybeParens(divisor)
3805                    )
3806                } else {
3807                    format!(
3808                        "failed to compute {:?} % {:?}: {} overflow",
3809                        self,
3810                        MaybeParens(divisor),
3811                        "isize"
3812                    )
3813                }
3814            })
3815        })
3816    }
3817    #[inline]
3818    ///Checked remainder assigement: executes `self %= divisor`, returning an error if overflow occured or if `divisor` is zero.
3819    ///
3820    ///Wrapper for [`isize::checked_rem`].
3821    fn crem_assign(&mut self, divisor: isize) -> Result<(), Self::Error> {
3822        *self = self.crem(divisor)?;
3823        Ok(())
3824    }
3825}
3826impl Crem for u8 {
3827    type Divisor = u8;
3828    type Output = u8;
3829    type Error = Error;
3830    ///Checked remainder: computes `value % divisor`, returning an error if overflow occured or if `divisor` is zero.
3831    ///
3832    ///Wrapper for [`u8::checked_rem`].
3833    #[inline]
3834    fn crem(self, divisor: u8) -> Result<u8, Error> {
3835        self.checked_rem(divisor).ok_or_else(|| {
3836            Error::new({
3837                if divisor == 0 {
3838                    format!(
3839                        "failed to compute {:?} % {:?}: division by zero",
3840                        self,
3841                        MaybeParens(divisor)
3842                    )
3843                } else {
3844                    format!(
3845                        "failed to compute {:?} % {:?}: {} overflow",
3846                        self,
3847                        MaybeParens(divisor),
3848                        "u8"
3849                    )
3850                }
3851            })
3852        })
3853    }
3854    #[inline]
3855    ///Checked remainder assigement: executes `self %= divisor`, returning an error if overflow occured or if `divisor` is zero.
3856    ///
3857    ///Wrapper for [`u8::checked_rem`].
3858    fn crem_assign(&mut self, divisor: u8) -> Result<(), Self::Error> {
3859        *self = self.crem(divisor)?;
3860        Ok(())
3861    }
3862}
3863impl Crem for u16 {
3864    type Divisor = u16;
3865    type Output = u16;
3866    type Error = Error;
3867    ///Checked remainder: computes `value % divisor`, returning an error if overflow occured or if `divisor` is zero.
3868    ///
3869    ///Wrapper for [`u16::checked_rem`].
3870    #[inline]
3871    fn crem(self, divisor: u16) -> Result<u16, Error> {
3872        self.checked_rem(divisor).ok_or_else(|| {
3873            Error::new({
3874                if divisor == 0 {
3875                    format!(
3876                        "failed to compute {:?} % {:?}: division by zero",
3877                        self,
3878                        MaybeParens(divisor)
3879                    )
3880                } else {
3881                    format!(
3882                        "failed to compute {:?} % {:?}: {} overflow",
3883                        self,
3884                        MaybeParens(divisor),
3885                        "u16"
3886                    )
3887                }
3888            })
3889        })
3890    }
3891    #[inline]
3892    ///Checked remainder assigement: executes `self %= divisor`, returning an error if overflow occured or if `divisor` is zero.
3893    ///
3894    ///Wrapper for [`u16::checked_rem`].
3895    fn crem_assign(&mut self, divisor: u16) -> Result<(), Self::Error> {
3896        *self = self.crem(divisor)?;
3897        Ok(())
3898    }
3899}
3900impl Crem for u32 {
3901    type Divisor = u32;
3902    type Output = u32;
3903    type Error = Error;
3904    ///Checked remainder: computes `value % divisor`, returning an error if overflow occured or if `divisor` is zero.
3905    ///
3906    ///Wrapper for [`u32::checked_rem`].
3907    #[inline]
3908    fn crem(self, divisor: u32) -> Result<u32, Error> {
3909        self.checked_rem(divisor).ok_or_else(|| {
3910            Error::new({
3911                if divisor == 0 {
3912                    format!(
3913                        "failed to compute {:?} % {:?}: division by zero",
3914                        self,
3915                        MaybeParens(divisor)
3916                    )
3917                } else {
3918                    format!(
3919                        "failed to compute {:?} % {:?}: {} overflow",
3920                        self,
3921                        MaybeParens(divisor),
3922                        "u32"
3923                    )
3924                }
3925            })
3926        })
3927    }
3928    #[inline]
3929    ///Checked remainder assigement: executes `self %= divisor`, returning an error if overflow occured or if `divisor` is zero.
3930    ///
3931    ///Wrapper for [`u32::checked_rem`].
3932    fn crem_assign(&mut self, divisor: u32) -> Result<(), Self::Error> {
3933        *self = self.crem(divisor)?;
3934        Ok(())
3935    }
3936}
3937impl Crem for u64 {
3938    type Divisor = u64;
3939    type Output = u64;
3940    type Error = Error;
3941    ///Checked remainder: computes `value % divisor`, returning an error if overflow occured or if `divisor` is zero.
3942    ///
3943    ///Wrapper for [`u64::checked_rem`].
3944    #[inline]
3945    fn crem(self, divisor: u64) -> Result<u64, Error> {
3946        self.checked_rem(divisor).ok_or_else(|| {
3947            Error::new({
3948                if divisor == 0 {
3949                    format!(
3950                        "failed to compute {:?} % {:?}: division by zero",
3951                        self,
3952                        MaybeParens(divisor)
3953                    )
3954                } else {
3955                    format!(
3956                        "failed to compute {:?} % {:?}: {} overflow",
3957                        self,
3958                        MaybeParens(divisor),
3959                        "u64"
3960                    )
3961                }
3962            })
3963        })
3964    }
3965    #[inline]
3966    ///Checked remainder assigement: executes `self %= divisor`, returning an error if overflow occured or if `divisor` is zero.
3967    ///
3968    ///Wrapper for [`u64::checked_rem`].
3969    fn crem_assign(&mut self, divisor: u64) -> Result<(), Self::Error> {
3970        *self = self.crem(divisor)?;
3971        Ok(())
3972    }
3973}
3974impl Crem for u128 {
3975    type Divisor = u128;
3976    type Output = u128;
3977    type Error = Error;
3978    ///Checked remainder: computes `value % divisor`, returning an error if overflow occured or if `divisor` is zero.
3979    ///
3980    ///Wrapper for [`u128::checked_rem`].
3981    #[inline]
3982    fn crem(self, divisor: u128) -> Result<u128, Error> {
3983        self.checked_rem(divisor).ok_or_else(|| {
3984            Error::new({
3985                if divisor == 0 {
3986                    format!(
3987                        "failed to compute {:?} % {:?}: division by zero",
3988                        self,
3989                        MaybeParens(divisor)
3990                    )
3991                } else {
3992                    format!(
3993                        "failed to compute {:?} % {:?}: {} overflow",
3994                        self,
3995                        MaybeParens(divisor),
3996                        "u128"
3997                    )
3998                }
3999            })
4000        })
4001    }
4002    #[inline]
4003    ///Checked remainder assigement: executes `self %= divisor`, returning an error if overflow occured or if `divisor` is zero.
4004    ///
4005    ///Wrapper for [`u128::checked_rem`].
4006    fn crem_assign(&mut self, divisor: u128) -> Result<(), Self::Error> {
4007        *self = self.crem(divisor)?;
4008        Ok(())
4009    }
4010}
4011impl Crem for usize {
4012    type Divisor = usize;
4013    type Output = usize;
4014    type Error = Error;
4015    ///Checked remainder: computes `value % divisor`, returning an error if overflow occured or if `divisor` is zero.
4016    ///
4017    ///Wrapper for [`usize::checked_rem`].
4018    #[inline]
4019    fn crem(self, divisor: usize) -> Result<usize, Error> {
4020        self.checked_rem(divisor).ok_or_else(|| {
4021            Error::new({
4022                if divisor == 0 {
4023                    format!(
4024                        "failed to compute {:?} % {:?}: division by zero",
4025                        self,
4026                        MaybeParens(divisor)
4027                    )
4028                } else {
4029                    format!(
4030                        "failed to compute {:?} % {:?}: {} overflow",
4031                        self,
4032                        MaybeParens(divisor),
4033                        "usize"
4034                    )
4035                }
4036            })
4037        })
4038    }
4039    #[inline]
4040    ///Checked remainder assigement: executes `self %= divisor`, returning an error if overflow occured or if `divisor` is zero.
4041    ///
4042    ///Wrapper for [`usize::checked_rem`].
4043    fn crem_assign(&mut self, divisor: usize) -> Result<(), Self::Error> {
4044        *self = self.crem(divisor)?;
4045        Ok(())
4046    }
4047}
4048///Checked euclidian reminder: computes `rem_euclid(value, divisor)`, returning an error if overflow occured or if `divisor` is zero.
4049///
4050///See also: [module documentation](self).
4051pub trait CremEuclid: Sized {
4052    #[expect(missing_docs, reason = "no need for doc")]
4053    type Divisor;
4054    #[expect(missing_docs, reason = "no need for doc")]
4055    type Output;
4056    #[expect(missing_docs, reason = "no need for doc")]
4057    type Error;
4058    ///Checked euclidian reminder: computes `rem_euclid(value, divisor)`, returning an error if overflow occured or if `divisor` is zero.
4059    ///
4060    ///Wrapper for `checked_rem_euclid`.
4061    fn crem_euclid(self, divisor: Self::Divisor) -> Result<Self::Output, Self::Error>;
4062}
4063///Checked euclidian reminder: computes `rem_euclid(value, divisor)`, returning an error if overflow occured or if `divisor` is zero.
4064///
4065///Wrapper for `checked_rem_euclid`.
4066///
4067///See also: [module documentation](self).
4068#[doc(alias = "checked_rem_euclid")]
4069#[inline]
4070pub fn crem_euclid<T>(value: T, divisor: T::Divisor) -> Result<T::Output, T::Error>
4071where
4072    T: CremEuclid,
4073{
4074    value.crem_euclid(divisor)
4075}
4076impl CremEuclid for i8 {
4077    type Divisor = i8;
4078    type Output = i8;
4079    type Error = Error;
4080    ///Checked euclidian reminder: computes `rem_euclid(value, divisor)`, returning an error if overflow occured or if `divisor` is zero.
4081    ///
4082    ///Wrapper for [`i8::checked_rem_euclid`].
4083    #[inline]
4084    fn crem_euclid(self, divisor: i8) -> Result<i8, Error> {
4085        self.checked_rem_euclid(divisor).ok_or_else(|| {
4086            Error::new({
4087                if divisor == 0 {
4088                    format!(
4089                        "failed to compute rem_euclid({:?}, {:?}): division by zero",
4090                        self, divisor
4091                    )
4092                } else {
4093                    format!(
4094                        "failed to compute rem_euclid({:?}, {:?}): {} overflow",
4095                        self, divisor, "i8"
4096                    )
4097                }
4098            })
4099        })
4100    }
4101}
4102impl CremEuclid for i16 {
4103    type Divisor = i16;
4104    type Output = i16;
4105    type Error = Error;
4106    ///Checked euclidian reminder: computes `rem_euclid(value, divisor)`, returning an error if overflow occured or if `divisor` is zero.
4107    ///
4108    ///Wrapper for [`i16::checked_rem_euclid`].
4109    #[inline]
4110    fn crem_euclid(self, divisor: i16) -> Result<i16, Error> {
4111        self.checked_rem_euclid(divisor).ok_or_else(|| {
4112            Error::new({
4113                if divisor == 0 {
4114                    format!(
4115                        "failed to compute rem_euclid({:?}, {:?}): division by zero",
4116                        self, divisor
4117                    )
4118                } else {
4119                    format!(
4120                        "failed to compute rem_euclid({:?}, {:?}): {} overflow",
4121                        self, divisor, "i16"
4122                    )
4123                }
4124            })
4125        })
4126    }
4127}
4128impl CremEuclid for i32 {
4129    type Divisor = i32;
4130    type Output = i32;
4131    type Error = Error;
4132    ///Checked euclidian reminder: computes `rem_euclid(value, divisor)`, returning an error if overflow occured or if `divisor` is zero.
4133    ///
4134    ///Wrapper for [`i32::checked_rem_euclid`].
4135    #[inline]
4136    fn crem_euclid(self, divisor: i32) -> Result<i32, Error> {
4137        self.checked_rem_euclid(divisor).ok_or_else(|| {
4138            Error::new({
4139                if divisor == 0 {
4140                    format!(
4141                        "failed to compute rem_euclid({:?}, {:?}): division by zero",
4142                        self, divisor
4143                    )
4144                } else {
4145                    format!(
4146                        "failed to compute rem_euclid({:?}, {:?}): {} overflow",
4147                        self, divisor, "i32"
4148                    )
4149                }
4150            })
4151        })
4152    }
4153}
4154impl CremEuclid for i64 {
4155    type Divisor = i64;
4156    type Output = i64;
4157    type Error = Error;
4158    ///Checked euclidian reminder: computes `rem_euclid(value, divisor)`, returning an error if overflow occured or if `divisor` is zero.
4159    ///
4160    ///Wrapper for [`i64::checked_rem_euclid`].
4161    #[inline]
4162    fn crem_euclid(self, divisor: i64) -> Result<i64, Error> {
4163        self.checked_rem_euclid(divisor).ok_or_else(|| {
4164            Error::new({
4165                if divisor == 0 {
4166                    format!(
4167                        "failed to compute rem_euclid({:?}, {:?}): division by zero",
4168                        self, divisor
4169                    )
4170                } else {
4171                    format!(
4172                        "failed to compute rem_euclid({:?}, {:?}): {} overflow",
4173                        self, divisor, "i64"
4174                    )
4175                }
4176            })
4177        })
4178    }
4179}
4180impl CremEuclid for i128 {
4181    type Divisor = i128;
4182    type Output = i128;
4183    type Error = Error;
4184    ///Checked euclidian reminder: computes `rem_euclid(value, divisor)`, returning an error if overflow occured or if `divisor` is zero.
4185    ///
4186    ///Wrapper for [`i128::checked_rem_euclid`].
4187    #[inline]
4188    fn crem_euclid(self, divisor: i128) -> Result<i128, Error> {
4189        self.checked_rem_euclid(divisor).ok_or_else(|| {
4190            Error::new({
4191                if divisor == 0 {
4192                    format!(
4193                        "failed to compute rem_euclid({:?}, {:?}): division by zero",
4194                        self, divisor
4195                    )
4196                } else {
4197                    format!(
4198                        "failed to compute rem_euclid({:?}, {:?}): {} overflow",
4199                        self, divisor, "i128"
4200                    )
4201                }
4202            })
4203        })
4204    }
4205}
4206impl CremEuclid for isize {
4207    type Divisor = isize;
4208    type Output = isize;
4209    type Error = Error;
4210    ///Checked euclidian reminder: computes `rem_euclid(value, divisor)`, returning an error if overflow occured or if `divisor` is zero.
4211    ///
4212    ///Wrapper for [`isize::checked_rem_euclid`].
4213    #[inline]
4214    fn crem_euclid(self, divisor: isize) -> Result<isize, Error> {
4215        self.checked_rem_euclid(divisor).ok_or_else(|| {
4216            Error::new({
4217                if divisor == 0 {
4218                    format!(
4219                        "failed to compute rem_euclid({:?}, {:?}): division by zero",
4220                        self, divisor
4221                    )
4222                } else {
4223                    format!(
4224                        "failed to compute rem_euclid({:?}, {:?}): {} overflow",
4225                        self, divisor, "isize"
4226                    )
4227                }
4228            })
4229        })
4230    }
4231}
4232impl CremEuclid for u8 {
4233    type Divisor = u8;
4234    type Output = u8;
4235    type Error = Error;
4236    ///Checked euclidian reminder: computes `rem_euclid(value, divisor)`, returning an error if overflow occured or if `divisor` is zero.
4237    ///
4238    ///Wrapper for [`u8::checked_rem_euclid`].
4239    #[inline]
4240    fn crem_euclid(self, divisor: u8) -> Result<u8, Error> {
4241        self.checked_rem_euclid(divisor).ok_or_else(|| {
4242            Error::new({
4243                if divisor == 0 {
4244                    format!(
4245                        "failed to compute rem_euclid({:?}, {:?}): division by zero",
4246                        self, divisor
4247                    )
4248                } else {
4249                    format!(
4250                        "failed to compute rem_euclid({:?}, {:?}): {} overflow",
4251                        self, divisor, "u8"
4252                    )
4253                }
4254            })
4255        })
4256    }
4257}
4258impl CremEuclid for u16 {
4259    type Divisor = u16;
4260    type Output = u16;
4261    type Error = Error;
4262    ///Checked euclidian reminder: computes `rem_euclid(value, divisor)`, returning an error if overflow occured or if `divisor` is zero.
4263    ///
4264    ///Wrapper for [`u16::checked_rem_euclid`].
4265    #[inline]
4266    fn crem_euclid(self, divisor: u16) -> Result<u16, Error> {
4267        self.checked_rem_euclid(divisor).ok_or_else(|| {
4268            Error::new({
4269                if divisor == 0 {
4270                    format!(
4271                        "failed to compute rem_euclid({:?}, {:?}): division by zero",
4272                        self, divisor
4273                    )
4274                } else {
4275                    format!(
4276                        "failed to compute rem_euclid({:?}, {:?}): {} overflow",
4277                        self, divisor, "u16"
4278                    )
4279                }
4280            })
4281        })
4282    }
4283}
4284impl CremEuclid for u32 {
4285    type Divisor = u32;
4286    type Output = u32;
4287    type Error = Error;
4288    ///Checked euclidian reminder: computes `rem_euclid(value, divisor)`, returning an error if overflow occured or if `divisor` is zero.
4289    ///
4290    ///Wrapper for [`u32::checked_rem_euclid`].
4291    #[inline]
4292    fn crem_euclid(self, divisor: u32) -> Result<u32, Error> {
4293        self.checked_rem_euclid(divisor).ok_or_else(|| {
4294            Error::new({
4295                if divisor == 0 {
4296                    format!(
4297                        "failed to compute rem_euclid({:?}, {:?}): division by zero",
4298                        self, divisor
4299                    )
4300                } else {
4301                    format!(
4302                        "failed to compute rem_euclid({:?}, {:?}): {} overflow",
4303                        self, divisor, "u32"
4304                    )
4305                }
4306            })
4307        })
4308    }
4309}
4310impl CremEuclid for u64 {
4311    type Divisor = u64;
4312    type Output = u64;
4313    type Error = Error;
4314    ///Checked euclidian reminder: computes `rem_euclid(value, divisor)`, returning an error if overflow occured or if `divisor` is zero.
4315    ///
4316    ///Wrapper for [`u64::checked_rem_euclid`].
4317    #[inline]
4318    fn crem_euclid(self, divisor: u64) -> Result<u64, Error> {
4319        self.checked_rem_euclid(divisor).ok_or_else(|| {
4320            Error::new({
4321                if divisor == 0 {
4322                    format!(
4323                        "failed to compute rem_euclid({:?}, {:?}): division by zero",
4324                        self, divisor
4325                    )
4326                } else {
4327                    format!(
4328                        "failed to compute rem_euclid({:?}, {:?}): {} overflow",
4329                        self, divisor, "u64"
4330                    )
4331                }
4332            })
4333        })
4334    }
4335}
4336impl CremEuclid for u128 {
4337    type Divisor = u128;
4338    type Output = u128;
4339    type Error = Error;
4340    ///Checked euclidian reminder: computes `rem_euclid(value, divisor)`, returning an error if overflow occured or if `divisor` is zero.
4341    ///
4342    ///Wrapper for [`u128::checked_rem_euclid`].
4343    #[inline]
4344    fn crem_euclid(self, divisor: u128) -> Result<u128, Error> {
4345        self.checked_rem_euclid(divisor).ok_or_else(|| {
4346            Error::new({
4347                if divisor == 0 {
4348                    format!(
4349                        "failed to compute rem_euclid({:?}, {:?}): division by zero",
4350                        self, divisor
4351                    )
4352                } else {
4353                    format!(
4354                        "failed to compute rem_euclid({:?}, {:?}): {} overflow",
4355                        self, divisor, "u128"
4356                    )
4357                }
4358            })
4359        })
4360    }
4361}
4362impl CremEuclid for usize {
4363    type Divisor = usize;
4364    type Output = usize;
4365    type Error = Error;
4366    ///Checked euclidian reminder: computes `rem_euclid(value, divisor)`, returning an error if overflow occured or if `divisor` is zero.
4367    ///
4368    ///Wrapper for [`usize::checked_rem_euclid`].
4369    #[inline]
4370    fn crem_euclid(self, divisor: usize) -> Result<usize, Error> {
4371        self.checked_rem_euclid(divisor).ok_or_else(|| {
4372            Error::new({
4373                if divisor == 0 {
4374                    format!(
4375                        "failed to compute rem_euclid({:?}, {:?}): division by zero",
4376                        self, divisor
4377                    )
4378                } else {
4379                    format!(
4380                        "failed to compute rem_euclid({:?}, {:?}): {} overflow",
4381                        self, divisor, "usize"
4382                    )
4383                }
4384            })
4385        })
4386    }
4387}
4388///Checked logarithm: computes <code>log<sub>base</sub> value</code>, returning an error if `value` is negative or zero, or if `base` is less than 2.
4389///
4390///See also: [module documentation](self).
4391pub trait Cilog: Sized {
4392    #[expect(missing_docs, reason = "no need for doc")]
4393    type Base;
4394    #[expect(missing_docs, reason = "no need for doc")]
4395    type Output;
4396    #[expect(missing_docs, reason = "no need for doc")]
4397    type Error;
4398    ///Checked logarithm: computes <code>log<sub>base</sub> value</code>, returning an error if `value` is negative or zero, or if `base` is less than 2.
4399    ///
4400    ///Wrapper for `checked_ilog`.
4401    fn cilog(self, base: Self::Base) -> Result<Self::Output, Self::Error>;
4402}
4403///Checked logarithm: computes <code>log<sub>base</sub> value</code>, returning an error if `value` is negative or zero, or if `base` is less than 2.
4404///
4405///Wrapper for `checked_ilog`.
4406///
4407///See also: [module documentation](self).
4408#[doc(alias = "checked_ilog")]
4409#[inline]
4410pub fn cilog<T>(value: T, base: T::Base) -> Result<T::Output, T::Error>
4411where
4412    T: Cilog,
4413{
4414    value.cilog(base)
4415}
4416impl Cilog for i8 {
4417    type Base = i8;
4418    type Output = u32;
4419    type Error = Error;
4420    ///Checked logarithm: computes <code>log<sub>base</sub> value</code>, returning an error if `value` is negative or zero, or if `base` is less than 2.
4421    ///
4422    ///Wrapper for [`i8::checked_ilog`].
4423    #[inline]
4424    fn cilog(self, base: i8) -> Result<u32, Error> {
4425        self.checked_ilog(base).ok_or_else(|| {
4426            Error::new({
4427                if base < 2 {
4428                    format!(
4429                        "failed to compute ilog({:?}, {:?}): base is less than 2",
4430                        self, base
4431                    )
4432                } else {
4433                    format!(
4434                        "failed to compute ilog({:?}, {:?}): first argument is not positive",
4435                        self, base
4436                    )
4437                }
4438            })
4439        })
4440    }
4441}
4442impl Cilog for i16 {
4443    type Base = i16;
4444    type Output = u32;
4445    type Error = Error;
4446    ///Checked logarithm: computes <code>log<sub>base</sub> value</code>, returning an error if `value` is negative or zero, or if `base` is less than 2.
4447    ///
4448    ///Wrapper for [`i16::checked_ilog`].
4449    #[inline]
4450    fn cilog(self, base: i16) -> Result<u32, Error> {
4451        self.checked_ilog(base).ok_or_else(|| {
4452            Error::new({
4453                if base < 2 {
4454                    format!(
4455                        "failed to compute ilog({:?}, {:?}): base is less than 2",
4456                        self, base
4457                    )
4458                } else {
4459                    format!(
4460                        "failed to compute ilog({:?}, {:?}): first argument is not positive",
4461                        self, base
4462                    )
4463                }
4464            })
4465        })
4466    }
4467}
4468impl Cilog for i32 {
4469    type Base = i32;
4470    type Output = u32;
4471    type Error = Error;
4472    ///Checked logarithm: computes <code>log<sub>base</sub> value</code>, returning an error if `value` is negative or zero, or if `base` is less than 2.
4473    ///
4474    ///Wrapper for [`i32::checked_ilog`].
4475    #[inline]
4476    fn cilog(self, base: i32) -> Result<u32, Error> {
4477        self.checked_ilog(base).ok_or_else(|| {
4478            Error::new({
4479                if base < 2 {
4480                    format!(
4481                        "failed to compute ilog({:?}, {:?}): base is less than 2",
4482                        self, base
4483                    )
4484                } else {
4485                    format!(
4486                        "failed to compute ilog({:?}, {:?}): first argument is not positive",
4487                        self, base
4488                    )
4489                }
4490            })
4491        })
4492    }
4493}
4494impl Cilog for i64 {
4495    type Base = i64;
4496    type Output = u32;
4497    type Error = Error;
4498    ///Checked logarithm: computes <code>log<sub>base</sub> value</code>, returning an error if `value` is negative or zero, or if `base` is less than 2.
4499    ///
4500    ///Wrapper for [`i64::checked_ilog`].
4501    #[inline]
4502    fn cilog(self, base: i64) -> Result<u32, Error> {
4503        self.checked_ilog(base).ok_or_else(|| {
4504            Error::new({
4505                if base < 2 {
4506                    format!(
4507                        "failed to compute ilog({:?}, {:?}): base is less than 2",
4508                        self, base
4509                    )
4510                } else {
4511                    format!(
4512                        "failed to compute ilog({:?}, {:?}): first argument is not positive",
4513                        self, base
4514                    )
4515                }
4516            })
4517        })
4518    }
4519}
4520impl Cilog for i128 {
4521    type Base = i128;
4522    type Output = u32;
4523    type Error = Error;
4524    ///Checked logarithm: computes <code>log<sub>base</sub> value</code>, returning an error if `value` is negative or zero, or if `base` is less than 2.
4525    ///
4526    ///Wrapper for [`i128::checked_ilog`].
4527    #[inline]
4528    fn cilog(self, base: i128) -> Result<u32, Error> {
4529        self.checked_ilog(base).ok_or_else(|| {
4530            Error::new({
4531                if base < 2 {
4532                    format!(
4533                        "failed to compute ilog({:?}, {:?}): base is less than 2",
4534                        self, base
4535                    )
4536                } else {
4537                    format!(
4538                        "failed to compute ilog({:?}, {:?}): first argument is not positive",
4539                        self, base
4540                    )
4541                }
4542            })
4543        })
4544    }
4545}
4546impl Cilog for isize {
4547    type Base = isize;
4548    type Output = u32;
4549    type Error = Error;
4550    ///Checked logarithm: computes <code>log<sub>base</sub> value</code>, returning an error if `value` is negative or zero, or if `base` is less than 2.
4551    ///
4552    ///Wrapper for [`isize::checked_ilog`].
4553    #[inline]
4554    fn cilog(self, base: isize) -> Result<u32, Error> {
4555        self.checked_ilog(base).ok_or_else(|| {
4556            Error::new({
4557                if base < 2 {
4558                    format!(
4559                        "failed to compute ilog({:?}, {:?}): base is less than 2",
4560                        self, base
4561                    )
4562                } else {
4563                    format!(
4564                        "failed to compute ilog({:?}, {:?}): first argument is not positive",
4565                        self, base
4566                    )
4567                }
4568            })
4569        })
4570    }
4571}
4572impl Cilog for u8 {
4573    type Base = u8;
4574    type Output = u32;
4575    type Error = Error;
4576    ///Checked logarithm: computes <code>log<sub>base</sub> value</code>, returning an error if `value` is negative or zero, or if `base` is less than 2.
4577    ///
4578    ///Wrapper for [`u8::checked_ilog`].
4579    #[inline]
4580    fn cilog(self, base: u8) -> Result<u32, Error> {
4581        self.checked_ilog(base).ok_or_else(|| {
4582            Error::new({
4583                if base < 2 {
4584                    format!(
4585                        "failed to compute ilog({:?}, {:?}): base is less than 2",
4586                        self, base
4587                    )
4588                } else {
4589                    format!(
4590                        "failed to compute ilog({:?}, {:?}): first argument is not positive",
4591                        self, base
4592                    )
4593                }
4594            })
4595        })
4596    }
4597}
4598impl Cilog for u16 {
4599    type Base = u16;
4600    type Output = u32;
4601    type Error = Error;
4602    ///Checked logarithm: computes <code>log<sub>base</sub> value</code>, returning an error if `value` is negative or zero, or if `base` is less than 2.
4603    ///
4604    ///Wrapper for [`u16::checked_ilog`].
4605    #[inline]
4606    fn cilog(self, base: u16) -> Result<u32, Error> {
4607        self.checked_ilog(base).ok_or_else(|| {
4608            Error::new({
4609                if base < 2 {
4610                    format!(
4611                        "failed to compute ilog({:?}, {:?}): base is less than 2",
4612                        self, base
4613                    )
4614                } else {
4615                    format!(
4616                        "failed to compute ilog({:?}, {:?}): first argument is not positive",
4617                        self, base
4618                    )
4619                }
4620            })
4621        })
4622    }
4623}
4624impl Cilog for u32 {
4625    type Base = u32;
4626    type Output = u32;
4627    type Error = Error;
4628    ///Checked logarithm: computes <code>log<sub>base</sub> value</code>, returning an error if `value` is negative or zero, or if `base` is less than 2.
4629    ///
4630    ///Wrapper for [`u32::checked_ilog`].
4631    #[inline]
4632    fn cilog(self, base: u32) -> Result<u32, Error> {
4633        self.checked_ilog(base).ok_or_else(|| {
4634            Error::new({
4635                if base < 2 {
4636                    format!(
4637                        "failed to compute ilog({:?}, {:?}): base is less than 2",
4638                        self, base
4639                    )
4640                } else {
4641                    format!(
4642                        "failed to compute ilog({:?}, {:?}): first argument is not positive",
4643                        self, base
4644                    )
4645                }
4646            })
4647        })
4648    }
4649}
4650impl Cilog for u64 {
4651    type Base = u64;
4652    type Output = u32;
4653    type Error = Error;
4654    ///Checked logarithm: computes <code>log<sub>base</sub> value</code>, returning an error if `value` is negative or zero, or if `base` is less than 2.
4655    ///
4656    ///Wrapper for [`u64::checked_ilog`].
4657    #[inline]
4658    fn cilog(self, base: u64) -> Result<u32, Error> {
4659        self.checked_ilog(base).ok_or_else(|| {
4660            Error::new({
4661                if base < 2 {
4662                    format!(
4663                        "failed to compute ilog({:?}, {:?}): base is less than 2",
4664                        self, base
4665                    )
4666                } else {
4667                    format!(
4668                        "failed to compute ilog({:?}, {:?}): first argument is not positive",
4669                        self, base
4670                    )
4671                }
4672            })
4673        })
4674    }
4675}
4676impl Cilog for u128 {
4677    type Base = u128;
4678    type Output = u32;
4679    type Error = Error;
4680    ///Checked logarithm: computes <code>log<sub>base</sub> value</code>, returning an error if `value` is negative or zero, or if `base` is less than 2.
4681    ///
4682    ///Wrapper for [`u128::checked_ilog`].
4683    #[inline]
4684    fn cilog(self, base: u128) -> Result<u32, Error> {
4685        self.checked_ilog(base).ok_or_else(|| {
4686            Error::new({
4687                if base < 2 {
4688                    format!(
4689                        "failed to compute ilog({:?}, {:?}): base is less than 2",
4690                        self, base
4691                    )
4692                } else {
4693                    format!(
4694                        "failed to compute ilog({:?}, {:?}): first argument is not positive",
4695                        self, base
4696                    )
4697                }
4698            })
4699        })
4700    }
4701}
4702impl Cilog for usize {
4703    type Base = usize;
4704    type Output = u32;
4705    type Error = Error;
4706    ///Checked logarithm: computes <code>log<sub>base</sub> value</code>, returning an error if `value` is negative or zero, or if `base` is less than 2.
4707    ///
4708    ///Wrapper for [`usize::checked_ilog`].
4709    #[inline]
4710    fn cilog(self, base: usize) -> Result<u32, Error> {
4711        self.checked_ilog(base).ok_or_else(|| {
4712            Error::new({
4713                if base < 2 {
4714                    format!(
4715                        "failed to compute ilog({:?}, {:?}): base is less than 2",
4716                        self, base
4717                    )
4718                } else {
4719                    format!(
4720                        "failed to compute ilog({:?}, {:?}): first argument is not positive",
4721                        self, base
4722                    )
4723                }
4724            })
4725        })
4726    }
4727}
4728///Checked base 2 logarithm: computes `ln value`, returning an error if `value` is negative or zero.
4729///
4730///See also: [module documentation](self).
4731pub trait Cilog2: Sized {
4732    #[expect(missing_docs, reason = "no need for doc")]
4733    type Output;
4734    #[expect(missing_docs, reason = "no need for doc")]
4735    type Error;
4736    ///Checked base 2 logarithm: computes `ln value`, returning an error if `value` is negative or zero.
4737    ///
4738    ///Wrapper for `checked_ilog2`.
4739    fn cilog2(self) -> Result<Self::Output, Self::Error>;
4740}
4741///Checked base 2 logarithm: computes `ln value`, returning an error if `value` is negative or zero.
4742///
4743///Wrapper for `checked_ilog2`.
4744#[doc(alias = "checked_ilog2")]
4745#[inline]
4746pub fn cilog2<T>(value: T) -> Result<T::Output, T::Error>
4747where
4748    T: Cilog2,
4749{
4750    Cilog2::cilog2(value)
4751}
4752impl Cilog2 for i8 {
4753    type Output = u32;
4754    type Error = Error;
4755    ///Checked base 2 logarithm: computes `ln value`, returning an error if `value` is negative or zero.
4756    ///
4757    ///Wrapper for [`i8::checked_ilog2`].
4758    #[inline]
4759    fn cilog2(self) -> Result<u32, Error> {
4760        self.checked_ilog2().ok_or_else(|| {
4761            Error::new(format!(
4762                "failed to compute ilog2({:?}): argument is not positive",
4763                self
4764            ))
4765        })
4766    }
4767}
4768impl Cilog2 for i16 {
4769    type Output = u32;
4770    type Error = Error;
4771    ///Checked base 2 logarithm: computes `ln value`, returning an error if `value` is negative or zero.
4772    ///
4773    ///Wrapper for [`i16::checked_ilog2`].
4774    #[inline]
4775    fn cilog2(self) -> Result<u32, Error> {
4776        self.checked_ilog2().ok_or_else(|| {
4777            Error::new(format!(
4778                "failed to compute ilog2({:?}): argument is not positive",
4779                self
4780            ))
4781        })
4782    }
4783}
4784impl Cilog2 for i32 {
4785    type Output = u32;
4786    type Error = Error;
4787    ///Checked base 2 logarithm: computes `ln value`, returning an error if `value` is negative or zero.
4788    ///
4789    ///Wrapper for [`i32::checked_ilog2`].
4790    #[inline]
4791    fn cilog2(self) -> Result<u32, Error> {
4792        self.checked_ilog2().ok_or_else(|| {
4793            Error::new(format!(
4794                "failed to compute ilog2({:?}): argument is not positive",
4795                self
4796            ))
4797        })
4798    }
4799}
4800impl Cilog2 for i64 {
4801    type Output = u32;
4802    type Error = Error;
4803    ///Checked base 2 logarithm: computes `ln value`, returning an error if `value` is negative or zero.
4804    ///
4805    ///Wrapper for [`i64::checked_ilog2`].
4806    #[inline]
4807    fn cilog2(self) -> Result<u32, Error> {
4808        self.checked_ilog2().ok_or_else(|| {
4809            Error::new(format!(
4810                "failed to compute ilog2({:?}): argument is not positive",
4811                self
4812            ))
4813        })
4814    }
4815}
4816impl Cilog2 for i128 {
4817    type Output = u32;
4818    type Error = Error;
4819    ///Checked base 2 logarithm: computes `ln value`, returning an error if `value` is negative or zero.
4820    ///
4821    ///Wrapper for [`i128::checked_ilog2`].
4822    #[inline]
4823    fn cilog2(self) -> Result<u32, Error> {
4824        self.checked_ilog2().ok_or_else(|| {
4825            Error::new(format!(
4826                "failed to compute ilog2({:?}): argument is not positive",
4827                self
4828            ))
4829        })
4830    }
4831}
4832impl Cilog2 for isize {
4833    type Output = u32;
4834    type Error = Error;
4835    ///Checked base 2 logarithm: computes `ln value`, returning an error if `value` is negative or zero.
4836    ///
4837    ///Wrapper for [`isize::checked_ilog2`].
4838    #[inline]
4839    fn cilog2(self) -> Result<u32, Error> {
4840        self.checked_ilog2().ok_or_else(|| {
4841            Error::new(format!(
4842                "failed to compute ilog2({:?}): argument is not positive",
4843                self
4844            ))
4845        })
4846    }
4847}
4848impl Cilog2 for u8 {
4849    type Output = u32;
4850    type Error = Error;
4851    ///Checked base 2 logarithm: computes `ln value`, returning an error if `value` is negative or zero.
4852    ///
4853    ///Wrapper for [`u8::checked_ilog2`].
4854    #[inline]
4855    fn cilog2(self) -> Result<u32, Error> {
4856        self.checked_ilog2().ok_or_else(|| {
4857            Error::new(format!(
4858                "failed to compute ilog2({:?}): argument is not positive",
4859                self
4860            ))
4861        })
4862    }
4863}
4864impl Cilog2 for u16 {
4865    type Output = u32;
4866    type Error = Error;
4867    ///Checked base 2 logarithm: computes `ln value`, returning an error if `value` is negative or zero.
4868    ///
4869    ///Wrapper for [`u16::checked_ilog2`].
4870    #[inline]
4871    fn cilog2(self) -> Result<u32, Error> {
4872        self.checked_ilog2().ok_or_else(|| {
4873            Error::new(format!(
4874                "failed to compute ilog2({:?}): argument is not positive",
4875                self
4876            ))
4877        })
4878    }
4879}
4880impl Cilog2 for u32 {
4881    type Output = u32;
4882    type Error = Error;
4883    ///Checked base 2 logarithm: computes `ln value`, returning an error if `value` is negative or zero.
4884    ///
4885    ///Wrapper for [`u32::checked_ilog2`].
4886    #[inline]
4887    fn cilog2(self) -> Result<u32, Error> {
4888        self.checked_ilog2().ok_or_else(|| {
4889            Error::new(format!(
4890                "failed to compute ilog2({:?}): argument is not positive",
4891                self
4892            ))
4893        })
4894    }
4895}
4896impl Cilog2 for u64 {
4897    type Output = u32;
4898    type Error = Error;
4899    ///Checked base 2 logarithm: computes `ln value`, returning an error if `value` is negative or zero.
4900    ///
4901    ///Wrapper for [`u64::checked_ilog2`].
4902    #[inline]
4903    fn cilog2(self) -> Result<u32, Error> {
4904        self.checked_ilog2().ok_or_else(|| {
4905            Error::new(format!(
4906                "failed to compute ilog2({:?}): argument is not positive",
4907                self
4908            ))
4909        })
4910    }
4911}
4912impl Cilog2 for u128 {
4913    type Output = u32;
4914    type Error = Error;
4915    ///Checked base 2 logarithm: computes `ln value`, returning an error if `value` is negative or zero.
4916    ///
4917    ///Wrapper for [`u128::checked_ilog2`].
4918    #[inline]
4919    fn cilog2(self) -> Result<u32, Error> {
4920        self.checked_ilog2().ok_or_else(|| {
4921            Error::new(format!(
4922                "failed to compute ilog2({:?}): argument is not positive",
4923                self
4924            ))
4925        })
4926    }
4927}
4928impl Cilog2 for usize {
4929    type Output = u32;
4930    type Error = Error;
4931    ///Checked base 2 logarithm: computes `ln value`, returning an error if `value` is negative or zero.
4932    ///
4933    ///Wrapper for [`usize::checked_ilog2`].
4934    #[inline]
4935    fn cilog2(self) -> Result<u32, Error> {
4936        self.checked_ilog2().ok_or_else(|| {
4937            Error::new(format!(
4938                "failed to compute ilog2({:?}): argument is not positive",
4939                self
4940            ))
4941        })
4942    }
4943}
4944///Checked base 10 logarithm: computes <code>log<sub>10</sub> value</code>, returning an error if `value` is negative or zero.
4945///
4946///See also: [module documentation](self).
4947pub trait Cilog10: Sized {
4948    #[expect(missing_docs, reason = "no need for doc")]
4949    type Output;
4950    #[expect(missing_docs, reason = "no need for doc")]
4951    type Error;
4952    ///Checked base 10 logarithm: computes <code>log<sub>10</sub> value</code>, returning an error if `value` is negative or zero.
4953    ///
4954    ///Wrapper for `checked_ilog10`.
4955    fn cilog10(self) -> Result<Self::Output, Self::Error>;
4956}
4957///Checked base 10 logarithm: computes <code>log<sub>10</sub> value</code>, returning an error if `value` is negative or zero.
4958///
4959///Wrapper for `checked_ilog10`.
4960#[doc(alias = "checked_ilog10")]
4961#[inline]
4962pub fn cilog10<T>(value: T) -> Result<T::Output, T::Error>
4963where
4964    T: Cilog10,
4965{
4966    Cilog10::cilog10(value)
4967}
4968impl Cilog10 for i8 {
4969    type Output = u32;
4970    type Error = Error;
4971    ///Checked base 10 logarithm: computes <code>log<sub>10</sub> value</code>, returning an error if `value` is negative or zero.
4972    ///
4973    ///Wrapper for [`i8::checked_ilog10`].
4974    #[inline]
4975    fn cilog10(self) -> Result<u32, Error> {
4976        self.checked_ilog10().ok_or_else(|| {
4977            Error::new(format!(
4978                "failed to compute ilog10({:?}): argument is not positive",
4979                self
4980            ))
4981        })
4982    }
4983}
4984impl Cilog10 for i16 {
4985    type Output = u32;
4986    type Error = Error;
4987    ///Checked base 10 logarithm: computes <code>log<sub>10</sub> value</code>, returning an error if `value` is negative or zero.
4988    ///
4989    ///Wrapper for [`i16::checked_ilog10`].
4990    #[inline]
4991    fn cilog10(self) -> Result<u32, Error> {
4992        self.checked_ilog10().ok_or_else(|| {
4993            Error::new(format!(
4994                "failed to compute ilog10({:?}): argument is not positive",
4995                self
4996            ))
4997        })
4998    }
4999}
5000impl Cilog10 for i32 {
5001    type Output = u32;
5002    type Error = Error;
5003    ///Checked base 10 logarithm: computes <code>log<sub>10</sub> value</code>, returning an error if `value` is negative or zero.
5004    ///
5005    ///Wrapper for [`i32::checked_ilog10`].
5006    #[inline]
5007    fn cilog10(self) -> Result<u32, Error> {
5008        self.checked_ilog10().ok_or_else(|| {
5009            Error::new(format!(
5010                "failed to compute ilog10({:?}): argument is not positive",
5011                self
5012            ))
5013        })
5014    }
5015}
5016impl Cilog10 for i64 {
5017    type Output = u32;
5018    type Error = Error;
5019    ///Checked base 10 logarithm: computes <code>log<sub>10</sub> value</code>, returning an error if `value` is negative or zero.
5020    ///
5021    ///Wrapper for [`i64::checked_ilog10`].
5022    #[inline]
5023    fn cilog10(self) -> Result<u32, Error> {
5024        self.checked_ilog10().ok_or_else(|| {
5025            Error::new(format!(
5026                "failed to compute ilog10({:?}): argument is not positive",
5027                self
5028            ))
5029        })
5030    }
5031}
5032impl Cilog10 for i128 {
5033    type Output = u32;
5034    type Error = Error;
5035    ///Checked base 10 logarithm: computes <code>log<sub>10</sub> value</code>, returning an error if `value` is negative or zero.
5036    ///
5037    ///Wrapper for [`i128::checked_ilog10`].
5038    #[inline]
5039    fn cilog10(self) -> Result<u32, Error> {
5040        self.checked_ilog10().ok_or_else(|| {
5041            Error::new(format!(
5042                "failed to compute ilog10({:?}): argument is not positive",
5043                self
5044            ))
5045        })
5046    }
5047}
5048impl Cilog10 for isize {
5049    type Output = u32;
5050    type Error = Error;
5051    ///Checked base 10 logarithm: computes <code>log<sub>10</sub> value</code>, returning an error if `value` is negative or zero.
5052    ///
5053    ///Wrapper for [`isize::checked_ilog10`].
5054    #[inline]
5055    fn cilog10(self) -> Result<u32, Error> {
5056        self.checked_ilog10().ok_or_else(|| {
5057            Error::new(format!(
5058                "failed to compute ilog10({:?}): argument is not positive",
5059                self
5060            ))
5061        })
5062    }
5063}
5064impl Cilog10 for u8 {
5065    type Output = u32;
5066    type Error = Error;
5067    ///Checked base 10 logarithm: computes <code>log<sub>10</sub> value</code>, returning an error if `value` is negative or zero.
5068    ///
5069    ///Wrapper for [`u8::checked_ilog10`].
5070    #[inline]
5071    fn cilog10(self) -> Result<u32, Error> {
5072        self.checked_ilog10().ok_or_else(|| {
5073            Error::new(format!(
5074                "failed to compute ilog10({:?}): argument is not positive",
5075                self
5076            ))
5077        })
5078    }
5079}
5080impl Cilog10 for u16 {
5081    type Output = u32;
5082    type Error = Error;
5083    ///Checked base 10 logarithm: computes <code>log<sub>10</sub> value</code>, returning an error if `value` is negative or zero.
5084    ///
5085    ///Wrapper for [`u16::checked_ilog10`].
5086    #[inline]
5087    fn cilog10(self) -> Result<u32, Error> {
5088        self.checked_ilog10().ok_or_else(|| {
5089            Error::new(format!(
5090                "failed to compute ilog10({:?}): argument is not positive",
5091                self
5092            ))
5093        })
5094    }
5095}
5096impl Cilog10 for u32 {
5097    type Output = u32;
5098    type Error = Error;
5099    ///Checked base 10 logarithm: computes <code>log<sub>10</sub> value</code>, returning an error if `value` is negative or zero.
5100    ///
5101    ///Wrapper for [`u32::checked_ilog10`].
5102    #[inline]
5103    fn cilog10(self) -> Result<u32, Error> {
5104        self.checked_ilog10().ok_or_else(|| {
5105            Error::new(format!(
5106                "failed to compute ilog10({:?}): argument is not positive",
5107                self
5108            ))
5109        })
5110    }
5111}
5112impl Cilog10 for u64 {
5113    type Output = u32;
5114    type Error = Error;
5115    ///Checked base 10 logarithm: computes <code>log<sub>10</sub> value</code>, returning an error if `value` is negative or zero.
5116    ///
5117    ///Wrapper for [`u64::checked_ilog10`].
5118    #[inline]
5119    fn cilog10(self) -> Result<u32, Error> {
5120        self.checked_ilog10().ok_or_else(|| {
5121            Error::new(format!(
5122                "failed to compute ilog10({:?}): argument is not positive",
5123                self
5124            ))
5125        })
5126    }
5127}
5128impl Cilog10 for u128 {
5129    type Output = u32;
5130    type Error = Error;
5131    ///Checked base 10 logarithm: computes <code>log<sub>10</sub> value</code>, returning an error if `value` is negative or zero.
5132    ///
5133    ///Wrapper for [`u128::checked_ilog10`].
5134    #[inline]
5135    fn cilog10(self) -> Result<u32, Error> {
5136        self.checked_ilog10().ok_or_else(|| {
5137            Error::new(format!(
5138                "failed to compute ilog10({:?}): argument is not positive",
5139                self
5140            ))
5141        })
5142    }
5143}
5144impl Cilog10 for usize {
5145    type Output = u32;
5146    type Error = Error;
5147    ///Checked base 10 logarithm: computes <code>log<sub>10</sub> value</code>, returning an error if `value` is negative or zero.
5148    ///
5149    ///Wrapper for [`usize::checked_ilog10`].
5150    #[inline]
5151    fn cilog10(self) -> Result<u32, Error> {
5152        self.checked_ilog10().ok_or_else(|| {
5153            Error::new(format!(
5154                "failed to compute ilog10({:?}): argument is not positive",
5155                self
5156            ))
5157        })
5158    }
5159}
5160///Checked shift left: computes `a << b`, returning an error if `b` is greater or equal to the number of bits in the type.
5161///
5162///See also: [module documentation](self).
5163pub trait Cshl: Sized {
5164    #[expect(missing_docs, reason = "no need for doc")]
5165    type Other;
5166    #[expect(missing_docs, reason = "no need for doc")]
5167    type Output;
5168    #[expect(missing_docs, reason = "no need for doc")]
5169    type Error;
5170    ///Checked shift left: computes `a << b`, returning an error if `b` is greater or equal to the number of bits in the type.
5171    ///
5172    ///Wrapper for `checked_shl`.
5173    fn cshl(self, other: Self::Other) -> Result<Self::Output, Self::Error>;
5174    ///Checked shift left assigement: executes `self <<= other`, returning an error if `other` is greater or equal to the number of bits in the type.
5175    ///
5176    ///Wrapper for `checked_shl`.
5177    fn cshl_assign(&mut self, other: Self::Other) -> Result<(), Self::Error>;
5178}
5179///Checked shift left: computes `a << b`, returning an error if `b` is greater or equal to the number of bits in the type.
5180///
5181///Wrapper for `checked_shl`.
5182///
5183///See also: [module documentation](self).
5184#[doc(alias = "checked_shl")]
5185#[inline]
5186pub fn cshl<T>(a: T, b: T::Other) -> Result<T::Output, T::Error>
5187where
5188    T: Cshl,
5189{
5190    a.cshl(b)
5191}
5192impl Cshl for i8 {
5193    type Other = u32;
5194    type Output = i8;
5195    type Error = Error;
5196    ///Checked shift left: computes `a << b`, returning an error if `b` is greater or equal to the number of bits in the type.
5197    ///
5198    ///Wrapper for [`i8::checked_shl`].
5199    #[inline]
5200    fn cshl(self, other: u32) -> Result<i8, Error> {
5201        self.checked_shl(other).ok_or_else(|| {
5202            Error::new(format!(
5203                "failed to compute {:?} << {:?}: shift amount is too large",
5204                MaybeParens(self),
5205                MaybeParens(other)
5206            ))
5207        })
5208    }
5209    #[inline]
5210    ///Checked shift left assigement: executes `self <<= other`, returning an error if `other` is greater or equal to the number of bits in the type.
5211    ///
5212    ///Wrapper for [`i8::checked_shl`].
5213    fn cshl_assign(&mut self, other: u32) -> Result<(), Self::Error> {
5214        *self = self.cshl(other)?;
5215        Ok(())
5216    }
5217}
5218impl Cshl for i16 {
5219    type Other = u32;
5220    type Output = i16;
5221    type Error = Error;
5222    ///Checked shift left: computes `a << b`, returning an error if `b` is greater or equal to the number of bits in the type.
5223    ///
5224    ///Wrapper for [`i16::checked_shl`].
5225    #[inline]
5226    fn cshl(self, other: u32) -> Result<i16, Error> {
5227        self.checked_shl(other).ok_or_else(|| {
5228            Error::new(format!(
5229                "failed to compute {:?} << {:?}: shift amount is too large",
5230                MaybeParens(self),
5231                MaybeParens(other)
5232            ))
5233        })
5234    }
5235    #[inline]
5236    ///Checked shift left assigement: executes `self <<= other`, returning an error if `other` is greater or equal to the number of bits in the type.
5237    ///
5238    ///Wrapper for [`i16::checked_shl`].
5239    fn cshl_assign(&mut self, other: u32) -> Result<(), Self::Error> {
5240        *self = self.cshl(other)?;
5241        Ok(())
5242    }
5243}
5244impl Cshl for i32 {
5245    type Other = u32;
5246    type Output = i32;
5247    type Error = Error;
5248    ///Checked shift left: computes `a << b`, returning an error if `b` is greater or equal to the number of bits in the type.
5249    ///
5250    ///Wrapper for [`i32::checked_shl`].
5251    #[inline]
5252    fn cshl(self, other: u32) -> Result<i32, Error> {
5253        self.checked_shl(other).ok_or_else(|| {
5254            Error::new(format!(
5255                "failed to compute {:?} << {:?}: shift amount is too large",
5256                MaybeParens(self),
5257                MaybeParens(other)
5258            ))
5259        })
5260    }
5261    #[inline]
5262    ///Checked shift left assigement: executes `self <<= other`, returning an error if `other` is greater or equal to the number of bits in the type.
5263    ///
5264    ///Wrapper for [`i32::checked_shl`].
5265    fn cshl_assign(&mut self, other: u32) -> Result<(), Self::Error> {
5266        *self = self.cshl(other)?;
5267        Ok(())
5268    }
5269}
5270impl Cshl for i64 {
5271    type Other = u32;
5272    type Output = i64;
5273    type Error = Error;
5274    ///Checked shift left: computes `a << b`, returning an error if `b` is greater or equal to the number of bits in the type.
5275    ///
5276    ///Wrapper for [`i64::checked_shl`].
5277    #[inline]
5278    fn cshl(self, other: u32) -> Result<i64, Error> {
5279        self.checked_shl(other).ok_or_else(|| {
5280            Error::new(format!(
5281                "failed to compute {:?} << {:?}: shift amount is too large",
5282                MaybeParens(self),
5283                MaybeParens(other)
5284            ))
5285        })
5286    }
5287    #[inline]
5288    ///Checked shift left assigement: executes `self <<= other`, returning an error if `other` is greater or equal to the number of bits in the type.
5289    ///
5290    ///Wrapper for [`i64::checked_shl`].
5291    fn cshl_assign(&mut self, other: u32) -> Result<(), Self::Error> {
5292        *self = self.cshl(other)?;
5293        Ok(())
5294    }
5295}
5296impl Cshl for i128 {
5297    type Other = u32;
5298    type Output = i128;
5299    type Error = Error;
5300    ///Checked shift left: computes `a << b`, returning an error if `b` is greater or equal to the number of bits in the type.
5301    ///
5302    ///Wrapper for [`i128::checked_shl`].
5303    #[inline]
5304    fn cshl(self, other: u32) -> Result<i128, Error> {
5305        self.checked_shl(other).ok_or_else(|| {
5306            Error::new(format!(
5307                "failed to compute {:?} << {:?}: shift amount is too large",
5308                MaybeParens(self),
5309                MaybeParens(other)
5310            ))
5311        })
5312    }
5313    #[inline]
5314    ///Checked shift left assigement: executes `self <<= other`, returning an error if `other` is greater or equal to the number of bits in the type.
5315    ///
5316    ///Wrapper for [`i128::checked_shl`].
5317    fn cshl_assign(&mut self, other: u32) -> Result<(), Self::Error> {
5318        *self = self.cshl(other)?;
5319        Ok(())
5320    }
5321}
5322impl Cshl for isize {
5323    type Other = u32;
5324    type Output = isize;
5325    type Error = Error;
5326    ///Checked shift left: computes `a << b`, returning an error if `b` is greater or equal to the number of bits in the type.
5327    ///
5328    ///Wrapper for [`isize::checked_shl`].
5329    #[inline]
5330    fn cshl(self, other: u32) -> Result<isize, Error> {
5331        self.checked_shl(other).ok_or_else(|| {
5332            Error::new(format!(
5333                "failed to compute {:?} << {:?}: shift amount is too large",
5334                MaybeParens(self),
5335                MaybeParens(other)
5336            ))
5337        })
5338    }
5339    #[inline]
5340    ///Checked shift left assigement: executes `self <<= other`, returning an error if `other` is greater or equal to the number of bits in the type.
5341    ///
5342    ///Wrapper for [`isize::checked_shl`].
5343    fn cshl_assign(&mut self, other: u32) -> Result<(), Self::Error> {
5344        *self = self.cshl(other)?;
5345        Ok(())
5346    }
5347}
5348impl Cshl for u8 {
5349    type Other = u32;
5350    type Output = u8;
5351    type Error = Error;
5352    ///Checked shift left: computes `a << b`, returning an error if `b` is greater or equal to the number of bits in the type.
5353    ///
5354    ///Wrapper for [`u8::checked_shl`].
5355    #[inline]
5356    fn cshl(self, other: u32) -> Result<u8, Error> {
5357        self.checked_shl(other).ok_or_else(|| {
5358            Error::new(format!(
5359                "failed to compute {:?} << {:?}: shift amount is too large",
5360                MaybeParens(self),
5361                MaybeParens(other)
5362            ))
5363        })
5364    }
5365    #[inline]
5366    ///Checked shift left assigement: executes `self <<= other`, returning an error if `other` is greater or equal to the number of bits in the type.
5367    ///
5368    ///Wrapper for [`u8::checked_shl`].
5369    fn cshl_assign(&mut self, other: u32) -> Result<(), Self::Error> {
5370        *self = self.cshl(other)?;
5371        Ok(())
5372    }
5373}
5374impl Cshl for u16 {
5375    type Other = u32;
5376    type Output = u16;
5377    type Error = Error;
5378    ///Checked shift left: computes `a << b`, returning an error if `b` is greater or equal to the number of bits in the type.
5379    ///
5380    ///Wrapper for [`u16::checked_shl`].
5381    #[inline]
5382    fn cshl(self, other: u32) -> Result<u16, Error> {
5383        self.checked_shl(other).ok_or_else(|| {
5384            Error::new(format!(
5385                "failed to compute {:?} << {:?}: shift amount is too large",
5386                MaybeParens(self),
5387                MaybeParens(other)
5388            ))
5389        })
5390    }
5391    #[inline]
5392    ///Checked shift left assigement: executes `self <<= other`, returning an error if `other` is greater or equal to the number of bits in the type.
5393    ///
5394    ///Wrapper for [`u16::checked_shl`].
5395    fn cshl_assign(&mut self, other: u32) -> Result<(), Self::Error> {
5396        *self = self.cshl(other)?;
5397        Ok(())
5398    }
5399}
5400impl Cshl for u32 {
5401    type Other = u32;
5402    type Output = u32;
5403    type Error = Error;
5404    ///Checked shift left: computes `a << b`, returning an error if `b` is greater or equal to the number of bits in the type.
5405    ///
5406    ///Wrapper for [`u32::checked_shl`].
5407    #[inline]
5408    fn cshl(self, other: u32) -> Result<u32, Error> {
5409        self.checked_shl(other).ok_or_else(|| {
5410            Error::new(format!(
5411                "failed to compute {:?} << {:?}: shift amount is too large",
5412                MaybeParens(self),
5413                MaybeParens(other)
5414            ))
5415        })
5416    }
5417    #[inline]
5418    ///Checked shift left assigement: executes `self <<= other`, returning an error if `other` is greater or equal to the number of bits in the type.
5419    ///
5420    ///Wrapper for [`u32::checked_shl`].
5421    fn cshl_assign(&mut self, other: u32) -> Result<(), Self::Error> {
5422        *self = self.cshl(other)?;
5423        Ok(())
5424    }
5425}
5426impl Cshl for u64 {
5427    type Other = u32;
5428    type Output = u64;
5429    type Error = Error;
5430    ///Checked shift left: computes `a << b`, returning an error if `b` is greater or equal to the number of bits in the type.
5431    ///
5432    ///Wrapper for [`u64::checked_shl`].
5433    #[inline]
5434    fn cshl(self, other: u32) -> Result<u64, Error> {
5435        self.checked_shl(other).ok_or_else(|| {
5436            Error::new(format!(
5437                "failed to compute {:?} << {:?}: shift amount is too large",
5438                MaybeParens(self),
5439                MaybeParens(other)
5440            ))
5441        })
5442    }
5443    #[inline]
5444    ///Checked shift left assigement: executes `self <<= other`, returning an error if `other` is greater or equal to the number of bits in the type.
5445    ///
5446    ///Wrapper for [`u64::checked_shl`].
5447    fn cshl_assign(&mut self, other: u32) -> Result<(), Self::Error> {
5448        *self = self.cshl(other)?;
5449        Ok(())
5450    }
5451}
5452impl Cshl for u128 {
5453    type Other = u32;
5454    type Output = u128;
5455    type Error = Error;
5456    ///Checked shift left: computes `a << b`, returning an error if `b` is greater or equal to the number of bits in the type.
5457    ///
5458    ///Wrapper for [`u128::checked_shl`].
5459    #[inline]
5460    fn cshl(self, other: u32) -> Result<u128, Error> {
5461        self.checked_shl(other).ok_or_else(|| {
5462            Error::new(format!(
5463                "failed to compute {:?} << {:?}: shift amount is too large",
5464                MaybeParens(self),
5465                MaybeParens(other)
5466            ))
5467        })
5468    }
5469    #[inline]
5470    ///Checked shift left assigement: executes `self <<= other`, returning an error if `other` is greater or equal to the number of bits in the type.
5471    ///
5472    ///Wrapper for [`u128::checked_shl`].
5473    fn cshl_assign(&mut self, other: u32) -> Result<(), Self::Error> {
5474        *self = self.cshl(other)?;
5475        Ok(())
5476    }
5477}
5478impl Cshl for usize {
5479    type Other = u32;
5480    type Output = usize;
5481    type Error = Error;
5482    ///Checked shift left: computes `a << b`, returning an error if `b` is greater or equal to the number of bits in the type.
5483    ///
5484    ///Wrapper for [`usize::checked_shl`].
5485    #[inline]
5486    fn cshl(self, other: u32) -> Result<usize, Error> {
5487        self.checked_shl(other).ok_or_else(|| {
5488            Error::new(format!(
5489                "failed to compute {:?} << {:?}: shift amount is too large",
5490                MaybeParens(self),
5491                MaybeParens(other)
5492            ))
5493        })
5494    }
5495    #[inline]
5496    ///Checked shift left assigement: executes `self <<= other`, returning an error if `other` is greater or equal to the number of bits in the type.
5497    ///
5498    ///Wrapper for [`usize::checked_shl`].
5499    fn cshl_assign(&mut self, other: u32) -> Result<(), Self::Error> {
5500        *self = self.cshl(other)?;
5501        Ok(())
5502    }
5503}
5504///Checked shift right: computes `a >> b`, returning an error if `b` is greater or equal to the number of bits in the type.
5505///
5506///See also: [module documentation](self).
5507pub trait Cshr: Sized {
5508    #[expect(missing_docs, reason = "no need for doc")]
5509    type Other;
5510    #[expect(missing_docs, reason = "no need for doc")]
5511    type Output;
5512    #[expect(missing_docs, reason = "no need for doc")]
5513    type Error;
5514    ///Checked shift right: computes `a >> b`, returning an error if `b` is greater or equal to the number of bits in the type.
5515    ///
5516    ///Wrapper for `checked_shr`.
5517    fn cshr(self, other: Self::Other) -> Result<Self::Output, Self::Error>;
5518    ///Checked shift right assigement: executes `self >>= other`, returning an error if `other` is greater or equal to the number of bits in the type.
5519    ///
5520    ///Wrapper for `checked_shr`.
5521    fn cshr_assign(&mut self, other: Self::Other) -> Result<(), Self::Error>;
5522}
5523///Checked shift right: computes `a >> b`, returning an error if `b` is greater or equal to the number of bits in the type.
5524///
5525///Wrapper for `checked_shr`.
5526///
5527///See also: [module documentation](self).
5528#[doc(alias = "checked_shr")]
5529#[inline]
5530pub fn cshr<T>(a: T, b: T::Other) -> Result<T::Output, T::Error>
5531where
5532    T: Cshr,
5533{
5534    a.cshr(b)
5535}
5536impl Cshr for i8 {
5537    type Other = u32;
5538    type Output = i8;
5539    type Error = Error;
5540    ///Checked shift right: computes `a >> b`, returning an error if `b` is greater or equal to the number of bits in the type.
5541    ///
5542    ///Wrapper for [`i8::checked_shr`].
5543    #[inline]
5544    fn cshr(self, other: u32) -> Result<i8, Error> {
5545        self.checked_shr(other).ok_or_else(|| {
5546            Error::new(format!(
5547                "failed to compute {:?} >> {:?}: shift amount is too large",
5548                MaybeParens(self),
5549                MaybeParens(other)
5550            ))
5551        })
5552    }
5553    #[inline]
5554    ///Checked shift right assigement: executes `self >>= other`, returning an error if `other` is greater or equal to the number of bits in the type.
5555    ///
5556    ///Wrapper for [`i8::checked_shr`].
5557    fn cshr_assign(&mut self, other: u32) -> Result<(), Self::Error> {
5558        *self = self.cshr(other)?;
5559        Ok(())
5560    }
5561}
5562impl Cshr for i16 {
5563    type Other = u32;
5564    type Output = i16;
5565    type Error = Error;
5566    ///Checked shift right: computes `a >> b`, returning an error if `b` is greater or equal to the number of bits in the type.
5567    ///
5568    ///Wrapper for [`i16::checked_shr`].
5569    #[inline]
5570    fn cshr(self, other: u32) -> Result<i16, Error> {
5571        self.checked_shr(other).ok_or_else(|| {
5572            Error::new(format!(
5573                "failed to compute {:?} >> {:?}: shift amount is too large",
5574                MaybeParens(self),
5575                MaybeParens(other)
5576            ))
5577        })
5578    }
5579    #[inline]
5580    ///Checked shift right assigement: executes `self >>= other`, returning an error if `other` is greater or equal to the number of bits in the type.
5581    ///
5582    ///Wrapper for [`i16::checked_shr`].
5583    fn cshr_assign(&mut self, other: u32) -> Result<(), Self::Error> {
5584        *self = self.cshr(other)?;
5585        Ok(())
5586    }
5587}
5588impl Cshr for i32 {
5589    type Other = u32;
5590    type Output = i32;
5591    type Error = Error;
5592    ///Checked shift right: computes `a >> b`, returning an error if `b` is greater or equal to the number of bits in the type.
5593    ///
5594    ///Wrapper for [`i32::checked_shr`].
5595    #[inline]
5596    fn cshr(self, other: u32) -> Result<i32, Error> {
5597        self.checked_shr(other).ok_or_else(|| {
5598            Error::new(format!(
5599                "failed to compute {:?} >> {:?}: shift amount is too large",
5600                MaybeParens(self),
5601                MaybeParens(other)
5602            ))
5603        })
5604    }
5605    #[inline]
5606    ///Checked shift right assigement: executes `self >>= other`, returning an error if `other` is greater or equal to the number of bits in the type.
5607    ///
5608    ///Wrapper for [`i32::checked_shr`].
5609    fn cshr_assign(&mut self, other: u32) -> Result<(), Self::Error> {
5610        *self = self.cshr(other)?;
5611        Ok(())
5612    }
5613}
5614impl Cshr for i64 {
5615    type Other = u32;
5616    type Output = i64;
5617    type Error = Error;
5618    ///Checked shift right: computes `a >> b`, returning an error if `b` is greater or equal to the number of bits in the type.
5619    ///
5620    ///Wrapper for [`i64::checked_shr`].
5621    #[inline]
5622    fn cshr(self, other: u32) -> Result<i64, Error> {
5623        self.checked_shr(other).ok_or_else(|| {
5624            Error::new(format!(
5625                "failed to compute {:?} >> {:?}: shift amount is too large",
5626                MaybeParens(self),
5627                MaybeParens(other)
5628            ))
5629        })
5630    }
5631    #[inline]
5632    ///Checked shift right assigement: executes `self >>= other`, returning an error if `other` is greater or equal to the number of bits in the type.
5633    ///
5634    ///Wrapper for [`i64::checked_shr`].
5635    fn cshr_assign(&mut self, other: u32) -> Result<(), Self::Error> {
5636        *self = self.cshr(other)?;
5637        Ok(())
5638    }
5639}
5640impl Cshr for i128 {
5641    type Other = u32;
5642    type Output = i128;
5643    type Error = Error;
5644    ///Checked shift right: computes `a >> b`, returning an error if `b` is greater or equal to the number of bits in the type.
5645    ///
5646    ///Wrapper for [`i128::checked_shr`].
5647    #[inline]
5648    fn cshr(self, other: u32) -> Result<i128, Error> {
5649        self.checked_shr(other).ok_or_else(|| {
5650            Error::new(format!(
5651                "failed to compute {:?} >> {:?}: shift amount is too large",
5652                MaybeParens(self),
5653                MaybeParens(other)
5654            ))
5655        })
5656    }
5657    #[inline]
5658    ///Checked shift right assigement: executes `self >>= other`, returning an error if `other` is greater or equal to the number of bits in the type.
5659    ///
5660    ///Wrapper for [`i128::checked_shr`].
5661    fn cshr_assign(&mut self, other: u32) -> Result<(), Self::Error> {
5662        *self = self.cshr(other)?;
5663        Ok(())
5664    }
5665}
5666impl Cshr for isize {
5667    type Other = u32;
5668    type Output = isize;
5669    type Error = Error;
5670    ///Checked shift right: computes `a >> b`, returning an error if `b` is greater or equal to the number of bits in the type.
5671    ///
5672    ///Wrapper for [`isize::checked_shr`].
5673    #[inline]
5674    fn cshr(self, other: u32) -> Result<isize, Error> {
5675        self.checked_shr(other).ok_or_else(|| {
5676            Error::new(format!(
5677                "failed to compute {:?} >> {:?}: shift amount is too large",
5678                MaybeParens(self),
5679                MaybeParens(other)
5680            ))
5681        })
5682    }
5683    #[inline]
5684    ///Checked shift right assigement: executes `self >>= other`, returning an error if `other` is greater or equal to the number of bits in the type.
5685    ///
5686    ///Wrapper for [`isize::checked_shr`].
5687    fn cshr_assign(&mut self, other: u32) -> Result<(), Self::Error> {
5688        *self = self.cshr(other)?;
5689        Ok(())
5690    }
5691}
5692impl Cshr for u8 {
5693    type Other = u32;
5694    type Output = u8;
5695    type Error = Error;
5696    ///Checked shift right: computes `a >> b`, returning an error if `b` is greater or equal to the number of bits in the type.
5697    ///
5698    ///Wrapper for [`u8::checked_shr`].
5699    #[inline]
5700    fn cshr(self, other: u32) -> Result<u8, Error> {
5701        self.checked_shr(other).ok_or_else(|| {
5702            Error::new(format!(
5703                "failed to compute {:?} >> {:?}: shift amount is too large",
5704                MaybeParens(self),
5705                MaybeParens(other)
5706            ))
5707        })
5708    }
5709    #[inline]
5710    ///Checked shift right assigement: executes `self >>= other`, returning an error if `other` is greater or equal to the number of bits in the type.
5711    ///
5712    ///Wrapper for [`u8::checked_shr`].
5713    fn cshr_assign(&mut self, other: u32) -> Result<(), Self::Error> {
5714        *self = self.cshr(other)?;
5715        Ok(())
5716    }
5717}
5718impl Cshr for u16 {
5719    type Other = u32;
5720    type Output = u16;
5721    type Error = Error;
5722    ///Checked shift right: computes `a >> b`, returning an error if `b` is greater or equal to the number of bits in the type.
5723    ///
5724    ///Wrapper for [`u16::checked_shr`].
5725    #[inline]
5726    fn cshr(self, other: u32) -> Result<u16, Error> {
5727        self.checked_shr(other).ok_or_else(|| {
5728            Error::new(format!(
5729                "failed to compute {:?} >> {:?}: shift amount is too large",
5730                MaybeParens(self),
5731                MaybeParens(other)
5732            ))
5733        })
5734    }
5735    #[inline]
5736    ///Checked shift right assigement: executes `self >>= other`, returning an error if `other` is greater or equal to the number of bits in the type.
5737    ///
5738    ///Wrapper for [`u16::checked_shr`].
5739    fn cshr_assign(&mut self, other: u32) -> Result<(), Self::Error> {
5740        *self = self.cshr(other)?;
5741        Ok(())
5742    }
5743}
5744impl Cshr for u32 {
5745    type Other = u32;
5746    type Output = u32;
5747    type Error = Error;
5748    ///Checked shift right: computes `a >> b`, returning an error if `b` is greater or equal to the number of bits in the type.
5749    ///
5750    ///Wrapper for [`u32::checked_shr`].
5751    #[inline]
5752    fn cshr(self, other: u32) -> Result<u32, Error> {
5753        self.checked_shr(other).ok_or_else(|| {
5754            Error::new(format!(
5755                "failed to compute {:?} >> {:?}: shift amount is too large",
5756                MaybeParens(self),
5757                MaybeParens(other)
5758            ))
5759        })
5760    }
5761    #[inline]
5762    ///Checked shift right assigement: executes `self >>= other`, returning an error if `other` is greater or equal to the number of bits in the type.
5763    ///
5764    ///Wrapper for [`u32::checked_shr`].
5765    fn cshr_assign(&mut self, other: u32) -> Result<(), Self::Error> {
5766        *self = self.cshr(other)?;
5767        Ok(())
5768    }
5769}
5770impl Cshr for u64 {
5771    type Other = u32;
5772    type Output = u64;
5773    type Error = Error;
5774    ///Checked shift right: computes `a >> b`, returning an error if `b` is greater or equal to the number of bits in the type.
5775    ///
5776    ///Wrapper for [`u64::checked_shr`].
5777    #[inline]
5778    fn cshr(self, other: u32) -> Result<u64, Error> {
5779        self.checked_shr(other).ok_or_else(|| {
5780            Error::new(format!(
5781                "failed to compute {:?} >> {:?}: shift amount is too large",
5782                MaybeParens(self),
5783                MaybeParens(other)
5784            ))
5785        })
5786    }
5787    #[inline]
5788    ///Checked shift right assigement: executes `self >>= other`, returning an error if `other` is greater or equal to the number of bits in the type.
5789    ///
5790    ///Wrapper for [`u64::checked_shr`].
5791    fn cshr_assign(&mut self, other: u32) -> Result<(), Self::Error> {
5792        *self = self.cshr(other)?;
5793        Ok(())
5794    }
5795}
5796impl Cshr for u128 {
5797    type Other = u32;
5798    type Output = u128;
5799    type Error = Error;
5800    ///Checked shift right: computes `a >> b`, returning an error if `b` is greater or equal to the number of bits in the type.
5801    ///
5802    ///Wrapper for [`u128::checked_shr`].
5803    #[inline]
5804    fn cshr(self, other: u32) -> Result<u128, Error> {
5805        self.checked_shr(other).ok_or_else(|| {
5806            Error::new(format!(
5807                "failed to compute {:?} >> {:?}: shift amount is too large",
5808                MaybeParens(self),
5809                MaybeParens(other)
5810            ))
5811        })
5812    }
5813    #[inline]
5814    ///Checked shift right assigement: executes `self >>= other`, returning an error if `other` is greater or equal to the number of bits in the type.
5815    ///
5816    ///Wrapper for [`u128::checked_shr`].
5817    fn cshr_assign(&mut self, other: u32) -> Result<(), Self::Error> {
5818        *self = self.cshr(other)?;
5819        Ok(())
5820    }
5821}
5822impl Cshr for usize {
5823    type Other = u32;
5824    type Output = usize;
5825    type Error = Error;
5826    ///Checked shift right: computes `a >> b`, returning an error if `b` is greater or equal to the number of bits in the type.
5827    ///
5828    ///Wrapper for [`usize::checked_shr`].
5829    #[inline]
5830    fn cshr(self, other: u32) -> Result<usize, Error> {
5831        self.checked_shr(other).ok_or_else(|| {
5832            Error::new(format!(
5833                "failed to compute {:?} >> {:?}: shift amount is too large",
5834                MaybeParens(self),
5835                MaybeParens(other)
5836            ))
5837        })
5838    }
5839    #[inline]
5840    ///Checked shift right assigement: executes `self >>= other`, returning an error if `other` is greater or equal to the number of bits in the type.
5841    ///
5842    ///Wrapper for [`usize::checked_shr`].
5843    fn cshr_assign(&mut self, other: u32) -> Result<(), Self::Error> {
5844        *self = self.cshr(other)?;
5845        Ok(())
5846    }
5847}
5848///Checked exponentiation: computes <code>value<sup>power</sup></code>, returning an error if overflow occured.
5849///
5850///See also: [module documentation](self).
5851pub trait Cpow: Sized {
5852    #[expect(missing_docs, reason = "no need for doc")]
5853    type Power;
5854    #[expect(missing_docs, reason = "no need for doc")]
5855    type Output;
5856    #[expect(missing_docs, reason = "no need for doc")]
5857    type Error;
5858    ///Checked exponentiation: computes <code>value<sup>power</sup></code>, returning an error if overflow occured.
5859    ///
5860    ///Wrapper for `checked_pow`.
5861    fn cpow(self, power: Self::Power) -> Result<Self::Output, Self::Error>;
5862}
5863///Checked exponentiation: computes <code>value<sup>power</sup></code>, returning an error if overflow occured.
5864///
5865///Wrapper for `checked_pow`.
5866///
5867///See also: [module documentation](self).
5868#[doc(alias = "checked_pow")]
5869#[inline]
5870pub fn cpow<T>(value: T, power: T::Power) -> Result<T::Output, T::Error>
5871where
5872    T: Cpow,
5873{
5874    value.cpow(power)
5875}
5876impl Cpow for NonZero<u8> {
5877    type Power = u32;
5878    type Output = NonZero<u8>;
5879    type Error = Error;
5880    ///Checked exponentiation: computes <code>value<sup>power</sup></code>, returning an error if overflow occured.
5881    ///
5882    ///Wrapper for [`NonZero<u8>::checked_pow`].
5883    #[inline]
5884    fn cpow(self, power: u32) -> Result<NonZero<u8>, Error> {
5885        self.checked_pow(power).ok_or_else(|| {
5886            Error::new(format!(
5887                "failed to compute pow({:?}, {:?}): {} overflow",
5888                self, power, "NonZero<u8>"
5889            ))
5890        })
5891    }
5892}
5893impl Cpow for NonZero<u16> {
5894    type Power = u32;
5895    type Output = NonZero<u16>;
5896    type Error = Error;
5897    ///Checked exponentiation: computes <code>value<sup>power</sup></code>, returning an error if overflow occured.
5898    ///
5899    ///Wrapper for [`NonZero<u16>::checked_pow`].
5900    #[inline]
5901    fn cpow(self, power: u32) -> Result<NonZero<u16>, Error> {
5902        self.checked_pow(power).ok_or_else(|| {
5903            Error::new(format!(
5904                "failed to compute pow({:?}, {:?}): {} overflow",
5905                self, power, "NonZero<u16>"
5906            ))
5907        })
5908    }
5909}
5910impl Cpow for NonZero<u32> {
5911    type Power = u32;
5912    type Output = NonZero<u32>;
5913    type Error = Error;
5914    ///Checked exponentiation: computes <code>value<sup>power</sup></code>, returning an error if overflow occured.
5915    ///
5916    ///Wrapper for [`NonZero<u32>::checked_pow`].
5917    #[inline]
5918    fn cpow(self, power: u32) -> Result<NonZero<u32>, Error> {
5919        self.checked_pow(power).ok_or_else(|| {
5920            Error::new(format!(
5921                "failed to compute pow({:?}, {:?}): {} overflow",
5922                self, power, "NonZero<u32>"
5923            ))
5924        })
5925    }
5926}
5927impl Cpow for NonZero<u64> {
5928    type Power = u32;
5929    type Output = NonZero<u64>;
5930    type Error = Error;
5931    ///Checked exponentiation: computes <code>value<sup>power</sup></code>, returning an error if overflow occured.
5932    ///
5933    ///Wrapper for [`NonZero<u64>::checked_pow`].
5934    #[inline]
5935    fn cpow(self, power: u32) -> Result<NonZero<u64>, Error> {
5936        self.checked_pow(power).ok_or_else(|| {
5937            Error::new(format!(
5938                "failed to compute pow({:?}, {:?}): {} overflow",
5939                self, power, "NonZero<u64>"
5940            ))
5941        })
5942    }
5943}
5944impl Cpow for NonZero<u128> {
5945    type Power = u32;
5946    type Output = NonZero<u128>;
5947    type Error = Error;
5948    ///Checked exponentiation: computes <code>value<sup>power</sup></code>, returning an error if overflow occured.
5949    ///
5950    ///Wrapper for [`NonZero<u128>::checked_pow`].
5951    #[inline]
5952    fn cpow(self, power: u32) -> Result<NonZero<u128>, Error> {
5953        self.checked_pow(power).ok_or_else(|| {
5954            Error::new(format!(
5955                "failed to compute pow({:?}, {:?}): {} overflow",
5956                self, power, "NonZero<u128>"
5957            ))
5958        })
5959    }
5960}
5961impl Cpow for NonZero<usize> {
5962    type Power = u32;
5963    type Output = NonZero<usize>;
5964    type Error = Error;
5965    ///Checked exponentiation: computes <code>value<sup>power</sup></code>, returning an error if overflow occured.
5966    ///
5967    ///Wrapper for [`NonZero<usize>::checked_pow`].
5968    #[inline]
5969    fn cpow(self, power: u32) -> Result<NonZero<usize>, Error> {
5970        self.checked_pow(power).ok_or_else(|| {
5971            Error::new(format!(
5972                "failed to compute pow({:?}, {:?}): {} overflow",
5973                self, power, "NonZero<usize>"
5974            ))
5975        })
5976    }
5977}
5978impl Cpow for NonZero<i8> {
5979    type Power = u32;
5980    type Output = NonZero<i8>;
5981    type Error = Error;
5982    ///Checked exponentiation: computes <code>value<sup>power</sup></code>, returning an error if overflow occured.
5983    ///
5984    ///Wrapper for [`NonZero<i8>::checked_pow`].
5985    #[inline]
5986    fn cpow(self, power: u32) -> Result<NonZero<i8>, Error> {
5987        self.checked_pow(power).ok_or_else(|| {
5988            Error::new(format!(
5989                "failed to compute pow({:?}, {:?}): {} overflow",
5990                self, power, "NonZero<i8>"
5991            ))
5992        })
5993    }
5994}
5995impl Cpow for NonZero<i16> {
5996    type Power = u32;
5997    type Output = NonZero<i16>;
5998    type Error = Error;
5999    ///Checked exponentiation: computes <code>value<sup>power</sup></code>, returning an error if overflow occured.
6000    ///
6001    ///Wrapper for [`NonZero<i16>::checked_pow`].
6002    #[inline]
6003    fn cpow(self, power: u32) -> Result<NonZero<i16>, Error> {
6004        self.checked_pow(power).ok_or_else(|| {
6005            Error::new(format!(
6006                "failed to compute pow({:?}, {:?}): {} overflow",
6007                self, power, "NonZero<i16>"
6008            ))
6009        })
6010    }
6011}
6012impl Cpow for NonZero<i32> {
6013    type Power = u32;
6014    type Output = NonZero<i32>;
6015    type Error = Error;
6016    ///Checked exponentiation: computes <code>value<sup>power</sup></code>, returning an error if overflow occured.
6017    ///
6018    ///Wrapper for [`NonZero<i32>::checked_pow`].
6019    #[inline]
6020    fn cpow(self, power: u32) -> Result<NonZero<i32>, Error> {
6021        self.checked_pow(power).ok_or_else(|| {
6022            Error::new(format!(
6023                "failed to compute pow({:?}, {:?}): {} overflow",
6024                self, power, "NonZero<i32>"
6025            ))
6026        })
6027    }
6028}
6029impl Cpow for NonZero<i64> {
6030    type Power = u32;
6031    type Output = NonZero<i64>;
6032    type Error = Error;
6033    ///Checked exponentiation: computes <code>value<sup>power</sup></code>, returning an error if overflow occured.
6034    ///
6035    ///Wrapper for [`NonZero<i64>::checked_pow`].
6036    #[inline]
6037    fn cpow(self, power: u32) -> Result<NonZero<i64>, Error> {
6038        self.checked_pow(power).ok_or_else(|| {
6039            Error::new(format!(
6040                "failed to compute pow({:?}, {:?}): {} overflow",
6041                self, power, "NonZero<i64>"
6042            ))
6043        })
6044    }
6045}
6046impl Cpow for NonZero<i128> {
6047    type Power = u32;
6048    type Output = NonZero<i128>;
6049    type Error = Error;
6050    ///Checked exponentiation: computes <code>value<sup>power</sup></code>, returning an error if overflow occured.
6051    ///
6052    ///Wrapper for [`NonZero<i128>::checked_pow`].
6053    #[inline]
6054    fn cpow(self, power: u32) -> Result<NonZero<i128>, Error> {
6055        self.checked_pow(power).ok_or_else(|| {
6056            Error::new(format!(
6057                "failed to compute pow({:?}, {:?}): {} overflow",
6058                self, power, "NonZero<i128>"
6059            ))
6060        })
6061    }
6062}
6063impl Cpow for NonZero<isize> {
6064    type Power = u32;
6065    type Output = NonZero<isize>;
6066    type Error = Error;
6067    ///Checked exponentiation: computes <code>value<sup>power</sup></code>, returning an error if overflow occured.
6068    ///
6069    ///Wrapper for [`NonZero<isize>::checked_pow`].
6070    #[inline]
6071    fn cpow(self, power: u32) -> Result<NonZero<isize>, Error> {
6072        self.checked_pow(power).ok_or_else(|| {
6073            Error::new(format!(
6074                "failed to compute pow({:?}, {:?}): {} overflow",
6075                self, power, "NonZero<isize>"
6076            ))
6077        })
6078    }
6079}
6080impl Cpow for i8 {
6081    type Power = u32;
6082    type Output = i8;
6083    type Error = Error;
6084    ///Checked exponentiation: computes <code>value<sup>power</sup></code>, returning an error if overflow occured.
6085    ///
6086    ///Wrapper for [`i8::checked_pow`].
6087    #[inline]
6088    fn cpow(self, power: u32) -> Result<i8, Error> {
6089        self.checked_pow(power).ok_or_else(|| {
6090            Error::new(format!(
6091                "failed to compute pow({:?}, {:?}): {} overflow",
6092                self, power, "i8"
6093            ))
6094        })
6095    }
6096}
6097impl Cpow for i16 {
6098    type Power = u32;
6099    type Output = i16;
6100    type Error = Error;
6101    ///Checked exponentiation: computes <code>value<sup>power</sup></code>, returning an error if overflow occured.
6102    ///
6103    ///Wrapper for [`i16::checked_pow`].
6104    #[inline]
6105    fn cpow(self, power: u32) -> Result<i16, Error> {
6106        self.checked_pow(power).ok_or_else(|| {
6107            Error::new(format!(
6108                "failed to compute pow({:?}, {:?}): {} overflow",
6109                self, power, "i16"
6110            ))
6111        })
6112    }
6113}
6114impl Cpow for i32 {
6115    type Power = u32;
6116    type Output = i32;
6117    type Error = Error;
6118    ///Checked exponentiation: computes <code>value<sup>power</sup></code>, returning an error if overflow occured.
6119    ///
6120    ///Wrapper for [`i32::checked_pow`].
6121    #[inline]
6122    fn cpow(self, power: u32) -> Result<i32, Error> {
6123        self.checked_pow(power).ok_or_else(|| {
6124            Error::new(format!(
6125                "failed to compute pow({:?}, {:?}): {} overflow",
6126                self, power, "i32"
6127            ))
6128        })
6129    }
6130}
6131impl Cpow for i64 {
6132    type Power = u32;
6133    type Output = i64;
6134    type Error = Error;
6135    ///Checked exponentiation: computes <code>value<sup>power</sup></code>, returning an error if overflow occured.
6136    ///
6137    ///Wrapper for [`i64::checked_pow`].
6138    #[inline]
6139    fn cpow(self, power: u32) -> Result<i64, Error> {
6140        self.checked_pow(power).ok_or_else(|| {
6141            Error::new(format!(
6142                "failed to compute pow({:?}, {:?}): {} overflow",
6143                self, power, "i64"
6144            ))
6145        })
6146    }
6147}
6148impl Cpow for i128 {
6149    type Power = u32;
6150    type Output = i128;
6151    type Error = Error;
6152    ///Checked exponentiation: computes <code>value<sup>power</sup></code>, returning an error if overflow occured.
6153    ///
6154    ///Wrapper for [`i128::checked_pow`].
6155    #[inline]
6156    fn cpow(self, power: u32) -> Result<i128, Error> {
6157        self.checked_pow(power).ok_or_else(|| {
6158            Error::new(format!(
6159                "failed to compute pow({:?}, {:?}): {} overflow",
6160                self, power, "i128"
6161            ))
6162        })
6163    }
6164}
6165impl Cpow for isize {
6166    type Power = u32;
6167    type Output = isize;
6168    type Error = Error;
6169    ///Checked exponentiation: computes <code>value<sup>power</sup></code>, returning an error if overflow occured.
6170    ///
6171    ///Wrapper for [`isize::checked_pow`].
6172    #[inline]
6173    fn cpow(self, power: u32) -> Result<isize, Error> {
6174        self.checked_pow(power).ok_or_else(|| {
6175            Error::new(format!(
6176                "failed to compute pow({:?}, {:?}): {} overflow",
6177                self, power, "isize"
6178            ))
6179        })
6180    }
6181}
6182impl Cpow for u8 {
6183    type Power = u32;
6184    type Output = u8;
6185    type Error = Error;
6186    ///Checked exponentiation: computes <code>value<sup>power</sup></code>, returning an error if overflow occured.
6187    ///
6188    ///Wrapper for [`u8::checked_pow`].
6189    #[inline]
6190    fn cpow(self, power: u32) -> Result<u8, Error> {
6191        self.checked_pow(power).ok_or_else(|| {
6192            Error::new(format!(
6193                "failed to compute pow({:?}, {:?}): {} overflow",
6194                self, power, "u8"
6195            ))
6196        })
6197    }
6198}
6199impl Cpow for u16 {
6200    type Power = u32;
6201    type Output = u16;
6202    type Error = Error;
6203    ///Checked exponentiation: computes <code>value<sup>power</sup></code>, returning an error if overflow occured.
6204    ///
6205    ///Wrapper for [`u16::checked_pow`].
6206    #[inline]
6207    fn cpow(self, power: u32) -> Result<u16, Error> {
6208        self.checked_pow(power).ok_or_else(|| {
6209            Error::new(format!(
6210                "failed to compute pow({:?}, {:?}): {} overflow",
6211                self, power, "u16"
6212            ))
6213        })
6214    }
6215}
6216impl Cpow for u32 {
6217    type Power = u32;
6218    type Output = u32;
6219    type Error = Error;
6220    ///Checked exponentiation: computes <code>value<sup>power</sup></code>, returning an error if overflow occured.
6221    ///
6222    ///Wrapper for [`u32::checked_pow`].
6223    #[inline]
6224    fn cpow(self, power: u32) -> Result<u32, Error> {
6225        self.checked_pow(power).ok_or_else(|| {
6226            Error::new(format!(
6227                "failed to compute pow({:?}, {:?}): {} overflow",
6228                self, power, "u32"
6229            ))
6230        })
6231    }
6232}
6233impl Cpow for u64 {
6234    type Power = u32;
6235    type Output = u64;
6236    type Error = Error;
6237    ///Checked exponentiation: computes <code>value<sup>power</sup></code>, returning an error if overflow occured.
6238    ///
6239    ///Wrapper for [`u64::checked_pow`].
6240    #[inline]
6241    fn cpow(self, power: u32) -> Result<u64, Error> {
6242        self.checked_pow(power).ok_or_else(|| {
6243            Error::new(format!(
6244                "failed to compute pow({:?}, {:?}): {} overflow",
6245                self, power, "u64"
6246            ))
6247        })
6248    }
6249}
6250impl Cpow for u128 {
6251    type Power = u32;
6252    type Output = u128;
6253    type Error = Error;
6254    ///Checked exponentiation: computes <code>value<sup>power</sup></code>, returning an error if overflow occured.
6255    ///
6256    ///Wrapper for [`u128::checked_pow`].
6257    #[inline]
6258    fn cpow(self, power: u32) -> Result<u128, Error> {
6259        self.checked_pow(power).ok_or_else(|| {
6260            Error::new(format!(
6261                "failed to compute pow({:?}, {:?}): {} overflow",
6262                self, power, "u128"
6263            ))
6264        })
6265    }
6266}
6267impl Cpow for usize {
6268    type Power = u32;
6269    type Output = usize;
6270    type Error = Error;
6271    ///Checked exponentiation: computes <code>value<sup>power</sup></code>, returning an error if overflow occured.
6272    ///
6273    ///Wrapper for [`usize::checked_pow`].
6274    #[inline]
6275    fn cpow(self, power: u32) -> Result<usize, Error> {
6276        self.checked_pow(power).ok_or_else(|| {
6277            Error::new(format!(
6278                "failed to compute pow({:?}, {:?}): {} overflow",
6279                self, power, "usize"
6280            ))
6281        })
6282    }
6283}
6284///Checked absolute value: computes `|value|`, returning an error if overflow occured.
6285///
6286///See also: [module documentation](self).
6287pub trait Cabs: Sized {
6288    #[expect(missing_docs, reason = "no need for doc")]
6289    type Output;
6290    #[expect(missing_docs, reason = "no need for doc")]
6291    type Error;
6292    ///Checked absolute value: computes `|value|`, returning an error if overflow occured.
6293    ///
6294    ///Wrapper for `checked_abs`.
6295    fn cabs(self) -> Result<Self::Output, Self::Error>;
6296}
6297///Checked absolute value: computes `|value|`, returning an error if overflow occured.
6298///
6299///Wrapper for `checked_abs`.
6300#[doc(alias = "checked_abs")]
6301#[inline]
6302pub fn cabs<T>(value: T) -> Result<T::Output, T::Error>
6303where
6304    T: Cabs,
6305{
6306    Cabs::cabs(value)
6307}
6308impl Cabs for NonZero<i8> {
6309    type Output = NonZero<i8>;
6310    type Error = Error;
6311    ///Checked absolute value: computes `|value|`, returning an error if overflow occured.
6312    ///
6313    ///Wrapper for [`NonZero<i8>::checked_abs`].
6314    #[inline]
6315    fn cabs(self) -> Result<NonZero<i8>, Error> {
6316        self.checked_abs().ok_or_else(|| {
6317            Error::new(format!(
6318                "failed to compute abs({:?}): {} overflow",
6319                self, "NonZero<i8>"
6320            ))
6321        })
6322    }
6323}
6324impl Cabs for NonZero<i16> {
6325    type Output = NonZero<i16>;
6326    type Error = Error;
6327    ///Checked absolute value: computes `|value|`, returning an error if overflow occured.
6328    ///
6329    ///Wrapper for [`NonZero<i16>::checked_abs`].
6330    #[inline]
6331    fn cabs(self) -> Result<NonZero<i16>, Error> {
6332        self.checked_abs().ok_or_else(|| {
6333            Error::new(format!(
6334                "failed to compute abs({:?}): {} overflow",
6335                self, "NonZero<i16>"
6336            ))
6337        })
6338    }
6339}
6340impl Cabs for NonZero<i32> {
6341    type Output = NonZero<i32>;
6342    type Error = Error;
6343    ///Checked absolute value: computes `|value|`, returning an error if overflow occured.
6344    ///
6345    ///Wrapper for [`NonZero<i32>::checked_abs`].
6346    #[inline]
6347    fn cabs(self) -> Result<NonZero<i32>, Error> {
6348        self.checked_abs().ok_or_else(|| {
6349            Error::new(format!(
6350                "failed to compute abs({:?}): {} overflow",
6351                self, "NonZero<i32>"
6352            ))
6353        })
6354    }
6355}
6356impl Cabs for NonZero<i64> {
6357    type Output = NonZero<i64>;
6358    type Error = Error;
6359    ///Checked absolute value: computes `|value|`, returning an error if overflow occured.
6360    ///
6361    ///Wrapper for [`NonZero<i64>::checked_abs`].
6362    #[inline]
6363    fn cabs(self) -> Result<NonZero<i64>, Error> {
6364        self.checked_abs().ok_or_else(|| {
6365            Error::new(format!(
6366                "failed to compute abs({:?}): {} overflow",
6367                self, "NonZero<i64>"
6368            ))
6369        })
6370    }
6371}
6372impl Cabs for NonZero<i128> {
6373    type Output = NonZero<i128>;
6374    type Error = Error;
6375    ///Checked absolute value: computes `|value|`, returning an error if overflow occured.
6376    ///
6377    ///Wrapper for [`NonZero<i128>::checked_abs`].
6378    #[inline]
6379    fn cabs(self) -> Result<NonZero<i128>, Error> {
6380        self.checked_abs().ok_or_else(|| {
6381            Error::new(format!(
6382                "failed to compute abs({:?}): {} overflow",
6383                self, "NonZero<i128>"
6384            ))
6385        })
6386    }
6387}
6388impl Cabs for NonZero<isize> {
6389    type Output = NonZero<isize>;
6390    type Error = Error;
6391    ///Checked absolute value: computes `|value|`, returning an error if overflow occured.
6392    ///
6393    ///Wrapper for [`NonZero<isize>::checked_abs`].
6394    #[inline]
6395    fn cabs(self) -> Result<NonZero<isize>, Error> {
6396        self.checked_abs().ok_or_else(|| {
6397            Error::new(format!(
6398                "failed to compute abs({:?}): {} overflow",
6399                self, "NonZero<isize>"
6400            ))
6401        })
6402    }
6403}
6404impl Cabs for i8 {
6405    type Output = i8;
6406    type Error = Error;
6407    ///Checked absolute value: computes `|value|`, returning an error if overflow occured.
6408    ///
6409    ///Wrapper for [`i8::checked_abs`].
6410    #[inline]
6411    fn cabs(self) -> Result<i8, Error> {
6412        self.checked_abs().ok_or_else(|| {
6413            Error::new(format!(
6414                "failed to compute abs({:?}): {} overflow",
6415                self, "i8"
6416            ))
6417        })
6418    }
6419}
6420impl Cabs for i16 {
6421    type Output = i16;
6422    type Error = Error;
6423    ///Checked absolute value: computes `|value|`, returning an error if overflow occured.
6424    ///
6425    ///Wrapper for [`i16::checked_abs`].
6426    #[inline]
6427    fn cabs(self) -> Result<i16, Error> {
6428        self.checked_abs().ok_or_else(|| {
6429            Error::new(format!(
6430                "failed to compute abs({:?}): {} overflow",
6431                self, "i16"
6432            ))
6433        })
6434    }
6435}
6436impl Cabs for i32 {
6437    type Output = i32;
6438    type Error = Error;
6439    ///Checked absolute value: computes `|value|`, returning an error if overflow occured.
6440    ///
6441    ///Wrapper for [`i32::checked_abs`].
6442    #[inline]
6443    fn cabs(self) -> Result<i32, Error> {
6444        self.checked_abs().ok_or_else(|| {
6445            Error::new(format!(
6446                "failed to compute abs({:?}): {} overflow",
6447                self, "i32"
6448            ))
6449        })
6450    }
6451}
6452impl Cabs for i64 {
6453    type Output = i64;
6454    type Error = Error;
6455    ///Checked absolute value: computes `|value|`, returning an error if overflow occured.
6456    ///
6457    ///Wrapper for [`i64::checked_abs`].
6458    #[inline]
6459    fn cabs(self) -> Result<i64, Error> {
6460        self.checked_abs().ok_or_else(|| {
6461            Error::new(format!(
6462                "failed to compute abs({:?}): {} overflow",
6463                self, "i64"
6464            ))
6465        })
6466    }
6467}
6468impl Cabs for i128 {
6469    type Output = i128;
6470    type Error = Error;
6471    ///Checked absolute value: computes `|value|`, returning an error if overflow occured.
6472    ///
6473    ///Wrapper for [`i128::checked_abs`].
6474    #[inline]
6475    fn cabs(self) -> Result<i128, Error> {
6476        self.checked_abs().ok_or_else(|| {
6477            Error::new(format!(
6478                "failed to compute abs({:?}): {} overflow",
6479                self, "i128"
6480            ))
6481        })
6482    }
6483}
6484impl Cabs for isize {
6485    type Output = isize;
6486    type Error = Error;
6487    ///Checked absolute value: computes `|value|`, returning an error if overflow occured.
6488    ///
6489    ///Wrapper for [`isize::checked_abs`].
6490    #[inline]
6491    fn cabs(self) -> Result<isize, Error> {
6492        self.checked_abs().ok_or_else(|| {
6493            Error::new(format!(
6494                "failed to compute abs({:?}): {} overflow",
6495                self, "isize"
6496            ))
6497        })
6498    }
6499}
6500///Checked square root: computes `√value`, returning an error if `value` is negative.
6501///
6502///See also: [module documentation](self).
6503pub trait Cisqrt: Sized {
6504    #[expect(missing_docs, reason = "no need for doc")]
6505    type Output;
6506    #[expect(missing_docs, reason = "no need for doc")]
6507    type Error;
6508    ///Checked square root: computes `√value`, returning an error if `value` is negative.
6509    ///
6510    ///Wrapper for `checked_isqrt`.
6511    fn cisqrt(self) -> Result<Self::Output, Self::Error>;
6512}
6513///Checked square root: computes `√value`, returning an error if `value` is negative.
6514///
6515///Wrapper for `checked_isqrt`.
6516#[doc(alias = "checked_isqrt")]
6517#[inline]
6518pub fn cisqrt<T>(value: T) -> Result<T::Output, T::Error>
6519where
6520    T: Cisqrt,
6521{
6522    Cisqrt::cisqrt(value)
6523}
6524impl Cisqrt for i8 {
6525    type Output = i8;
6526    type Error = Error;
6527    ///Checked square root: computes `√value`, returning an error if `value` is negative.
6528    ///
6529    ///Wrapper for [`i8::checked_isqrt`].
6530    #[inline]
6531    fn cisqrt(self) -> Result<i8, Error> {
6532        self.checked_isqrt().ok_or_else(|| {
6533            Error::new(format!(
6534                "failed to compute isqrt({:?}): argument is negative",
6535                self
6536            ))
6537        })
6538    }
6539}
6540impl Cisqrt for i16 {
6541    type Output = i16;
6542    type Error = Error;
6543    ///Checked square root: computes `√value`, returning an error if `value` is negative.
6544    ///
6545    ///Wrapper for [`i16::checked_isqrt`].
6546    #[inline]
6547    fn cisqrt(self) -> Result<i16, Error> {
6548        self.checked_isqrt().ok_or_else(|| {
6549            Error::new(format!(
6550                "failed to compute isqrt({:?}): argument is negative",
6551                self
6552            ))
6553        })
6554    }
6555}
6556impl Cisqrt for i32 {
6557    type Output = i32;
6558    type Error = Error;
6559    ///Checked square root: computes `√value`, returning an error if `value` is negative.
6560    ///
6561    ///Wrapper for [`i32::checked_isqrt`].
6562    #[inline]
6563    fn cisqrt(self) -> Result<i32, Error> {
6564        self.checked_isqrt().ok_or_else(|| {
6565            Error::new(format!(
6566                "failed to compute isqrt({:?}): argument is negative",
6567                self
6568            ))
6569        })
6570    }
6571}
6572impl Cisqrt for i64 {
6573    type Output = i64;
6574    type Error = Error;
6575    ///Checked square root: computes `√value`, returning an error if `value` is negative.
6576    ///
6577    ///Wrapper for [`i64::checked_isqrt`].
6578    #[inline]
6579    fn cisqrt(self) -> Result<i64, Error> {
6580        self.checked_isqrt().ok_or_else(|| {
6581            Error::new(format!(
6582                "failed to compute isqrt({:?}): argument is negative",
6583                self
6584            ))
6585        })
6586    }
6587}
6588impl Cisqrt for i128 {
6589    type Output = i128;
6590    type Error = Error;
6591    ///Checked square root: computes `√value`, returning an error if `value` is negative.
6592    ///
6593    ///Wrapper for [`i128::checked_isqrt`].
6594    #[inline]
6595    fn cisqrt(self) -> Result<i128, Error> {
6596        self.checked_isqrt().ok_or_else(|| {
6597            Error::new(format!(
6598                "failed to compute isqrt({:?}): argument is negative",
6599                self
6600            ))
6601        })
6602    }
6603}
6604impl Cisqrt for isize {
6605    type Output = isize;
6606    type Error = Error;
6607    ///Checked square root: computes `√value`, returning an error if `value` is negative.
6608    ///
6609    ///Wrapper for [`isize::checked_isqrt`].
6610    #[inline]
6611    fn cisqrt(self) -> Result<isize, Error> {
6612        self.checked_isqrt().ok_or_else(|| {
6613            Error::new(format!(
6614                "failed to compute isqrt({:?}): argument is negative",
6615                self
6616            ))
6617        })
6618    }
6619}
6620///Checked next multiple of `b`, returning an error if overflow occured or if `b` is zero.
6621///
6622///See also: [module documentation](self).
6623pub trait CnextMultipleOf: Sized {
6624    #[expect(missing_docs, reason = "no need for doc")]
6625    type Other;
6626    #[expect(missing_docs, reason = "no need for doc")]
6627    type Output;
6628    #[expect(missing_docs, reason = "no need for doc")]
6629    type Error;
6630    ///Checked next multiple of `b`, returning an error if overflow occured or if `b` is zero.
6631    ///
6632    ///Wrapper for `checked_next_multiple_of`.
6633    fn cnext_multiple_of(self, other: Self::Other) -> Result<Self::Output, Self::Error>;
6634}
6635///Checked next multiple of `b`, returning an error if overflow occured or if `b` is zero.
6636///
6637///Wrapper for `checked_next_multiple_of`.
6638///
6639///See also: [module documentation](self).
6640#[doc(alias = "checked_next_multiple_of")]
6641#[inline]
6642pub fn cnext_multiple_of<T>(a: T, b: T::Other) -> Result<T::Output, T::Error>
6643where
6644    T: CnextMultipleOf,
6645{
6646    a.cnext_multiple_of(b)
6647}
6648impl CnextMultipleOf for u8 {
6649    type Other = u8;
6650    type Output = u8;
6651    type Error = Error;
6652    ///Checked next multiple of `b`, returning an error if overflow occured or if `b` is zero.
6653    ///
6654    ///Wrapper for [`u8::checked_next_multiple_of`].
6655    #[inline]
6656    fn cnext_multiple_of(self, other: u8) -> Result<u8, Error> {
6657        self.checked_next_multiple_of(other).ok_or_else(|| {
6658            Error::new({
6659                if other < 2 {
6660                    format!(
6661                        "failed to compute next_multiple_of({:?}, {:?}): multiplier is zero",
6662                        self, other
6663                    )
6664                } else {
6665                    format!(
6666                        "failed to compute next_multiple_of({:?}, {:?}): {} overflow",
6667                        self, other, "u8"
6668                    )
6669                }
6670            })
6671        })
6672    }
6673}
6674impl CnextMultipleOf for u16 {
6675    type Other = u16;
6676    type Output = u16;
6677    type Error = Error;
6678    ///Checked next multiple of `b`, returning an error if overflow occured or if `b` is zero.
6679    ///
6680    ///Wrapper for [`u16::checked_next_multiple_of`].
6681    #[inline]
6682    fn cnext_multiple_of(self, other: u16) -> Result<u16, Error> {
6683        self.checked_next_multiple_of(other).ok_or_else(|| {
6684            Error::new({
6685                if other < 2 {
6686                    format!(
6687                        "failed to compute next_multiple_of({:?}, {:?}): multiplier is zero",
6688                        self, other
6689                    )
6690                } else {
6691                    format!(
6692                        "failed to compute next_multiple_of({:?}, {:?}): {} overflow",
6693                        self, other, "u16"
6694                    )
6695                }
6696            })
6697        })
6698    }
6699}
6700impl CnextMultipleOf for u32 {
6701    type Other = u32;
6702    type Output = u32;
6703    type Error = Error;
6704    ///Checked next multiple of `b`, returning an error if overflow occured or if `b` is zero.
6705    ///
6706    ///Wrapper for [`u32::checked_next_multiple_of`].
6707    #[inline]
6708    fn cnext_multiple_of(self, other: u32) -> Result<u32, Error> {
6709        self.checked_next_multiple_of(other).ok_or_else(|| {
6710            Error::new({
6711                if other < 2 {
6712                    format!(
6713                        "failed to compute next_multiple_of({:?}, {:?}): multiplier is zero",
6714                        self, other
6715                    )
6716                } else {
6717                    format!(
6718                        "failed to compute next_multiple_of({:?}, {:?}): {} overflow",
6719                        self, other, "u32"
6720                    )
6721                }
6722            })
6723        })
6724    }
6725}
6726impl CnextMultipleOf for u64 {
6727    type Other = u64;
6728    type Output = u64;
6729    type Error = Error;
6730    ///Checked next multiple of `b`, returning an error if overflow occured or if `b` is zero.
6731    ///
6732    ///Wrapper for [`u64::checked_next_multiple_of`].
6733    #[inline]
6734    fn cnext_multiple_of(self, other: u64) -> Result<u64, Error> {
6735        self.checked_next_multiple_of(other).ok_or_else(|| {
6736            Error::new({
6737                if other < 2 {
6738                    format!(
6739                        "failed to compute next_multiple_of({:?}, {:?}): multiplier is zero",
6740                        self, other
6741                    )
6742                } else {
6743                    format!(
6744                        "failed to compute next_multiple_of({:?}, {:?}): {} overflow",
6745                        self, other, "u64"
6746                    )
6747                }
6748            })
6749        })
6750    }
6751}
6752impl CnextMultipleOf for u128 {
6753    type Other = u128;
6754    type Output = u128;
6755    type Error = Error;
6756    ///Checked next multiple of `b`, returning an error if overflow occured or if `b` is zero.
6757    ///
6758    ///Wrapper for [`u128::checked_next_multiple_of`].
6759    #[inline]
6760    fn cnext_multiple_of(self, other: u128) -> Result<u128, Error> {
6761        self.checked_next_multiple_of(other).ok_or_else(|| {
6762            Error::new({
6763                if other < 2 {
6764                    format!(
6765                        "failed to compute next_multiple_of({:?}, {:?}): multiplier is zero",
6766                        self, other
6767                    )
6768                } else {
6769                    format!(
6770                        "failed to compute next_multiple_of({:?}, {:?}): {} overflow",
6771                        self, other, "u128"
6772                    )
6773                }
6774            })
6775        })
6776    }
6777}
6778impl CnextMultipleOf for usize {
6779    type Other = usize;
6780    type Output = usize;
6781    type Error = Error;
6782    ///Checked next multiple of `b`, returning an error if overflow occured or if `b` is zero.
6783    ///
6784    ///Wrapper for [`usize::checked_next_multiple_of`].
6785    #[inline]
6786    fn cnext_multiple_of(self, other: usize) -> Result<usize, Error> {
6787        self.checked_next_multiple_of(other).ok_or_else(|| {
6788            Error::new({
6789                if other < 2 {
6790                    format!(
6791                        "failed to compute next_multiple_of({:?}, {:?}): multiplier is zero",
6792                        self, other
6793                    )
6794                } else {
6795                    format!(
6796                        "failed to compute next_multiple_of({:?}, {:?}): {} overflow",
6797                        self, other, "usize"
6798                    )
6799                }
6800            })
6801        })
6802    }
6803}
6804///Checked next power of 2, returning an error if overflow occured.
6805///
6806///See also: [module documentation](self).
6807pub trait CnextPowerOfTwo: Sized {
6808    #[expect(missing_docs, reason = "no need for doc")]
6809    type Output;
6810    #[expect(missing_docs, reason = "no need for doc")]
6811    type Error;
6812    ///Checked next power of 2, returning an error if overflow occured.
6813    ///
6814    ///Wrapper for `checked_next_power_of_two`.
6815    fn cnext_power_of_two(self) -> Result<Self::Output, Self::Error>;
6816}
6817///Checked next power of 2, returning an error if overflow occured.
6818///
6819///Wrapper for `checked_next_power_of_two`.
6820#[doc(alias = "checked_next_power_of_two")]
6821#[inline]
6822pub fn cnext_power_of_two<T>(value: T) -> Result<T::Output, T::Error>
6823where
6824    T: CnextPowerOfTwo,
6825{
6826    CnextPowerOfTwo::cnext_power_of_two(value)
6827}
6828impl CnextPowerOfTwo for NonZero<u8> {
6829    type Output = NonZero<u8>;
6830    type Error = Error;
6831    ///Checked next power of 2, returning an error if overflow occured.
6832    ///
6833    ///Wrapper for [`NonZero<u8>::checked_next_power_of_two`].
6834    #[inline]
6835    fn cnext_power_of_two(self) -> Result<NonZero<u8>, Error> {
6836        self.checked_next_power_of_two().ok_or_else(|| {
6837            Error::new(format!(
6838                "failed to compute next_power_of_two({:?}): {} overflow",
6839                self, "NonZero<u8>"
6840            ))
6841        })
6842    }
6843}
6844impl CnextPowerOfTwo for NonZero<u16> {
6845    type Output = NonZero<u16>;
6846    type Error = Error;
6847    ///Checked next power of 2, returning an error if overflow occured.
6848    ///
6849    ///Wrapper for [`NonZero<u16>::checked_next_power_of_two`].
6850    #[inline]
6851    fn cnext_power_of_two(self) -> Result<NonZero<u16>, Error> {
6852        self.checked_next_power_of_two().ok_or_else(|| {
6853            Error::new(format!(
6854                "failed to compute next_power_of_two({:?}): {} overflow",
6855                self, "NonZero<u16>"
6856            ))
6857        })
6858    }
6859}
6860impl CnextPowerOfTwo for NonZero<u32> {
6861    type Output = NonZero<u32>;
6862    type Error = Error;
6863    ///Checked next power of 2, returning an error if overflow occured.
6864    ///
6865    ///Wrapper for [`NonZero<u32>::checked_next_power_of_two`].
6866    #[inline]
6867    fn cnext_power_of_two(self) -> Result<NonZero<u32>, Error> {
6868        self.checked_next_power_of_two().ok_or_else(|| {
6869            Error::new(format!(
6870                "failed to compute next_power_of_two({:?}): {} overflow",
6871                self, "NonZero<u32>"
6872            ))
6873        })
6874    }
6875}
6876impl CnextPowerOfTwo for NonZero<u64> {
6877    type Output = NonZero<u64>;
6878    type Error = Error;
6879    ///Checked next power of 2, returning an error if overflow occured.
6880    ///
6881    ///Wrapper for [`NonZero<u64>::checked_next_power_of_two`].
6882    #[inline]
6883    fn cnext_power_of_two(self) -> Result<NonZero<u64>, Error> {
6884        self.checked_next_power_of_two().ok_or_else(|| {
6885            Error::new(format!(
6886                "failed to compute next_power_of_two({:?}): {} overflow",
6887                self, "NonZero<u64>"
6888            ))
6889        })
6890    }
6891}
6892impl CnextPowerOfTwo for NonZero<u128> {
6893    type Output = NonZero<u128>;
6894    type Error = Error;
6895    ///Checked next power of 2, returning an error if overflow occured.
6896    ///
6897    ///Wrapper for [`NonZero<u128>::checked_next_power_of_two`].
6898    #[inline]
6899    fn cnext_power_of_two(self) -> Result<NonZero<u128>, Error> {
6900        self.checked_next_power_of_two().ok_or_else(|| {
6901            Error::new(format!(
6902                "failed to compute next_power_of_two({:?}): {} overflow",
6903                self, "NonZero<u128>"
6904            ))
6905        })
6906    }
6907}
6908impl CnextPowerOfTwo for NonZero<usize> {
6909    type Output = NonZero<usize>;
6910    type Error = Error;
6911    ///Checked next power of 2, returning an error if overflow occured.
6912    ///
6913    ///Wrapper for [`NonZero<usize>::checked_next_power_of_two`].
6914    #[inline]
6915    fn cnext_power_of_two(self) -> Result<NonZero<usize>, Error> {
6916        self.checked_next_power_of_two().ok_or_else(|| {
6917            Error::new(format!(
6918                "failed to compute next_power_of_two({:?}): {} overflow",
6919                self, "NonZero<usize>"
6920            ))
6921        })
6922    }
6923}
6924impl CnextPowerOfTwo for u8 {
6925    type Output = u8;
6926    type Error = Error;
6927    ///Checked next power of 2, returning an error if overflow occured.
6928    ///
6929    ///Wrapper for [`u8::checked_next_power_of_two`].
6930    #[inline]
6931    fn cnext_power_of_two(self) -> Result<u8, Error> {
6932        self.checked_next_power_of_two().ok_or_else(|| {
6933            Error::new(format!(
6934                "failed to compute next_power_of_two({:?}): {} overflow",
6935                self, "u8"
6936            ))
6937        })
6938    }
6939}
6940impl CnextPowerOfTwo for u16 {
6941    type Output = u16;
6942    type Error = Error;
6943    ///Checked next power of 2, returning an error if overflow occured.
6944    ///
6945    ///Wrapper for [`u16::checked_next_power_of_two`].
6946    #[inline]
6947    fn cnext_power_of_two(self) -> Result<u16, Error> {
6948        self.checked_next_power_of_two().ok_or_else(|| {
6949            Error::new(format!(
6950                "failed to compute next_power_of_two({:?}): {} overflow",
6951                self, "u16"
6952            ))
6953        })
6954    }
6955}
6956impl CnextPowerOfTwo for u32 {
6957    type Output = u32;
6958    type Error = Error;
6959    ///Checked next power of 2, returning an error if overflow occured.
6960    ///
6961    ///Wrapper for [`u32::checked_next_power_of_two`].
6962    #[inline]
6963    fn cnext_power_of_two(self) -> Result<u32, Error> {
6964        self.checked_next_power_of_two().ok_or_else(|| {
6965            Error::new(format!(
6966                "failed to compute next_power_of_two({:?}): {} overflow",
6967                self, "u32"
6968            ))
6969        })
6970    }
6971}
6972impl CnextPowerOfTwo for u64 {
6973    type Output = u64;
6974    type Error = Error;
6975    ///Checked next power of 2, returning an error if overflow occured.
6976    ///
6977    ///Wrapper for [`u64::checked_next_power_of_two`].
6978    #[inline]
6979    fn cnext_power_of_two(self) -> Result<u64, Error> {
6980        self.checked_next_power_of_two().ok_or_else(|| {
6981            Error::new(format!(
6982                "failed to compute next_power_of_two({:?}): {} overflow",
6983                self, "u64"
6984            ))
6985        })
6986    }
6987}
6988impl CnextPowerOfTwo for u128 {
6989    type Output = u128;
6990    type Error = Error;
6991    ///Checked next power of 2, returning an error if overflow occured.
6992    ///
6993    ///Wrapper for [`u128::checked_next_power_of_two`].
6994    #[inline]
6995    fn cnext_power_of_two(self) -> Result<u128, Error> {
6996        self.checked_next_power_of_two().ok_or_else(|| {
6997            Error::new(format!(
6998                "failed to compute next_power_of_two({:?}): {} overflow",
6999                self, "u128"
7000            ))
7001        })
7002    }
7003}
7004impl CnextPowerOfTwo for usize {
7005    type Output = usize;
7006    type Error = Error;
7007    ///Checked next power of 2, returning an error if overflow occured.
7008    ///
7009    ///Wrapper for [`usize::checked_next_power_of_two`].
7010    #[inline]
7011    fn cnext_power_of_two(self) -> Result<usize, Error> {
7012        self.checked_next_power_of_two().ok_or_else(|| {
7013            Error::new(format!(
7014                "failed to compute next_power_of_two({:?}): {} overflow",
7015                self, "usize"
7016            ))
7017        })
7018    }
7019}
7020///Checked duration since: computes `a.duration_since(b)`, returning an error if b is earlier than a.
7021///
7022///See also: [module documentation](self).
7023pub trait CdurationSince: Sized {
7024    #[expect(missing_docs, reason = "no need for doc")]
7025    type Other;
7026    #[expect(missing_docs, reason = "no need for doc")]
7027    type Output;
7028    #[expect(missing_docs, reason = "no need for doc")]
7029    type Error;
7030    ///Checked duration since: computes `a.duration_since(b)`, returning an error if b is earlier than a.
7031    ///
7032    ///Wrapper for `checked_duration_since`.
7033    fn cduration_since(self, other: Self::Other) -> Result<Self::Output, Self::Error>;
7034}
7035///Checked duration since: computes `a.duration_since(b)`, returning an error if b is earlier than a.
7036///
7037///Wrapper for `checked_duration_since`.
7038///
7039///See also: [module documentation](self).
7040#[doc(alias = "checked_duration_since")]
7041#[inline]
7042pub fn cduration_since<T>(a: T, b: T::Other) -> Result<T::Output, T::Error>
7043where
7044    T: CdurationSince,
7045{
7046    a.cduration_since(b)
7047}
7048#[cfg(feature = "std")]
7049impl CdurationSince for Instant {
7050    type Other = Instant;
7051    type Output = Duration;
7052    type Error = Error;
7053    ///Checked duration since: computes `a.duration_since(b)`, returning an error if b is earlier than a.
7054    ///
7055    ///Wrapper for [`Instant::checked_duration_since`].
7056    #[inline]
7057    fn cduration_since(self, other: Instant) -> Result<Duration, Error> {
7058        self.checked_duration_since(other).ok_or_else(|| {
7059            Error::new(format!(
7060                "failed to compute {:?}.duration_since({:?}): {:?} is earlier than {:?}",
7061                self, other, other, self
7062            ))
7063        })
7064    }
7065}