devela/num/int/wrapper/
namespace.rs
1#[doc = crate::TAG_NAMESPACE!()]
7#[repr(transparent)]
35pub struct Int<T>(pub T);
36
37crate::num::impl_ops![Int:
38 i8:"_int_i8",
39 i16:"_int_i16",
40 i32:"_int_i32",
41 i64:"_int_i64",
42 i128:"_int_i128",
43 isize:"_int_isize"];
44crate::num::impl_ops![Int: (no_neg)
45 u8:"_int_i8",
46 u16:"_int_u16",
47 u32:"_int_u32",
48 u64:"_int_u64",
49 u128:"_int_u128",
50 usize:"_int_usize"];
51
52#[rustfmt::skip]
53mod core_impls {
54 use core::fmt;
55 use crate::{Hash, Hasher, Int, Ordering, ValueQuant};
56
57 impl<T: Clone> Clone for Int<T> {
58 #[must_use]
59 fn clone(&self) -> Self { Self(self.0.clone()) }
60 }
61 impl<T: Copy> Copy for Int<T> {}
62 impl<T: fmt::Debug> fmt::Debug for Int<T> {
63 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
64 f.debug_tuple("Int").field(&self.0).finish()
65 }
66 }
67 impl<T: fmt::Display> fmt::Display for Int<T> {
68 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fmt::Display::fmt(&self.0, f) }
69 }
70 impl<T: fmt::Binary> fmt::Binary for Int<T> {
71 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fmt::Binary::fmt(&self.0, f) }
72 }
73 impl<T: fmt::Octal> fmt::Octal for Int<T> {
74 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fmt::Octal::fmt(&self.0, f) }
75 }
76 impl<T: fmt::LowerHex> fmt::LowerHex for Int<T> {
77 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fmt::LowerHex::fmt(&self.0, f) }
78 }
79 impl<T: fmt::UpperHex> fmt::UpperHex for Int<T> {
80 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fmt::UpperHex::fmt(&self.0, f) }
81 }
82 impl<T: fmt::UpperExp> fmt::UpperExp for Int<T> {
83 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fmt::UpperExp::fmt(&self.0, f) }
84 }
85 impl<T: fmt::LowerExp> fmt::LowerExp for Int<T> {
86 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fmt::LowerExp::fmt(&self.0, f) }
87 }
88
89 impl<T: PartialEq> PartialEq for Int<T> {
92 #[must_use]
93 fn eq(&self, other: &Self) -> bool { self.0.eq(&other.0) }
94 }
95 impl<T: Eq> Eq for Int<T> {}
96 impl<T: PartialEq> PartialEq<T> for Int<T> {
98 #[must_use]
99 fn eq(&self, other: &T) -> bool { self.0.eq(other) }
100 }
101 impl<T: PartialEq> PartialEq<ValueQuant<T, T>> for ValueQuant<Int<T>, Int<T>> {
103 #[must_use]
104 fn eq(&self, other: &ValueQuant<T, T>) -> bool {
105 self.v.eq(&other.v) && self.q.eq(&other.q)
106 }
107 }
108 impl<T: PartialEq> PartialEq<ValueQuant<Int<T>, Int<T>>> for ValueQuant<T, T> {
109 #[must_use]
110 fn eq(&self, other: &ValueQuant<Int<T>, Int<T>>) -> bool {
111 self.v.eq(&other.v.0) && self.q.eq(&other.q.0)
112 }
113 }
114 impl<T: PartialEq> PartialEq<(T, T)> for ValueQuant<Int<T>, Int<T>> {
116 #[must_use]
117 fn eq(&self, other: &(T, T)) -> bool {
118 self.v.eq(&other.0) && self.q.eq(&other.1)
119 }
120 }
121 impl<T: PartialEq> PartialEq<(Int<T>, Int<T>)> for ValueQuant<T, T> {
122 #[must_use]
123 fn eq(&self, other: &(Int<T>, Int<T>)) -> bool {
124 self.v.eq(&other.0.0) && self.q.eq(&other.1.0)
125 }
126 }
127
128 impl<T: PartialOrd> PartialOrd for Int<T> {
131 #[must_use]
132 fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
133 self.0.partial_cmp(&other.0)
134 }
135 }
136 impl<T: Ord> Ord for Int<T> {
137 #[must_use]
138 fn cmp(&self, other: &Self) -> Ordering {
139 self.0.cmp(&other.0)
140 }
141 }
142 impl<T: PartialOrd> PartialOrd<T> for Int<T> {
144 #[must_use]
145 fn partial_cmp(&self, other: &T) -> Option<Ordering> {
146 self.0.partial_cmp(other)
147 }
148 }
149
150 impl<T: Hash> Hash for Int<T> {
151 fn hash<H: Hasher>(&self, state: &mut H) {
152 self.0.hash(state);
153 }
154 }
155 impl<T: Hasher> Hasher for Int<T> {
156 #[must_use]
157 fn finish(&self) -> u64 {
158 self.0.finish()
159 }
160 fn write(&mut self, bytes: &[u8]) {
161 self.0.write(bytes);
162 }
163 }
164}