How can I statically register structures at compile time?

后端 未结 3 1455
后悔当初
后悔当初 2020-12-02 03:06

I\'m looking for the right method to statically register structures at compile time.

The origin of this requirement is to have a bunch of applets with dedic

3条回答
  •  没有蜡笔的小新
    2020-12-02 03:39

    This is not a direct answer to your question but just FYI... For ELF binaries, I could achieve something similar to GCC's __attribute__((constructor)) with

    fn init() { ... }
    #[link_section = ".init_array"]
    static INIT: fn() = init;
    

    This is obviously a deviation from Rust's design philosophies. (Portability and what @DK calls "no code before main" principle.)

    INIT can also be an Rust array. You might need to pay more attention to alignments.

提交回复
热议问题