Skip to main content

no_copy/
ops_impl.rs

1use super::NoCopy;
2use core::ops::*;
3
4macro_rules! impl_ops {
5    ($Add:ident $add:ident $AddAssign:ident $add_assign:ident) => {
6        impl<T: $Add<U>, U> $Add<U> for NoCopy<T> {
7            type Output = T::Output;
8
9            #[track_caller]
10            fn $add(self, rhs: U) -> Self::Output {
11                self.0.$add(rhs)
12            }
13        }
14
15        impl<T: $AddAssign<U>, U> $AddAssign<U> for NoCopy<T> {
16            #[track_caller]
17            fn $add_assign(&mut self, rhs: U) {
18                self.0.$add_assign(rhs);
19            }
20        }
21    };
22}
23
24impl_ops!(Add       add     AddAssign       add_assign);
25impl_ops!(Sub       sub     SubAssign       sub_assign);
26impl_ops!(Mul       mul     MulAssign       mul_assign);
27impl_ops!(Div       div     DivAssign       div_assign);
28impl_ops!(Rem       rem     RemAssign       rem_assign);
29impl_ops!(Shl       shl     ShlAssign       shl_assign);
30impl_ops!(Shr       shr     ShrAssign       shr_assign);
31impl_ops!(BitAnd    bitand  BitAndAssign    bitand_assign);
32impl_ops!(BitOr     bitor   BitOrAssign     bitor_assign);
33impl_ops!(BitXor    bitxor  BitXorAssign    bitxor_assign);
34
35impl<T: Index<U>, U> Index<U> for NoCopy<T> {
36    type Output = T::Output;
37
38    #[track_caller]
39    fn index(&self, index: U) -> &Self::Output {
40        self.0.index(index)
41    }
42}
43
44impl<T: IndexMut<U>, U> IndexMut<U> for NoCopy<T> {
45    #[track_caller]
46    fn index_mut(&mut self, index: U) -> &mut Self::Output {
47        self.0.index_mut(index)
48    }
49}
50
51impl<T: Neg> Neg for NoCopy<T> {
52    type Output = T::Output;
53
54    #[track_caller]
55    fn neg(self) -> Self::Output {
56        self.0.neg()
57    }
58}
59
60impl<T: Not> Not for NoCopy<T> {
61    type Output = T::Output;
62
63    #[track_caller]
64    fn not(self) -> Self::Output {
65        self.0.not()
66    }
67}
68
69impl<T: RangeBounds<R>, R> RangeBounds<R> for NoCopy<T> {
70    #[track_caller]
71    fn contains<U>(&self, item: &U) -> bool
72    where R: PartialOrd<U>,
73          U: ?Sized + PartialOrd<R>,
74    {
75        self.0.contains(item)
76    }
77
78    #[track_caller]
79    fn end_bound(&self) -> Bound<&R> {
80        self.0.end_bound()
81    }
82
83    #[track_caller]
84    fn start_bound(&self) -> Bound<&R> {
85        self.0.start_bound()
86    }
87}