#constructor #init #main #static #ctor

yanked startup

Tiny (no dependency, no proc macro) way to run some code before main

3 unstable releases

0.1.1 Feb 2, 2021
0.1.0 Feb 2, 2021
0.0.1 Feb 2, 2021

#12 in #main

Download history 25/week @ 2022-12-03 47/week @ 2022-12-10 10/week @ 2022-12-17 9/week @ 2022-12-24 5/week @ 2022-12-31 25/week @ 2023-01-07 32/week @ 2023-01-14 33/week @ 2023-01-21 20/week @ 2023-01-28 81/week @ 2023-02-04 22/week @ 2023-02-11 28/week @ 2023-02-18 16/week @ 2023-02-25 13/week @ 2023-03-04 12/week @ 2023-03-11 11/week @ 2023-03-18

59 downloads per month

Apache-2.0 OR MIT OR Zlib

85 lines

startup: Run Rust code "before main"

Build Status Docs Latest Version Minimum Rust Version

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");


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:

  • Much faster to compile — no proc macros / syn / quote.
  • More obviously safe. No support for #[ctor] on statics, no #[dtor] equivalent, and avoids a number of issues I filed with ctor in the past...
  • Handle untested unix platforms by assuming they support at least the .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.

No runtime deps