rstmt_core/pitch/impls/
impl_pitch_ext.rs1use crate::pitch::{Pitch, RawPitch};
7use num_traits::{Num, One, Zero};
8
9contained::fmt_wrapper! {
10 impl Pitch<T> {
11 Binary,
12 Debug,
13 Display,
14 LowerExp,
15 LowerHex,
16 Octal,
17 UpperExp,
18 UpperHex
19 }
20}
21
22contained::binary_wrapper! {
23 impl Pitch {
24 Add.add,
25 Div.div,
26 Mul.mul,
27 Rem.rem,
28 Sub.sub,
29 BitAnd.bitand,
30 BitOr.bitor,
31 BitXor.bitxor,
32 Shl.shl,
33 Shr.shr
34 }
35}
36
37contained::unary_wrapper! {
38 impl Pitch {
39 Neg.neg,
40 Not.not
41 }
42}
43
44impl<T> AsRef<T> for Pitch<T>
45where
46 T: RawPitch,
47{
48 fn as_ref(&self) -> &T {
49 &self.0
50 }
51}
52
53impl<T> AsMut<T> for Pitch<T> {
54 fn as_mut(&mut self) -> &mut T {
55 &mut self.0
56 }
57}
58
59impl<T> core::borrow::Borrow<T> for Pitch<T> {
60 fn borrow(&self) -> &T {
61 &self.0
62 }
63}
64
65impl<T> core::borrow::BorrowMut<T> for Pitch<T> {
66 fn borrow_mut(&mut self) -> &mut T {
67 &mut self.0
68 }
69}
70
71impl<T> core::ops::Deref for Pitch<T> {
72 type Target = T;
73
74 fn deref(&self) -> &Self::Target {
75 &self.0
76 }
77}
78
79impl<T> core::ops::DerefMut for Pitch<T> {
80 fn deref_mut(&mut self) -> &mut Self::Target {
81 &mut self.0
82 }
83}
84
85impl<T> One for Pitch<T>
86where
87 T: One,
88{
89 fn one() -> Self {
90 Pitch(T::one())
91 }
92}
93
94impl<T> Zero for Pitch<T>
95where
96 T: Zero,
97{
98 fn zero() -> Self {
99 Pitch(T::zero())
100 }
101
102 fn is_zero(&self) -> bool {
103 self.0.is_zero()
104 }
105}
106
107impl<T, E> Num for Pitch<T>
108where
109 T: Num<FromStrRadixErr = E> + RawPitch,
110{
111 type FromStrRadixErr = T::FromStrRadixErr;
112
113 fn from_str_radix(str: &str, radix: u32) -> Result<Self, Self::FromStrRadixErr> {
114 T::from_str_radix(str, radix).map(Pitch::new)
115 }
116}
117
118impl<T> PartialEq<T> for Pitch<T>
119where
120 T: PartialEq,
121{
122 fn eq(&self, other: &T) -> bool {
123 self.0 == *other
124 }
125}
126
127impl<T> PartialOrd<T> for Pitch<T>
128where
129 T: PartialOrd,
130{
131 fn partial_cmp(&self, other: &T) -> Option<core::cmp::Ordering> {
132 self.0.partial_cmp(other)
133 }
134}