macro

Visibility and lifetime fragments

A visibility capture may be empty. A lifetime capture lets generated signatures reuse a caller-specified lifetime name. Expected stdout (not executed): 'note\n' Common mistake: A lifetime annotation does not keep a referenced value alive.

Formal Syntax & Structure

rust syntaxrust
$v:vis / $lt:lifetime

Working Example

Example Snippetrust
macro_rules! view {    ($v:vis, $lt:lifetime) => { $v struct View<$lt> { text: &$lt str } };}view!(pub(crate), 'a);fn main() { let v = View { text: "note" }; println!("{}", v.text); }
Rust Reference