Crates.io | contructor-derive |
lib.rs | contructor-derive |
version | 0.1.1 |
source | src |
created_at | 2018-11-28 10:48:50.85452 |
updated_at | 2018-11-28 10:51:49.717745 |
description | Registers a function to be called before/after main (if an executable) or when loaded/unloaded (if a dynamic library). |
homepage | |
repository | https://github.com/flier/contructor-derive |
max_upload_size | |
id | 99052 |
size | 19,685 |
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.
Add the following dependency to your Cargo manifest...
[dependencies]
contructor_derive = "0.1.0"
#[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 });
}
Licensed under either of