Crates.io | maybe_null |
lib.rs | maybe_null |
version | |
source | src |
created_at | 2024-12-04 01:38:15.369658 |
updated_at | 2024-12-04 16:21:15.990027 |
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 |
Cargo.toml error: | TOML parse error at line 17, column 1 | 17 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
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.