scsys_core/state/impls/
impl_wrapper_ops.rs1use crate::state::{RawState, State};
6use num_traits::{Num, One, Zero};
7
8impl<Q> One for State<Q>
9where
10 Q: RawState + One,
11{
12 fn one() -> Self {
13 State(Q::one())
14 }
15}
16
17impl<Q> Zero for State<Q>
18where
19 Q: RawState + Zero,
20{
21 fn zero() -> Self {
22 State(Q::zero())
23 }
24
25 fn is_zero(&self) -> bool {
26 self.get().is_zero()
27 }
28}
29
30impl<Q> Num for State<Q>
31where
32 Q: RawState + Num,
33{
34 type FromStrRadixErr = Q::FromStrRadixErr;
35
36 fn from_str_radix(s: &str, radix: u32) -> Result<Self, Self::FromStrRadixErr> {
37 Q::from_str_radix(s, radix).map(State)
38 }
39}
40
41impl_wrapper_binary! {
42 State::<[
43 Add.add,
44 Sub.sub,
45 Mul.mul,
46 Div.div,
47 Rem.rem,
48 BitAnd.bitand,
49 BitOr.bitor,
50 BitXor.bitxor,
51 Shl.shl,
52 Shr.shr
53 ]>
54}
55
56impl_wrapper_unary! {
57 State::<[
58 Neg.neg,
59 Not.not
60 ]>
61}