Skip to content
On this page

宏1:exercises/macros/macros1.rs

题目

rust
// macros1.rs
//
// Execute `rustlings hint macros1` or use the `hint` watch subcommand for a
// hint.

// I AM NOT DONE

macro_rules! my_macro {
    () => {
        println!("Check out my macro!");
    };
}

fn main() {
    my_macro();
}

题目解析

声明宏在定义的时候不需要带!号,但是在调用的时候需要带!号。所以调用的时候与println类似,后面加!

rust
// macros1.rs
//
// Execute `rustlings hint macros1` or use the `hint` watch subcommand for a
// hint.

// I AM NOT DONE

macro_rules! my_macro {
    () => {
        println!("Check out my macro!");
    };
}

fn main() {
    my_macro(); 
    my_macro!(); 
}

参考资料

Powered by VitePress