macro_rules! ctor {
(#[ctor $(($($meta:tt)*))?] $(#[$imeta:meta])* pub ( $($extra:tt)* ) $($item:tt)*) => { ... };
(#[ctor $(($($meta:tt)*))?] $(#[$imeta:meta])* pub $($item:tt)*) => { ... };
(#[ctor $(($($meta:tt)*))?] $(#[$imeta:meta])* fn $($item:tt)*) => { ... };
(#[ctor $(($($meta:tt)*))?] $(#[$imeta:meta])* unsafe $($item:tt)*) => { ... };
(#[ctor $(($($meta:tt)*))?] $(#[$imeta:meta])* static $($item:tt)*) => { ... };
(#[$imeta:meta] $($rest:tt)*) => { ... };
(__reorder__($(#[$imeta:meta],)*), #[ctor $(($($meta:tt)*))?] $($rest:tt)*) => { ... };
(__reorder__($(#[$imeta:meta],)*), #[$imeta2:meta] $($rest:tt)*) => { ... };
}
Expand description
Parse a #[ctor]
-annotated item as if it were a proc-macro.
This macro supports both the fn
and static
forms of the #[ctor]
attribute, including attribute parameters.
ctor! {
/// Create a ctor with a link section
#[ctor(link_section = ".ctors")]
unsafe fn foo() { /* ... */ }
}
ctor! {
#[ctor]
static FOO: std::collections::HashMap<u32, String> = unsafe {
let mut m = std::collections::HashMap::new();
m.insert(1, "foo".to_string());
m
};
}