macros!
Mới bắt đầu với Rust chúng ta thường sử dụng rất nhiều macro như println!
.
Thực chất có 3 loại macro trong Rust.
- Custom
#[derive]
macros that specify code added with the derive attribute used on structs and enums - Attribute-like macros that define custom attributes usable on any item
- Function-like macros that look like function calls but operate on the tokens specified as their argument
Sự khác nhau giữa Macros và Functions
TODO
Macros mặc định
Standard Macros được định nghĩa bởi compiler và std.
print!, println!, eprint!, eprintln!
format!, format_args!
write!, writeln!
concat!, concat_idents!, stringify // concat_idents: nightly-only experimental API
include!, include_bytes!, include_str!
assert!, assert_eq!, assert_ne!
debug_assert!, debug_assert_eq!, debug_assert_ne!
try!, panic!, compile_error!, unreachable!, unimplemented!
file!, line!, column!, module_path!
env!, option_env!
cfg!
select!, thread_local! // select: nightly-only experimental API
vec!