21 lines
423 B
Rust
21 lines
423 B
Rust
|
|
||
|
|
||
|
pub trait HelloMacro {
|
||
|
fn hello_macro();
|
||
|
}
|
||
|
|
||
|
/// Simplified version of the vec! macro
|
||
|
/// This is an example of a declarative macro
|
||
|
#[macro_export] // This makes the macro usable
|
||
|
macro_rules! vec {
|
||
|
( $( $x:expr ),* ) => { // This matches the argument list
|
||
|
{
|
||
|
let mut temp_vec = Vec::new();
|
||
|
$(
|
||
|
temp_vec.push($x);
|
||
|
)*
|
||
|
temp_vec
|
||
|
}
|
||
|
};
|
||
|
}
|