Goal of the crate is to allow using safe uninitialized values. Many similar features
are already in the Rust
core library as
MaybeUninit and functions in standard types.
For example, currently (stable Rust 1.41) as nightly feature of a compiler one can see
Box::new_uninit() which allows to allocate memory with
MaybeUninit value. Basically,
crate allows creating not 'Maybe' but surely uninitialized values that are safe to use
despite they are uninitialized. Because of this they are directly presented as a value without
any wrappers like
MaybeUninit and no requirement for unsafe block.
Main trait is
SafeUninit which indicated the type which can be safely used without
initialization and without further wrappers. It is implemented for all primitive integer
types and their atomic variants, for fixed-size arrays of
SafeUninit of up to 32 values
(but there is a way of creating bigger arrays),
for tuples of
SafeUninit objects of up to 12 elements and for unit type
This crate is
no-std but also implements traits for
alloc types where appropriate.
Pointers are safe to be uninitialized. Even if the values they are pointing to are not
Firstly, pointers are internally a plain number of type usize which is safe.
Secondly, dereferencing pointers is an unsafe operation anyway and even if pointer
with uninitialized address gets dereferenced this will be done under unsafe block
and programmer will be fully responsible for any consequences of using it.
These types are not safe to use uninitialized and one should use
Boolean valid values are
false. If boolean is internally
(as an example) stored as a byte which holds values different from 0 or 1 then this will
lead to unexpected behaviour and thus this type is not safe to use uninitialized. One
Such types as
NonZeroI32 are unsafe to leave uninitialized. These types are assumed to
never be zero. Uninitialized value though can occur zero and this will cause undefined
Here are listed types that can be unsafe and should be further investigated:
To be used with
Marks the type that is safe to use uninitialized. For example, if you create uninitialized
Shorthand for types that are