Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Expands add_all!(a, b, c) to 0 + a + b + c
- macro_rules! add_all {
- ($($x:expr),*) => {
- 0 $(
- + $x
- )*
- }
- }
- fn main() {
- let x = add_all!(1, 2, 3, 4, 5, 6);
- println!("{}", x);
- }
- // Write a macro, `cool_vec`, which takes a list of expressions, and pushes them
- // all onto a `Vec`. The macro should expand to an *expression* that evaluates to
- // the vector itself. That is, the macro should expand this code:
- //
- // let x = cool_vec!(1, 2, 3);
- //
- // into
- //
- // let x = {
- // let v = Vec::new();
- // v.push(1);
- // v.push(2);
- // v.push(3);
- // v
- // };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement