Function serde::lib::core::ptr::invalid

const: 1.61.0 · source ·
pub const fn invalid<T>(addr: usize) -> *const T
🔬This is a nightly-only experimental API. (strict_provenance)
Expand description

Creates an invalid pointer with the given address.

This is different from addr as *const T, which creates a pointer that picks up a previously exposed provenance. See from_exposed_addr for more details on that operation.

The module’s top-level documentation discusses the precise meaning of an “invalid” pointer but essentially this expresses that the pointer is not associated with any actual allocation and is little more than a usize address in disguise.

This pointer will have no provenance associated with it and is therefore UB to read/write/offset. This mostly exists to facilitate things like ptr::null and NonNull::dangling which make invalid pointers.

(Standard “Zero-Sized-Types get to cheat and lie” caveats apply, although it may be desirable to give them their own API just to make that 100% clear.)

This API and its claimed semantics are part of the Strict Provenance experiment, see the module documentation for details.