Advertisement
Guest User

Untitled

a guest
Oct 13th, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement