pub enum MangledOption<T> {
Some(MangledBoxArbitrary<T>),
None,
}Expand description
MangledOption is a variant of Option that is mangled with a random key.
It guarantees that value is initialized whenever Some variant is used.
Variants§
Some(MangledBoxArbitrary<T>)
None
Implementations§
Source§impl<T> MangledOption<T>
impl<T> MangledOption<T>
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new MangledOption with the None variant.
Sourcepub fn filled_with_unmasked_value(value: T) -> Self
pub fn filled_with_unmasked_value(value: T) -> Self
Creates a new MangledOption with the Some variant.
Please note that often you don’t want to have an unmasked T value in the first place.
You can construct it in-place using Self::insert_by_ptr.
Sourcepub fn take(&mut self) -> MangledOption<T>
pub fn take(&mut self) -> MangledOption<T>
Takes the value out of the option, leaving a None in its place.
Sourcepub fn insert_unmasked_value(&mut self, value: T)
pub fn insert_unmasked_value(&mut self, value: T)
Replaces the value in the option, leaving a Some variant in its place.
The old value is dropped if it was present.
Please note that often you don’t want to have an unmasked T value in the first place.
You can construct it in-place using Self::insert_by_ptr.
Sourcepub fn insert_by_ptr(&mut self, f: impl FnOnce(NonNull<T>))
pub fn insert_by_ptr(&mut self, f: impl FnOnce(NonNull<T>))
Replaces the value in the option, leaving a Some variant in its place.
The old value is dropped if it was present, after construction of the new one.
The pointer passed to the “constructor” is pointing into an uninitialized memory, allocation
suitable for T both in size and alignment.
Sourcepub fn map_mut_or_else<F, G, R>(&mut self, default: G, f: F) -> R
pub fn map_mut_or_else<F, G, R>(&mut self, default: G, f: F) -> R
Unmangles the contents and invokes the provided closure on it. Invokes a default
closure if the option is None instead.
An immutable version is not available because it would still need to make a mutation, to read the data, and it is not possible to do concurrently.
Please check the compiled code to determine if your function makes a spurious copy which could be a security issue.
Sourcepub fn map_mut<F, R>(&mut self, f: F) -> Option<R>
pub fn map_mut<F, R>(&mut self, f: F) -> Option<R>
Unmangles the contents and invokes the provided closure on it.
An immutable version is not available because it would still need to make a mutation, to read the data, and it is not possible to do concurrently.
Please check the compiled code to determine if your function makes a spurious copy which could be a security issue.