A Rust library for MaybeNull pointer type.
Find a file
2024-12-04 16:21:05 +00:00
src using Option<NonNull> rather than a raw pointer 2024-12-04 16:21:05 +00:00
.gitignore initial commit 2024-12-04 01:18:24 +00:00
Cargo.lock using Option<NonNull> rather than a raw pointer 2024-12-04 16:21:05 +00:00
Cargo.toml using Option<NonNull> rather than a raw pointer 2024-12-04 16:21:05 +00:00
LICENSE Create LICENSE 2024-12-04 01:34:54 +00:00
README.md updated readme 2024-12-04 01:39:08 +00:00

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.