dtor/
lib.rs

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