| Crates.io | dtor |
| lib.rs | dtor |
| version | 0.1.0 |
| created_at | 2024-02-27 01:44:05.755753+00 |
| updated_at | 2025-08-10 17:10:05.390487+00 |
| description | __attribute__((destructor)) for Rust |
| homepage | |
| repository | https://github.com/mmastrac/rust-ctor |
| max_upload_size | |
| id | 1154412 |
| size | 44,437 |
Module teardown functions for Rust (like __attribute__((destructor)) in C/C++)
for Linux, OSX, FreeBSD, NetBSD, Illumos, OpenBSD, DragonFlyBSD, Android, iOS,
WASM, and Windows.
Print a message at shutdown time. Note that Rust may have shut down some stdlib services at this time.
#[dtor]
unsafe fn shutdown() {
// Using println or eprintln here will panic as Rust has shut down
libc::printf("Shutting down!\n\0".as_ptr() as *const i8);
}
The #[dtor] macro effectively creates a constructor that calls libc::atexit
with the provided function, ie roughly equivalent to:
#[ctor]
fn dtor_atexit() {
libc::atexit(dtor);
}