rstm_state/impls/
impl_state_ops.rs

1/*
2    Appellation: impl_ops <state>
3    Contrib: FL03 <jo3mccain@icloud.com>
4*/
5use crate::state::State;
6use crate::traits::RawState;
7use num_traits::{Num, One, Zero};
8
9impl<Q> Num for State<Q>
10where
11    Q: RawState + Num,
12{
13    type FromStrRadixErr = Q::FromStrRadixErr;
14
15    fn from_str_radix(str: &str, radix: u32) -> Result<Self, Self::FromStrRadixErr> {
16        Q::from_str_radix(str, radix).map(State)
17    }
18}
19
20impl<Q> One for State<Q>
21where
22    Q: RawState + PartialEq + One,
23{
24    fn one() -> Self {
25        State(Q::one())
26    }
27
28    fn is_one(&self) -> bool {
29        self.0.is_one()
30    }
31}
32
33impl<Q> Zero for State<Q>
34where
35    Q: RawState + Zero,
36{
37    fn zero() -> Self {
38        State(Q::zero())
39    }
40
41    fn is_zero(&self) -> bool {
42        self.0.is_zero()
43    }
44}
45
46contained::impl_wrapper_unary! {
47    State {
48        Neg.neg,
49        Not.not,
50    }
51}
52
53contained::binary_wrapper! {
54    impl State {
55        Add.add,
56        Sub.sub,
57        Mul.mul,
58        Div.div,
59        Rem.rem,
60        BitAnd.bitand,
61        BitOr.bitor,
62        BitXor.bitxor,
63        Shl.shl,
64        Shr.shr
65    }
66}