Attribute Macro static_init::destructor[][src]

#[destructor]

Attribute for functions run at program termination (after main)

#[destructor]
unsafe extern "C" fn droper () {
// run after main return
}

The execution order of destructors is unspecified. Nevertheless on ELF plateform (linux,any unixes but mac) and windows plateform a priority can be specified using the syntax destructor(<num>) where <num> is a number included in the range [0 ; 216-1].

Destructors without priority are run first (in unspecified order), then destructors with priority 0 are run, then destructors with priority number 1,... finaly destructors with priority 65535 are run.

Safety

Destructor functions must be unsafe. Any access to statics dropped with an equal or lower priority will cause undefined behavior.

#[destructor(1)]
unsafe extern "C" fn first () {
// run after main return
}

#[destructor(0)]
unsafe extern "C" fn then () {
// run after main return
}

Destructor signature

Destructor function should have type unsafe extern "C" fn() -> ().