Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::ops::Add;
- macro_rules! impl_op {
- (impl $trait:ident for $type:ident {
- fn $fn:ident;
- }) => {
- impl $trait for $type {
- type Output = $type;
- fn $fn(self, other: $type) -> $type {
- $type((self.0).$fn(other.0))
- }
- }
- }
- }
- struct X(i32);
- impl_op! {
- impl Add for X {
- fn add;
- }
- }
- fn main() {
- dbg!((X(10) + X(5)).0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement