devela 0.27.0

A development layer of coherence.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
// devela::num::grain::cast::namespace::cast
//
//! fns to cast between primitives in a checked manner.
//
// TOC
// - impl_cast_fns!
// - impl_cast_aliases!
// - impl_cast_methods!

use crate::{
    Cast, Overflow,
    Sign::{Negative, Positive},
    is, isize_down, isize_up, paste, usize_down, usize_up,
};

/// Implements private, standalone casting functions between integer primitives
///
/// `$f`:   the type to cast from
/// `$t`:   the type to cast to
macro_rules! impl_cast_fns {
    () => {
        /* independent of pointer width */

        impl_cast_fns![can_overunderflow
            // from bigger signed to unsigned
            i16:u8, i32:u8, i64:u8, i128:u8,
            i32:u16, i64:u16, i128:u16,
            i64:u32, i128:u32,
            i128:u64,
            // from bigger signed to signed
            i16:i8, i32:i8, i64:i8, i128:i8,
            i32:i16, i64:i16, i128:i16,
            i64:i32, i128:i32,
            i128:i64
        ];
        impl_cast_fns![can_overflow
            // from bigger unsigned to unsigned
            u16:u8, u32:u8, u64:u8, u128:u8,
            u32:u16, u64:u16, u128:u16,
            u64:u32, u128:u32,
            u128:u64,
            // from bigger unsigned to signed
            u16:i8, u32:i8, u64:i8, u128:i8,
            u32:i16, u64:i16, u128:i16,
            u64:i32, u128:i32,
            u128:i64,
            // from equalsized unsigned to signed
            u8:i8, u16:i16, u32:i32, u64:i64, u128:i128, usize:isize
        ];
        impl_cast_fns![can_underflow
            // from smaller signed to unsigned
            i8:u16, i8:u32, i8:u64, i8:u128,
            i16:u32, i16:u64, i16:u128,
            i32:u64, i32:u128,
            i64:u128,
            // from equalsized signed to unsigned
            i8:u8, i16:u16, i32:u32, i64:u64, i128:u128, isize:usize
        ];
        impl_cast_fns![cant_fail
            // from smaller unsigned to unsigned
            u8:u16, u8:u32, u8:u64, u8:u128,
            u16:u32, u16:u64, u16:u128,
            u32:u64, u32:u128,
            u64:u128,
            // from smaller unsigned to signed
            u8:i16, u8:i32, u8:i64, u8:i128,
            u16:i32, u16:i64, u16:i128,
            u32:i64, u32:i128,
            u64:i128,
            // from smaller signed to signed
            i8:i16, i8:i32, i8:i64, i8:i128,
            i16:i32, i16:i64, i16:i128,
            i32:i64, i32:i128,
            i64:i128,
            // from equalsized unsigned to unsigned
            u8:u8, u16:u16, u32:u32, u64:u64, u128:u128, usize:usize,
            // from equalsized signed to signed
            i8:i8, i16:i16, i32:i32, i64:i64, i128:i128, isize:isize
        ];

        /* dependent on pointer width */

        #[cfg(target_pointer_width = "16")]
        impl_cast_fns![can_overunderflow
            // from bigger signed to unsigned
            isize:u8,
            i32:usize, i64:usize, i128:usize,
            // from bigger signed to signed
            isize:i8,
            i32:isize, i64:isize, i128:isize
        ];
        #[cfg(target_pointer_width = "32")]
        impl_cast_fns![can_overunderflow
            // from bigger signed to unsigned
            isize:u8, isize:u16,
            i64:usize, i128:usize,
            // from bigger signed to signed
            isize:i8, isize:i16,
            i64:isize, i128:isize
        ];
        #[cfg(target_pointer_width = "64")]
        impl_cast_fns![can_overunderflow
            // from bigger signed to unsigned
            isize:u8, isize:u16, isize:u32,
            i128:usize,
            // from bigger signed to signed
            isize:i8, isize:i16, isize:i32,
            i128:isize
        ];

        #[cfg(target_pointer_width = "16")]
        impl_cast_fns![can_overflow
            // from bigger unsigned to unsigned
            usize:u8,
            u32:usize, u64:usize, u128:usize,
            // from bigger unsigned to signed
            usize:i8,
            u32:isize, u64:isize, u128:isize,
            // from equalsized unsigned to signed
            u16:isize, usize:i16
        ];
        #[cfg(target_pointer_width = "32")]
        impl_cast_fns![can_overflow
            // from bigger unsigned to unsigned
            usize:u8, usize:u16,
            u64:usize, u128:usize,
            // from bigger unsigned to signed
            usize:i8, usize:i16,
            u64:isize, u128:isize,
            // from equalsized unsigned to signed
            u32:isize, usize:i32
        ];
        #[cfg(target_pointer_width = "64")]
        impl_cast_fns![can_overflow
            // from bigger unsigned to unsigned
            usize:u8, usize:u16, usize:u32,
            u128:usize,
            // from bigger unsigned to signed
            usize:i8, usize:i16, usize:i32,
            u128:isize,
            // from equalsized unsigned to signed
            u64:isize, usize:i64
        ];

        #[cfg(target_pointer_width = "16")]
        impl_cast_fns![can_underflow
            // from smaller signed to unsigned
            isize:u32, isize:u64, isize:u128,
            i8:usize,
            // from equalsized signed to unsigned
            i16:usize, isize:u16
        ];
        #[cfg(target_pointer_width = "32")]
        impl_cast_fns![can_underflow
            // from smaller signed to unsigned
            isize:u64, isize:u128,
            i8:usize, i16:usize,
            // from equalsized signed to unsigned
            i32:usize, isize:u32
        ];
        #[cfg(target_pointer_width = "64")]
        impl_cast_fns![can_underflow
            // from smaller signed to unsigned
            isize:u128,
            i8:usize, i16:usize, i32:usize,
            // from equalsized signed to unsigned
            i64:usize, isize:u64
        ];

        #[cfg(target_pointer_width = "16")]
        impl_cast_fns![cant_fail ptr:16
            // from smaller unsigned to unsigned
            usize:u32, usize:u64, usize:u128,
            u8:usize,
            // from smaller unsigned to signed
            usize:i32, usize:i64, usize:i128,
            u8:isize,
            // from smaller signed to signed
            isize:i32, isize:i64, isize:i128,
            i8:isize,
            // from equalsized unsigned to unsigned
            usize:u16, u16:usize,
            // from equalsized signed to signed
            isize:i16, i16:isize
        ];
        #[cfg(target_pointer_width = "32")]
        impl_cast_fns![cant_fail ptr:32
            // from smaller unsigned to unsigned
            usize:u64, usize:u128,
            u8:usize, u16:usize,
            // from smaller unsigned to signed
            usize:i64, usize:i128,
            u8:isize, u16:isize,
            // from smaller signed to signed
            isize:i64, isize:i128,
            i8:isize, i16:isize,
            // from equalsized unsigned to unsigned
            usize:u32, u32:usize,
            // from equalsized signed to signed
            isize:i32, i32:isize
        ];
        #[cfg(target_pointer_width = "64")]
        impl_cast_fns![cant_fail ptr:64
            // from smaller unsigned to unsigned
            usize:u128,
            u8:usize, u16:usize, u32:usize,
            // from smaller unsigned to signed
            usize:i128,
            u8:isize, u16:isize, u32:isize,
            // from smaller signed to signed
            isize:i128,
            i8:isize, i16:isize, i32:isize,
            // from equalsized unsigned to unsigned
            usize:u64, u64:usize,
            // from equalsized signed to signed
            isize:i64, i64:isize
        ];
    };
    (can_overunderflow $( $f:ty : $t:ty ),+) => {
        $( impl_cast_fns![@can_overunderflow $f:$t]; )+
    };
    (@can_overunderflow $f:ty : $t:ty) => { paste! {
        const fn [<checked_cast_ $f _to_ $t>](p: $f) -> Result<$t, Overflow> {
            if p < <$t>::MIN as $f {
                Err(Overflow(Some(Negative)))
            } else if p > $t::MAX as $f {
                Err(Overflow(Some(Positive)))
            } else {
                Ok(p as $t)
            }
        }
        const fn [<saturating_cast_ $f _to_ $t>](p: $f) -> $t {
            if p < <$t>::MIN as $f {
                <$t>::MIN
            } else if p > $t::MAX as $f {
                <$t>::MAX
            } else {
                p as $t
            }
        }
        #[inline(always)]
        const fn [<wrapping_cast_ $f _to_ $t>](p: $f) -> $t {
            p as $t
        }
    }};
    (can_overflow $( $f:ty:$t:ty ),+) => { $( impl_cast_fns![@can_overflow $f:$t]; )+ };
    (@can_overflow $f:ty:$t:ty) => { paste! {
        const fn [<checked_cast_ $f _to_ $t>](p: $f) -> Result<$t, Overflow> {
            is![p > <$t>::MAX as $f, Err(Overflow(Some(Positive))), Ok(p as $t)]
        }
        const fn [<saturating_cast_ $f _to_ $t>](p: $f) -> $t {
            is![p > <$t>::MAX as $f, <$t>::MAX, p as $t]
        }
        #[inline(always)]
        const fn [<wrapping_cast_ $f _to_ $t>](p: $f) -> $t {
            p as $t
        }
    }};
    (can_underflow $( $f:ty:$t:ty ),+) => { $( impl_cast_fns![@can_underflow $f:$t]; )+ };
    (@can_underflow $f:ty:$t:ty) => { paste! {
        #[inline(always)]
        const fn [<checked_cast_ $f _to_ $t>](p: $f) -> Result<$t, Overflow> {
            is![p < 0, Err(Overflow(Some(Negative))), Ok(p as $t)]
        }
        #[inline(always)]
        const fn [<saturating_cast_ $f _to_ $t>](p: $f) -> $t {
            is![p < 0, 0, p as $t]
        }
        #[inline(always)]
        const fn [<wrapping_cast_ $f _to_ $t>](p: $f) -> $t {
            p as $t
        }
    }};
    (cant_fail $( $f:ty:$t:ty ),+) => { $( impl_cast_fns![@cant_fail $f:$t]; )+ };
    (@cant_fail $f:ty:$t:ty) => { paste! {
        #[inline(always)]
        const fn [<checked_cast_ $f _to_ $t>](p: $f) -> Result<$t, Overflow> {
            Ok(p as $t)
        }
        #[inline(always)]
        const fn [<saturating_cast_ $f _to_ $t>](p: $f) -> $t {
            p as $t
        }
        #[inline(always)]
        const fn [<wrapping_cast_ $f _to_ $t>](p: $f) -> $t {
            p as $t
        }
    }};
    (cant_fail ptr:$ptr:literal $( $f:ty:$t:ty ),+) => {
        $( impl_cast_fns![@cant_fail ptr:$ptr $f:$t]; )+
    };
    (@cant_fail ptr:$ptr:literal $f:ty:$t:ty) => { paste! {
        #[inline(always)]
        const fn [<checked_cast_ $f _to_ $t>](p: $f) -> Result<$t, Overflow> {
            Ok(p as $t)
        }
        #[inline(always)]
        const fn [<saturating_cast_ $f _to_ $t>](p: $f) -> $t {
            p as $t
        }
        #[inline(always)]
        const fn [<wrapping_cast_ $f _to_ $t>](p: $f) -> $t {
            p as $t
        }
    }};
}
impl_cast_fns![];

/// implement the casting functions for the upcasted aliases
///
/// `$f`: the type to cast from
/// `$a`: the type to cast to (name alias)
/// `$t`: the type to cast to (real type)
macro_rules! impl_cast_fns_alias {
    () => {
        #[cfg(target_pointer_width = "16")] impl_cast_fns_alias![@to isize_up|i32];
        #[cfg(target_pointer_width = "16")] impl_cast_fns_alias![@to usize_up|u32];
        #[cfg(target_pointer_width = "16")] impl_cast_fns_alias![@to isize_down|i8];
        #[cfg(target_pointer_width = "16")] impl_cast_fns_alias![@to usize_down|u8];
        //
        #[cfg(target_pointer_width = "32")] impl_cast_fns_alias![@to isize_up|i64];
        #[cfg(target_pointer_width = "32")] impl_cast_fns_alias![@to usize_up|u64];
        #[cfg(target_pointer_width = "32")] impl_cast_fns_alias![@to isize_down|i16];
        #[cfg(target_pointer_width = "32")] impl_cast_fns_alias![@to usize_down|u16];
        //
        #[cfg(target_pointer_width = "64")] impl_cast_fns_alias![@to isize_up|i128];
        #[cfg(target_pointer_width = "64")] impl_cast_fns_alias![@to usize_up|u128];
        #[cfg(target_pointer_width = "64")] impl_cast_fns_alias![@to isize_down|i32];
        #[cfg(target_pointer_width = "64")] impl_cast_fns_alias![@to usize_down|u32];
    };
    (@to $a:ident|$t:ty) => {
        impl_cast_fns_alias![@to $a|$t:
            i8, u8, i16, u16, i32, u32, i64, u64, i128, u128, isize, usize];
    };
    (@to $a:ident|$t:ty : $($f:ty),+) => { $( impl_cast_fns_alias!(@impl $f, $a, $t);)+ };
    (@impl $f:ty, $a:ty, $t:ty) => { paste! {
        #[inline(always)]
        const fn [<checked_cast_ $f _to_ $a>](p: $f) -> Result<$a, Overflow> {
            [<checked_cast_ $f _to_ $t>](p)
        }
        #[inline(always)]
        const fn [<saturating_cast_ $f _to_ $a>](p: $f) -> $a {
            [<saturating_cast_ $f _to_ $t>](p)
        }
        #[inline(always)]
        const fn [<wrapping_cast_ $f _to_ $a>](p: $f) -> $a {
            [<wrapping_cast_ $f _to_ $t>](p)
        }
    }};
}
impl_cast_fns_alias![];

/// Implements the public casting methods for the [`Cast`] namespace.
macro_rules! impl_cast_methods {
    () => {
        impl_cast_methods![u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128, isize];
    };
    ($($t:ty),+) => { $( impl_cast_methods![@$t]; )+ };
    (@$t:ty) => { paste! {
        /// Checked casts and saturating casts.
        ///
        /// # Errors
        /// Checked methods will return [`Overflow`] if `self` can't fit in the returned type.
        impl Cast<$t> {
            /* checked */

            #[inline(always)]
            #[doc = "Casts from `" $t "` to `u8` with range check."]
            pub const fn checked_cast_to_u8(self) -> Result<u8, Overflow> {
                [<checked_cast_ $t _to_u8>](self.0)
            }
            #[inline(always)]
            #[doc = "Casts from `" $t "` to `u16` with range check."]
            pub const fn checked_cast_to_u16(self) -> Result<u16, Overflow> {
                [<checked_cast_ $t _to_u16>](self.0)
            }
            #[inline(always)]
            #[doc = "Casts from `" $t "` to `u32` with range check."]
            pub const fn checked_cast_to_u32(self) -> Result<u32, Overflow> {
                [<checked_cast_ $t _to_u32>](self.0)
            }
            #[inline(always)]
            #[doc = "Casts from `" $t "` to `u64` with range check."]
            pub const fn checked_cast_to_u64(self) -> Result<u64, Overflow> {
                [<checked_cast_ $t _to_u64>](self.0)
            }
            #[inline(always)]
            #[doc = "Casts from `" $t "` to `u128` with range check."]
            pub const fn checked_cast_to_u128(self) -> Result<u128, Overflow> {
                [<checked_cast_ $t _to_u128>](self.0)
            }
            #[inline(always)]
            #[doc = "Casts from `" $t "` to `usize` with range check."]
            pub const fn checked_cast_to_usize(self) -> Result<usize, Overflow> {
                [<checked_cast_ $t _to_usize>](self.0)
            }
            #[inline(always)]
            #[doc = "Casts from `" $t "` to `usize_up` with range check."]
            pub const fn checked_cast_to_usize_up(self) -> Result<usize_up, Overflow> {
                [<checked_cast_ $t _to_usize_up>](self.0)
            }
            #[inline(always)]
            #[doc = "Casts from `" $t "` to `usize_down` with range check."]
            pub const fn checked_cast_to_usize_down(self) -> Result<usize_down, Overflow> {
                [<checked_cast_ $t _to_usize_down>](self.0)
            }

            #[inline(always)]
            #[doc = "Casts from `" $t "` to `i8` with range check."]
            pub const fn checked_cast_to_i8(self) -> Result<i8, Overflow> {
                [<checked_cast_ $t _to_i8>](self.0)
            }
            #[inline(always)]
            #[doc = "Casts from `" $t "` to `i16` with range check."]
            pub const fn checked_cast_to_i16(self) -> Result<i16, Overflow> {
                [<checked_cast_ $t _to_i16>](self.0)
            }
            #[inline(always)]
            #[doc = "Casts from `" $t "` to `i32` with range check."]
            pub const fn checked_cast_to_i32(self) -> Result<i32, Overflow> {
                [<checked_cast_ $t _to_i32>](self.0)
            }
            #[inline(always)]
            #[doc = "Casts from `" $t "` to `i64` with range check."]
            pub const fn checked_cast_to_i64(self) -> Result<i64, Overflow> {
                [<checked_cast_ $t _to_i64>](self.0)
            }
            #[inline(always)]
            #[doc = "Casts from `" $t "` to `i128` with range check."]
            pub const fn checked_cast_to_i128(self) -> Result<i128, Overflow> {
                [<checked_cast_ $t _to_i128>](self.0)
            }
            #[inline(always)]
            #[doc = "Casts from `" $t "` to `isize` with range check."]
            pub const fn checked_cast_to_isize(self) -> Result<isize, Overflow> {
                [<checked_cast_ $t _to_isize>](self.0)
            }
            #[inline(always)]
            #[doc = "Casts from `" $t "` to `isize_up` with range check."]
            pub const fn checked_cast_to_isize_up(self) -> Result<isize_up, Overflow> {
                [<checked_cast_ $t _to_isize_up>](self.0)
            }
            #[inline(always)]
            #[doc = "Casts from `" $t "` to `isize_down` with range check."]
            pub const fn checked_cast_to_isize_down(self) -> Result<isize_down, Overflow> {
                [<checked_cast_ $t _to_isize_down>](self.0)
            }

            /* saturating */

            #[must_use]
            #[inline(always)]
            #[doc = "Casts from `" $t "` to `u8` clamping at the numeric bounds."]
            pub const fn saturating_cast_to_u8(self) -> u8 {
                [<saturating_cast_ $t _to_u8>](self.0)
            }
            #[must_use]
            #[inline(always)]
            #[doc = "Casts from `" $t "` to `u16` clamping at the numeric bounds."]
            pub const fn saturating_cast_to_u16(self) -> u16 {
                [<saturating_cast_ $t _to_u16>](self.0)
            }
            #[must_use]
            #[inline(always)]
            #[doc = "Casts from `" $t "` to `u32` clamping at the numeric bounds."]
            pub const fn saturating_cast_to_u32(self) -> u32 {
                [<saturating_cast_ $t _to_u32>](self.0)
            }
            #[must_use]
            #[inline(always)]
            #[doc = "Casts from `" $t "` to `u64` clamping at the numeric bounds."]
            pub const fn saturating_cast_to_u64(self) -> u64 {
                [<saturating_cast_ $t _to_u64>](self.0)
            }
            #[must_use]
            #[inline(always)]
            #[doc = "Casts from `" $t "` to `u128` clamping at the numeric bounds."]
            pub const fn saturating_cast_to_u128(self) -> u128 {
                [<saturating_cast_ $t _to_u128>](self.0)
            }
            #[must_use]
            #[inline(always)]
            #[doc = "Casts from `" $t "` to `usize` clamping at the numeric bounds."]
            pub const fn saturating_cast_to_usize(self) -> usize {
                [<saturating_cast_ $t _to_usize>](self.0)
            }
            #[must_use]
            #[inline(always)]
            #[doc = "Casts from `" $t "` to `usize_up` clamping at the numeric bounds."]
            pub const fn saturating_cast_to_usize_up(self) -> usize_up {
                [<saturating_cast_ $t _to_usize_up>](self.0)
            }
            #[must_use]
            #[inline(always)]
            #[doc = "Casts from `" $t "` to `usize_down` clamping at the numeric bounds."]
            pub const fn saturating_cast_to_usize_down(self) -> usize_down {
                [<saturating_cast_ $t _to_usize_down>](self.0)
            }

            #[must_use]
            #[inline(always)]
            #[doc = "Casts from `" $t "` to `i8` clamping at the numeric bounds."]
            pub const fn saturating_cast_to_i8(self) -> i8 {
                [<saturating_cast_ $t _to_i8>](self.0)
            }
            #[must_use]
            #[inline(always)]
            #[doc = "Casts from `" $t "` to `i16` clamping at the numeric bounds."]
            pub const fn saturating_cast_to_i16(self) -> i16 {
                [<saturating_cast_ $t _to_i16>](self.0)
            }
            #[must_use]
            #[inline(always)]
            #[doc = "Casts from `" $t "` to `i32` clamping at the numeric bounds."]
            pub const fn saturating_cast_to_i32(self) -> i32 {
                [<saturating_cast_ $t _to_i32>](self.0)
            }
            #[must_use]
            #[inline(always)]
            #[doc = "Casts from `" $t "` to `i64` clamping at the numeric bounds."]
            pub const fn saturating_cast_to_i64(self) -> i64 {
                [<saturating_cast_ $t _to_i64>](self.0)
            }
            #[must_use]
            #[inline(always)]
            #[doc = "Casts from `" $t "` to `i128` clamping at the numeric bounds."]
            pub const fn saturating_cast_to_i128(self) -> i128 {
                [<saturating_cast_ $t _to_i128>](self.0)
            }
            #[must_use]
            #[inline(always)]
            #[doc = "Casts from `" $t "` to `isize` clamping at the numeric bounds."]
            pub const fn saturating_cast_to_isize(self) -> isize {
                [<saturating_cast_ $t _to_isize>](self.0)
            }
            #[must_use]
            #[inline(always)]
            #[doc = "Casts from `" $t "` to `isize_up` clamping at the numeric bounds."]
            pub const fn saturating_cast_to_isize_up(self) -> isize_up {
                [<saturating_cast_ $t _to_isize_up>](self.0)
            }
            #[must_use]
            #[inline(always)]
            #[doc = "Casts from `" $t "` to `isize_down` clamping at the numeric bounds."]
            pub const fn saturating_cast_to_isize_down(self) -> isize_down {
                [<saturating_cast_ $t _to_isize_down>](self.0)
            }

            /* wrapping */

            #[must_use]
            #[inline(always)]
            #[doc = "Casts from `" $t "` to `u8` wrapping at the numeric bounds."]
            pub const fn wrapping_cast_to_u8(self) -> u8 {
                [<wrapping_cast_ $t _to_u8>](self.0)
            }
            #[must_use]
            #[inline(always)]
            #[doc = "Casts from `" $t "` to `u16` wrapping at the numeric bounds."]
            pub const fn wrapping_cast_to_u16(self) -> u16 {
                [<wrapping_cast_ $t _to_u16>](self.0)
            }
            #[must_use]
            #[inline(always)]
            #[doc = "Casts from `" $t "` to `u32` wrapping at the numeric bounds."]
            pub const fn wrapping_cast_to_u32(self) -> u32 {
                [<wrapping_cast_ $t _to_u32>](self.0)
            }
            #[must_use]
            #[inline(always)]
            #[doc = "Casts from `" $t "` to `u64` wrapping at the numeric bounds."]
            pub const fn wrapping_cast_to_u64(self) -> u64 {
                [<wrapping_cast_ $t _to_u64>](self.0)
            }
            #[must_use]
            #[inline(always)]
            #[doc = "Casts from `" $t "` to `u128` wrapping at the numeric bounds."]
            pub const fn wrapping_cast_to_u128(self) -> u128 {
                [<wrapping_cast_ $t _to_u128>](self.0)
            }
            #[must_use]
            #[inline(always)]
            #[doc = "Casts from `" $t "` to `usize` wrapping at the numeric bounds."]
            pub const fn wrapping_cast_to_usize(self) -> usize {
                [<wrapping_cast_ $t _to_usize>](self.0)
            }
            #[must_use]
            #[inline(always)]
            #[doc = "Casts from `" $t "` to `usize_up` wrapping at the numeric bounds."]
            pub const fn wrapping_cast_to_usize_up(self) -> usize_up {
                [<wrapping_cast_ $t _to_usize_up>](self.0)
            }
            #[must_use]
            #[inline(always)]
            #[doc = "Casts from `" $t "` to `usize_down` wrapping at the numeric bounds."]
            pub const fn wrapping_cast_to_usize_down(self) -> usize_down {
                [<wrapping_cast_ $t _to_usize_down>](self.0)
            }

            #[must_use]
            #[inline(always)]
            #[doc = "Casts from `" $t "` to `i8` wrapping at the numeric bounds."]
            pub const fn wrapping_cast_to_i8(self) -> i8 {
                [<wrapping_cast_ $t _to_i8>](self.0)
            }
            #[must_use]
            #[inline(always)]
            #[doc = "Casts from `" $t "` to `i16` wrapping at the numeric bounds."]
            pub const fn wrapping_cast_to_i16(self) -> i16 {
                [<wrapping_cast_ $t _to_i16>](self.0)
            }
            #[must_use]
            #[inline(always)]
            #[doc = "Casts from `" $t "` to `i32` wrapping at the numeric bounds."]
            pub const fn wrapping_cast_to_i32(self) -> i32 {
                [<wrapping_cast_ $t _to_i32>](self.0)
            }
            #[must_use]
            #[inline(always)]
            #[doc = "Casts from `" $t "` to `i64` wrapping at the numeric bounds."]
            pub const fn wrapping_cast_to_i64(self) -> i64 {
                [<wrapping_cast_ $t _to_i64>](self.0)
            }
            #[must_use]
            #[inline(always)]
            #[doc = "Casts from `" $t "` to `i128` wrapping at the numeric bounds."]
            pub const fn wrapping_cast_to_i128(self) -> i128 {
                [<wrapping_cast_ $t _to_i128>](self.0)
            }
            #[must_use]
            #[inline(always)]
            #[doc = "Casts from `" $t "` to `isize` wrapping at the numeric bounds."]
            pub const fn wrapping_cast_to_isize(self) -> isize {
                [<wrapping_cast_ $t _to_isize>](self.0)
            }
            #[must_use]
            #[inline(always)]
            #[doc = "Casts from `" $t "` to `isize_up` wrapping at the numeric bounds."]
            pub const fn wrapping_cast_to_isize_up(self) -> isize_up {
                [<wrapping_cast_ $t _to_isize_up>](self.0)
            }
            #[must_use]
            #[inline(always)]
            #[doc = "Casts from `" $t "` to `isize_down` wrapping at the numeric bounds."]
            pub const fn wrapping_cast_to_isize_down(self) -> isize_down {
                [<wrapping_cast_ $t _to_isize_down>](self.0)
            }
        }
    }};
}
impl_cast_methods![];