| Crates.io | unsafe-tools-canary |
| lib.rs | unsafe-tools-canary |
| version | 0.1.2 |
| created_at | 2025-11-06 15:21:39.396914+00 |
| updated_at | 2025-11-12 10:48:54.30441+00 |
| description | Runtime initialization checking for Rust types |
| homepage | |
| repository | |
| max_upload_size | |
| id | 1919797 |
| size | 4,822 |
canarycanary wraps your types and checks for uninitialized memory. There is no reason to use this type in safe Rust,
but unsafe Rust or Rust that interacts with other languages over FFI may find this useful to find problematic behaviour.
Just wrap the type in question in Canary and it will automatically check for correct initialization on each Deref or DerefMut (when debug assertions are enabled).
use unsafe_tools_canary::Canary;
const CANARY: u64 = u64::from_le_bytes(*b"testmagc");
let mut my_val = Canary::<_, CANARY>::new(String::new());
assert_eq!(*my_val, "");
my_val.push_str("foo");
assert_eq!(*my_val, "foo");
When you attempt to access an incorrectly uninitialized type, it will panic:
use unsafe_tools_canary::Canary;
use std::mem::MaybeUninit;
const CANARY: u64 = u64::from_le_bytes(*b"testmagc");
let b: Canary<u64, CANARY> = unsafe { MaybeUninit::uninit().assume_init() };
// THIS WILL PANIC!
assert_eq!(*b, 42);