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