rstmt_core/octave/
impl_octave_ext.rs1use super::{Octave, RawOctave};
7use num_traits::{Num, One, Zero};
8
9contained::fmt_wrapper! {
10 impl Octave<T> {
11 Binary,
12 Debug,
13 Display,
14 LowerExp,
15 LowerHex,
16 Octal,
17 Pointer,
18 UpperExp,
19 UpperHex
20 }
21
22}
23
24contained::binary_wrapper! {
25 impl Octave {
26 Add.add,
27 Div.div,
28 Mul.mul,
29 Rem.rem,
30 Sub.sub,
31 BitAnd.bitand,
32 BitOr.bitor,
33 BitXor.bitxor,
34 Shl.shl,
35 Shr.shr
36 }
37}
38
39contained::unary_wrapper! {
40 impl Octave {
41 Neg.neg,
42 Not.not,
43 }
44}
45
46impl<T> One for Octave<T>
47where
48 T: One,
49{
50 fn one() -> Self {
51 Octave(T::one())
52 }
53}
54
55impl<T> Zero for Octave<T>
56where
57 T: Zero,
58{
59 fn zero() -> Self {
60 Octave(T::zero())
61 }
62
63 fn is_zero(&self) -> bool {
64 self.0.is_zero()
65 }
66}
67
68impl<T> Num for Octave<T>
69where
70 T: Num,
71{
72 type FromStrRadixErr = T::FromStrRadixErr;
73
74 fn from_str_radix(str: &str, radix: u32) -> Result<Self, Self::FromStrRadixErr> {
75 T::from_str_radix(str, radix).map(Octave)
76 }
77}
78
79impl<T> AsRef<T> for Octave<T> {
80 fn as_ref(&self) -> &T {
81 &self.0
82 }
83}
84
85impl<T> AsMut<T> for Octave<T> {
86 fn as_mut(&mut self) -> &mut T {
87 &mut self.0
88 }
89}
90
91impl<T> core::borrow::Borrow<T> for Octave<T> {
92 fn borrow(&self) -> &T {
93 &self.0
94 }
95}
96
97impl<T> core::borrow::BorrowMut<T> for Octave<T> {
98 fn borrow_mut(&mut self) -> &mut T {
99 &mut self.0
100 }
101}
102
103impl<T> core::ops::Deref for Octave<T> {
104 type Target = T;
105
106 fn deref(&self) -> &Self::Target {
107 &self.0
108 }
109}
110
111impl<T> core::ops::DerefMut for Octave<T> {
112 fn deref_mut(&mut self) -> &mut Self::Target {
113 &mut self.0
114 }
115}
116
117impl<T> From<T> for Octave<T>
118where
119 T: RawOctave,
120{
121 fn from(index: T) -> Self {
122 Octave(index)
123 }
124}
125
126impl<T> PartialEq<T> for Octave<T>
127where
128 T: PartialEq,
129{
130 fn eq(&self, other: &T) -> bool {
131 &self.0 == other
132 }
133}
134
135impl<'a, T> PartialEq<&'a T> for Octave<T>
136where
137 T: PartialEq,
138{
139 fn eq(&self, other: &&'a T) -> bool {
140 &self.0 == *other
141 }
142}
143
144impl<'a, T> PartialEq<&'a mut T> for Octave<T>
145where
146 T: PartialEq,
147{
148 fn eq(&self, other: &&'a mut T) -> bool {
149 &self.0 == *other
150 }
151}
152
153impl<T> PartialOrd<T> for Octave<T>
154where
155 T: PartialOrd,
156{
157 fn partial_cmp(&self, other: &T) -> Option<core::cmp::Ordering> {
158 self.0.partial_cmp(other)
159 }
160}
161
162impl<'a, T> PartialOrd<&'a T> for Octave<T>
163where
164 T: PartialOrd,
165{
166 fn partial_cmp(&self, other: &&'a T) -> Option<core::cmp::Ordering> {
167 self.0.partial_cmp(*other)
168 }
169}
170
171impl<'a, T> PartialOrd<&'a mut T> for Octave<T>
172where
173 T: PartialOrd,
174{
175 fn partial_cmp(&self, other: &&'a mut T) -> Option<core::cmp::Ordering> {
176 self.0.partial_cmp(*other)
177 }
178}