| Crates.io | maybe_null |
| lib.rs | maybe_null |
| version | 0.2.0 |
| created_at | 2024-12-04 01:38:15.369658+00 |
| updated_at | 2024-12-04 16:21:15.990027+00 |
| description | A pointer type for handling potentially null values without accidental dereference |
| homepage | |
| repository | https://github.com/hazelwiss/maybe_null |
| max_upload_size | |
| id | 1470896 |
| size | 14,301 |
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);
}
The AtomicMaybeNull works like MaybeNull but allows for atomic access of the pointer.