4 releases
0.2.0 | Dec 4, 2024 |
---|---|
0.1.2 | Dec 4, 2024 |
0.1.1 | Dec 4, 2024 |
0.1.0 | Dec 4, 2024 |
#1192 in Rust patterns
308 downloads per month
14KB
281 lines
MaybeNull
The MaybeNull
type is used for hinting that a pointer may be null, and still prevent accidental null pointer dereference.
use maybe_null::MaybeNull;
let ptr = MaybeNull::<u32>::null();
let Some(ptr) = ptr.get() {
// We know the pointer is non-null here.
// Whoops! this will never happen because our `ptr` was initialized as null!
ptr.write(0);
}
AtomicMaybeNull
The AtomicMaybeNull
works like MaybeNull
but allows for atomic access of the pointer.