SHARE
TWEET

Untitled

a guest Oct 13th, 2019 84 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. use std::ops::Add;
  2.  
  3. macro_rules! impl_op {
  4.     (impl $trait:ident for $type:ident {
  5.         fn $fn:ident;
  6.     }) => {
  7.         impl $trait for $type {
  8.             type Output = $type;
  9.             fn $fn(self, other: $type) -> $type {
  10.                 $type((self.0).$fn(other.0))
  11.             }
  12.         }
  13.     }
  14. }
  15.  
  16. struct X(i32);
  17.  
  18. impl_op! {
  19.     impl Add for X {
  20.         fn add;
  21.     }
  22. }
  23.  
  24. fn main() {
  25.     dbg!((X(10) + X(5)).0);
  26. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top