[][src]Attribute Macro static_init::destructor

#[destructor]

Attribute for functions run at program termination (after main)

#[destructor]
unsafe fn droper () {
// run before main start
}

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 65535 are run, the destructors with priority number 65534,... finaly destructors with priority 0 are run.

Safety

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

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

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