SHARE
TWEET

Untitled

a guest Oct 16th, 2019 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Expands add_all!(a, b, c) to 0 + a + b + c
  2. macro_rules! add_all {
  3.     ($($x:expr),*) => {
  4.         0 $(
  5.             + $x
  6.         )*
  7.     }
  8. }
  9.  
  10. fn main() {
  11.     let x = add_all!(1, 2, 3, 4, 5, 6);
  12.     println!("{}", x);
  13. }
  14.  
  15. // Write a macro, `cool_vec`, which takes a list of expressions, and pushes them
  16. // all onto a `Vec`. The macro should expand to an *expression* that evaluates to
  17. // the vector itself. That is, the macro should expand this code:
  18. //
  19. // let x = cool_vec!(1, 2, 3);
  20. //
  21. // into
  22. //
  23. // let x = {
  24. //     let v = Vec::new();
  25. //     v.push(1);
  26. //     v.push(2);
  27. //     v.push(3);
  28. //     v
  29. // };
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