MangledOption

Enum MangledOption 

Source
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§

Implementations§

Source§

impl<T> MangledOption<T>

Source

pub fn new() -> Self

Creates a new MangledOption with the None variant.

Source

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.

Source

pub fn is_some(&self) -> bool

Returns true if the option is a Some variant.

Source

pub fn is_none(&self) -> bool

Returns true if the option is a None variant.

Source

pub fn take(&mut self) -> MangledOption<T>

Takes the value out of the option, leaving a None in its place.

Source

pub fn clear(&mut self)

Clears the option, dropping the value if it is a Some variant.

Source

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.

Source

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.

Source

pub fn map_mut_or_else<F, G, R>(&mut self, default: G, f: F) -> R
where F: FnOnce(&mut T) -> R, G: FnOnce() -> 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.

Source

pub fn map_mut<F, R>(&mut self, f: F) -> Option<R>
where F: FnOnce(&mut T) -> 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.

Source

pub fn rekey(&mut self)

Rekeys the box, preserving its contents.

Source

pub fn as_ptr(&mut self) -> *mut T

Returns pointer to mangled data.

Trait Implementations§

Source§

impl<T> Default for MangledOption<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<T> Drop for MangledOption<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<T> Freeze for MangledOption<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for MangledOption<T>
where T: RefUnwindSafe,

§

impl<T> Send for MangledOption<T>
where T: Send,

§

impl<T> Sync for MangledOption<T>
where T: Sync,

§

impl<T> Unpin for MangledOption<T>
where T: Unpin,

§

impl<T> UnwindSafe for MangledOption<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.