1use super::*;
2
3impl ToU8 for i128 {
4 fn to_u8(self) -> u8 {
5 self.to_u128().to_u8()
6 }
7}
8impl ToU16 for i128 {
9 fn to_u16(self) -> u16 {
10 self.to_u128().to_u16()
11 }
12}
13impl ToU32 for i128 {
14 fn to_u32(self) -> u32 {
15 self.to_u128().to_u32()
16 }
17}
18impl ToU64 for i128 {
19 fn to_u64(self) -> u64 {
20 self.to_u128().to_u64()
21 }
22}
23impl ToU128 for i128 {
24 fn to_u128(self) -> u128 {
25 if self & Self::MIN != 0 {
26 0
27 } else {
28 self as u128
29 }
30 }
31}
32
33impl ToI8 for i128 {
34 fn to_i8(self) -> i8 {
35 match self {
36 ..-0x80 => i8::MIN,
37 -0x80..0x80 => self as i8,
38 0x80.. => i8::MAX,
39 }
40 }
41}
42impl ToI16 for i128 {
43 fn to_i16(self) -> i16 {
44 match self {
45 ..-0x8000 => i16::MIN,
46 -0x8000..0x8000 => self as i16,
47 0x8000.. => i16::MAX,
48 }
49 }
50}
51impl ToI32 for i128 {
52 fn to_i32(self) -> i32 {
53 match self {
54 ..-0x8000_0000 => i32::MIN,
55 -0x8000_0000..0x8000_0000 => self as i32,
56 0x8000_0000.. => i32::MAX,
57 }
58 }
59}
60impl ToI64 for i128 {
61 fn to_i64(self) -> i64 {
62 match self {
63 ..-0x8000_0000_0000_0000 => i64::MIN,
64 -0x8000_0000_0000_0000..0x8000_0000_0000_0000 => self as i64,
65 0x8000_0000_0000_0000.. => i64::MAX,
66 }
67 }
68}
69impl AsI128 for i128 {
70 fn as_i128(self) -> i128 {
71 self
72 }
73}
74
75impl ToF32 for i128 {
76 fn to_f32(self) -> f32 {
77 self as f32
78 }
79}
80impl ToF64 for i128 {
81 fn to_f64(self) -> f64 {
82 self as f64
83 }
84}