Crates.io | startup |
lib.rs | startup |
version | 0.1.1 |
source | src |
created_at | 2021-02-02 00:59:49.440162 |
updated_at | 2021-02-02 19:51:07.106081 |
description | Tiny (no dependency, no proc macro) way to run some code before main. |
homepage | https://github.com/thomcc/startup |
repository | https://github.com/thomcc/startup |
max_upload_size | |
id | 349452 |
size | 24,078 |
startup
: Run Rust code "before main"Tiny (no dependency, no proc macro) way to run some code before main. This is similar to the GNU C extension __attribute__((constructor))
, or the behavior of static constructors from C++.
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:
I'm running before main.
I'm inside main.
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:
#[ctor]
on statics, no #[dtor]
equivalent, and avoids a number of issues I filed with ctor
in the past....ctors
section. This is in line with what clang seems to do when compiling C++ static constructors. This means we should expect to have better platform support.