Struct clear_on_drop::ClearOnDrop [] [src]

pub struct ClearOnDrop<P> where P: DerefMut, P::Target: Clear { /* fields omitted */ }

Zeroizes a storage location when dropped.

This struct contains a reference to a memory location, either as a mutable borrow (&mut T), or as a owned container (Box<T> or similar). When this struct is dropped, the referenced location is overwritten with its Default value.

Example

#[derive(Default)]
struct MyData {
    value: u32,
}

let mut place = MyData { value: 0 };
{
    let mut key = ClearOnDrop::new(&mut place);
    key.value = 0x01234567;
    // ...
}   // key is dropped here
assert_eq!(place.value, 0);

Methods

impl<P> ClearOnDrop<P> where P: DerefMut, P::Target: Clear
[src]

Creates a new ClearOnDrop which clears place on drop.

The place parameter can be a &mut T, a Box<T>, or other containers which behave like Box<T>.

Consumes the ClearOnDrop, returning the place without clearing.

Note: this is an associated function, which means that you have to call it as ClearOnDrop::into_uncleared_place(c) instead of c.into_uncleared_place(). This is so that there is no conflict with a method on the inner type.

Consumes the ClearOnDrop, returning the place after clearing.

Note: this is an associated function, which means that you have to call it as ClearOnDrop::into_place(c) instead of c.into_place(). This is so that there is no conflict with a method on the inner type.

Trait Implementations

impl<P> Clone for ClearOnDrop<P> where P: DerefMut + Clone, P::Target: Clear
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl<P> Debug for ClearOnDrop<P> where P: DerefMut + Debug, P::Target: Clear
[src]

Formats the value using the given formatter.

impl<P> Deref for ClearOnDrop<P> where P: DerefMut, P::Target: Clear
[src]

The resulting type after dereferencing

The method called to dereference a value

impl<P> DerefMut for ClearOnDrop<P> where P: DerefMut, P::Target: Clear
[src]

The method called to mutably dereference a value

impl<P> Drop for ClearOnDrop<P> where P: DerefMut, P::Target: Clear
[src]

A method called when the value goes out of scope. Read more

impl<P, T: ?Sized> AsRef<T> for ClearOnDrop<P> where P: DerefMut + AsRef<T>, P::Target: Clear
[src]

Performs the conversion.

impl<P, T: ?Sized> AsMut<T> for ClearOnDrop<P> where P: DerefMut + AsMut<T>, P::Target: Clear
[src]

Performs the conversion.

impl<P, T: ?Sized> Borrow<T> for ClearOnDrop<P> where P: DerefMut + Borrow<T>, P::Target: Clear, T: Clear
[src]

Immutably borrows from an owned value. Read more

impl<P, T: ?Sized> BorrowMut<T> for ClearOnDrop<P> where P: DerefMut + BorrowMut<T>, P::Target: Clear, T: Clear
[src]

Mutably borrows from an owned value. Read more

impl<P> Hash for ClearOnDrop<P> where P: DerefMut + Hash, P::Target: Clear
[src]

Feeds this value into the state given, updating the hasher as necessary.

Feeds a slice of this type into the state provided.

impl<P, Q> PartialEq<ClearOnDrop<Q>> for ClearOnDrop<P> where P: DerefMut + PartialEq<Q>, P::Target: Clear, Q: DerefMut, Q::Target: Clear
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<P> Eq for ClearOnDrop<P> where P: DerefMut + Eq, P::Target: Clear
[src]

impl<P, Q> PartialOrd<ClearOnDrop<Q>> for ClearOnDrop<P> where P: DerefMut + PartialOrd<Q>, P::Target: Clear, Q: DerefMut, Q::Target: Clear
[src]

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl<P> Ord for ClearOnDrop<P> where P: DerefMut + Ord, P::Target: Clear
[src]

This method returns an Ordering between self and other. Read more