Expand description
§nonzero_macros
Macros for compile-time checked NonZero integers and safe NonNull pointer creation in no_std environments.
Far simpler than other crates, as it leverages the modern generic core::num::NonZero type.
Lightweight, no_std, and dependency-free.
§Macros
§nonzero!
Constructs a NonZero* type at compile-time. Panics if the value is zero.
use nonzero_macros::nonzero;
use core::num::NonZeroUsize;
const MY_VAL: NonZeroUsize = nonzero!(10);§try_nonzero!
Constructs an Option<NonZero*> type. Works at both compile-time and runtime.
Returns None if the value is zero.
use nonzero_macros::try_nonzero;
use core::num::NonZeroUsize;
const MY_VAL: Option<NonZeroUsize> = try_nonzero!(10);
const MY_ZERO: Option<NonZeroUsize> = try_nonzero!(0); // None
let x = 10;
let val = try_nonzero!(x);§nonnull_raw_mut!
Constructs a core::ptr::NonNull from a mutable reference expression. Useful for static muts.
use nonzero_macros::nonnull_raw_mut;
static mut MY_STATIC: i32 = 0;
let ptr = nonnull_raw_mut!(MY_STATIC);§License
Licensed under either of Apache License, Version 2.0 or MIT license at your option.Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
# `nonzero_macros`
A collection of lightweight, no_std, dependency-free macros for LibAFL and general Rust development.
§Macros
nonzero!: A compile-time checked way to createNonZero*types. Panics if the value is zero.try_nonzero!: A compile-time checked way to createOption<NonZero*>types. ReturnsNoneif the value is zero.nonnull_raw_mut!: A safe wrapper around&raw mutthat returns aNonNullpointer.
Macros§
- nonnull_
raw_ mut - Get a
core::ptr::NonNullto a global static mut (or similar). - nonzero
- Zero-cost way to construct
NonZero*types fromcore::numat compile-time. - try_
nonzero - Construct
Option<NonZero*>types fromcore::num.