dtor/lib.rs
1#![doc = include_str!("../README.md")]
2
3mod macros;
4
5#[doc(hidden)]
6#[allow(unused)]
7pub use macros::__support;
8
9/// Marks a function as a library/executable destructor. This uses OS-specific
10/// linker sections to call a specific function at termination time.
11///
12/// Multiple shutdown functions are supported, but the invocation order is not
13/// guaranteed.
14///
15/// # Attribute parameters
16///
17/// - `crate_path = ::path::to::dtor::crate`: The path to the `dtor` crate
18/// containing the support macros. If you re-export `dtor` items as part of
19/// your crate, you can use this to redirect the macro's output to the
20/// correct crate.
21/// - `used(linker)`: (Advanced) Mark the function as being used in the link
22/// phase.
23/// - `link_section = "section"`: The section to place the dtor's code in.
24/// - `anonymous`: Do not give the destructor a name in the generated code
25/// (allows for multiple destructors with the same name).
26///
27/// ```rust
28/// # #![cfg_attr(feature="used_linker", feature(used_with_arg))]
29/// # extern crate dtor;
30/// # use dtor::dtor;
31/// # fn main() {}
32///
33/// #[dtor]
34/// fn shutdown() {
35/// /* ... */
36/// }
37/// ```
38#[doc(inline)]
39#[cfg(feature = "proc_macro")]
40pub use dtor_proc_macro::dtor;
41
42#[doc(hidden)]
43#[cfg(feature = "proc_macro")]
44pub use dtor_proc_macro::__dtor_from_ctor;
45
46/// Declarative forms of the `#[dtor]` macro.
47///
48/// The declarative forms wrap and parse a proc_macro-like syntax like so, and
49/// are identical in expansion to the undecorated procedural macros. The
50/// declarative forms support the same attribute parameters as the procedural
51/// macros.
52///
53/// ```rust
54/// # #[cfg(any())] mod test { use dtor::*; use libc_print::*;
55/// dtor::declarative::dtor! {
56/// #[dtor]
57/// fn foo() {
58/// libc_println!("Goodbye, world!");
59/// }
60/// }
61/// # }
62///
63/// // ... the above is identical to:
64///
65/// # #[cfg(any())] mod test_2 { use dtor::*; use libc_print::*;
66/// #[dtor]
67/// fn foo() {
68/// libc_println!("Goodbye, world!");
69/// }
70/// # }
71/// ```
72pub mod declarative {
73 #[doc(inline)]
74 pub use crate::__support::dtor_parse as dtor;
75}