Debian Codegraph @

debian/rust-vendor/ctor/examples/ctor-dynamic.rs

raw
1 //! Demonstrate dynamic `#[ctor]`s.
2 #![allow(clippy::incompatible_msrv)]
3
4 use ctor::ctor;
5 use libc_print::*;
6
7 #[ctor(unsafe)]
8 static STATIC_CTORS: &[fn()] = const {
9 fn bind_const<const N: usize>() {
10 libc_eprintln!("bind_const: {}", N);
11 }
12 [bind_const::<1>, bind_const::<2>, bind_const::<3>].as_slice()
13 };
14
15 #[ctor(unsafe)]
16 static OPTIONAL_CTOR: &[fn()] = const {
17 #[allow(unexpected_cfgs)]
18 if cfg!(enable_ctor) {
19 fn ctor() {
20 libc_eprintln!("ctor");
21 }
22 [ctor as fn()].as_slice()
23 } else {
24 &[]
25 }
26 };
27
28 fn main() {}