diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
commit | 698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch) | |
tree | 173a775858bd501c378080a10dca74132f05bc50 /vendor/ctor/src/example.rs | |
parent | Initial commit. (diff) | |
download | rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip |
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/ctor/src/example.rs')
-rw-r--r-- | vendor/ctor/src/example.rs | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/vendor/ctor/src/example.rs b/vendor/ctor/src/example.rs new file mode 100644 index 000000000..73babb12b --- /dev/null +++ b/vendor/ctor/src/example.rs @@ -0,0 +1,54 @@ +extern crate ctor; +extern crate libc_print; + +use ctor::*; +use libc_print::*; +use std::collections::HashMap; + +#[ctor] +/// This is an immutable static, evaluated at init time +static STATIC_CTOR: HashMap<u32, &'static str> = { + let mut m = HashMap::new(); + m.insert(0, "foo"); + m.insert(1, "bar"); + m.insert(2, "baz"); + libc_eprintln!("STATIC_CTOR"); + m +}; + +#[ctor] +fn ctor() { + libc_eprintln!("ctor"); +} + +#[ctor] +unsafe fn ctor_unsafe() { + libc_eprintln!("ctor_unsafe"); +} + +#[dtor] +fn dtor() { + libc_eprintln!("dtor"); +} + +#[dtor] +unsafe fn dtor_unsafe() { + libc_eprintln!("dtor_unsafe"); +} + +mod module { + use ctor::*; + use libc_print::*; + + #[ctor] + pub static STATIC_CTOR: u8 = { + libc_eprintln!("module::STATIC_CTOR"); + 42 + }; +} + +pub fn main() { + libc_eprintln!("main!"); + libc_eprintln!("STATIC_CTOR = {:?}", *STATIC_CTOR); + libc_eprintln!("module::STATIC_CTOR = {:?}", *module::STATIC_CTOR); +} |