ip/concrete/addr/
ops.rs

1use core::ops::{Add, BitAnd, BitAndAssign, BitOr, BitXor};
2
3use num_traits::CheckedAdd;
4
5use super::{
6    super::{mask_types::Type, Mask},
7    Address,
8};
9use crate::traits::Afi;
10
11impl<A: Afi, T: Type> BitAnd<Mask<T, A>> for Address<A> {
12    type Output = Self;
13
14    fn bitand(self, mask: Mask<T, A>) -> Self::Output {
15        Self::new(self.into_primitive().bitand(mask.into_primitive()))
16    }
17}
18
19impl<A: Afi, T> BitAndAssign<T> for Address<A>
20where
21    Self: BitAnd<T, Output = Self>,
22{
23    fn bitand_assign(&mut self, rhs: T) {
24        *self = self.bitand(rhs);
25    }
26}
27
28impl<A: Afi, T: Type> BitOr<Mask<T, A>> for Address<A> {
29    type Output = Self;
30
31    fn bitor(self, mask: Mask<T, A>) -> Self::Output {
32        Self::new(self.into_primitive().bitor(mask.into_primitive()))
33    }
34}
35
36impl<A: Afi, T: Type> Add<Mask<T, A>> for Address<A> {
37    type Output = Option<Self>;
38
39    fn add(self, mask: Mask<T, A>) -> Self::Output {
40        self.into_primitive()
41            .checked_add(&mask.into_primitive())
42            .map(Self::new)
43    }
44}
45
46impl<A: Afi> BitXor<Self> for Address<A> {
47    type Output = A::Primitive;
48
49    fn bitxor(self, rhs: Self) -> Self::Output {
50        self.into_primitive() ^ rhs.into_primitive()
51    }
52}