Macro forward_ref::forward_ref_unop [−][src]
macro_rules! forward_ref_unop { (impl $imp:ident, $method:ident for $t:ty) => { ... }; }
Expand description
Extend a unary operator trait impl over refs.
Given an implementation of op T
where T is Copy
able, implements the unary
operator op &T
.
Examples
use core::ops::Neg; use forward_ref::forward_ref_unop; #[derive(Clone, Copy, Debug, PartialEq)] struct MyInt(i32); impl Neg for MyInt { type Output = Self; #[inline] fn neg(self) -> Self::Output { Self(self.0.neg()) } } forward_ref_unop!(impl Neg, neg for MyInt); // Now negation will work for references. let a = MyInt(1); assert_eq!(-a, MyInt(-1)); assert_eq!(-&a, MyInt(-1));