Attribute Macro dtor

Source
#[dtor]
Expand description

Marks a function as a library/executable destructor. This uses OS-specific linker sections to call a specific function at termination time.

Multiple shutdown functions are supported, but the invocation order is not guaranteed.

§Attribute parameters

  • crate_path = ::path::to::dtor::crate: The path to the dtor crate containing the support macros. If you re-export dtor items as part of your crate, you can use this to redirect the macro’s output to the correct crate.
  • used(linker): (Advanced) Mark the function as being used in the link phase.
  • link_section = "section": The section to place the dtor’s code in.
  • anonymous: Do not give the destructor a name in the generated code (allows for multiple destructors with the same name).

#[dtor]
fn shutdown() {
  /* ... */
}