https://github.com/flier/contructor-derive
Registers a function to be called before/after main (if an executable) or when loaded/unloaded (if a dynamic library).
https://github.com/flier/contructor-derive
Last synced: over 1 year ago
JSON representation
Registers a function to be called before/after main (if an executable) or when loaded/unloaded (if a dynamic library).
- Host: GitHub
- URL: https://github.com/flier/contructor-derive
- Owner: flier
- License: apache-2.0
- Created: 2018-11-28T10:43:48.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-11-28T10:57:07.000Z (over 7 years ago)
- Last Synced: 2025-01-21T22:09:43.062Z (over 1 year ago)
- Language: Rust
- Size: 9.77 KB
- Stars: 1
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
contructor_derive [](https://travis-ci.org/flier/contructor-derive) [](https://crates.io/crates/contructor_derive) [](https://docs.rs/contructor-derive)
====
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...
```toml
[dependencies]
contructor_derive = "0.1.0"
```
## Example
```rust
#[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
* Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
* MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)