#constructor #init #term #destructor

macro contructor-derive

Registers a function to be called before/after main (if an executable) or when loaded/unloaded (if a dynamic library)

2 releases

0.1.1 Nov 28, 2018
0.1.0 Nov 28, 2018

#90 in FFI

Download history 26/week @ 2018-11-27 17/week @ 2018-12-04 2/week @ 2018-12-11 14/week @ 2018-12-18 1/week @ 2018-12-25 2/week @ 2019-01-01 7/week @ 2019-01-08 5/week @ 2019-01-15 1/week @ 2019-01-22

3 downloads per month

MIT/Apache

7KB
103 lines

contructor_derive Build Status Latest Version Rust Documentation

Registers a function to be called before/after main (if an executable) or when loaded/unloaded (if a dynamic library).

Notes

Use this library is unsafe unless you want to interop directly with a FFI library.

Please consider to use the lazy-static crate instead of it.

Usage

Add the following dependency to your Cargo manifest...

[dependencies]
contructor_derive = "0.1.0"

Example

#[macro_use]
extern crate contructor_derive;

pub static mut RAN: bool = false;

#[constructor]
extern "C" fn set_ran() {
    unsafe { RAN = true }
}

#[destructor]
extern "C" fn reset_ran() {
    unsafe { RAN = false }
}

fn main() {
    assert!(unsafe { RAN });
}

License

Licensed under either of

Dependencies

~1MB
~18K SLoC