startup: Run Rust code "before main"

Docs Latest Version

Tiny (no-dependency, no proc macro) way to run some code before main (or when your dynamic library is loaded in the case of code loaded via dlopen). This is similar to the GNU C extension __attribute__((constructor)), or the behavior of static constructors from C++.

Usage

rust startup::on_startup! { // Note: not all of the rust stdlib may be supported before main. println!("I'm running before main"); } fn main() { println!("I'm inside main"); }

Prints:

text I'm running before main. I'm inside main.

Comparison with ctor

This crate is the moral equivalent to the ctor crate, although the API is completely different. The main reasons for it's existence are: