[−][src]Struct clear_on_drop::ClearOnDrop
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]
P: DerefMut,
P::Target: Clear,
pub fn new(place: P) -> Self
[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>
.
Note: only the first level of dereference will be cleared. Do
not use &mut Box<T>
or similar as the place, since the heap
contents won't be cleared in that case. If you need the place
back, use ClearOnDrop::into_place(...)
instead of a borrow.
pub fn into_place(c: Self) -> P
[src]
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.
pub fn into_uncleared_place(c: Self) -> P
[src]
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.
Trait Implementations
impl<P> Debug for ClearOnDrop<P> where
P: DerefMut + Debug,
P::Target: Clear,
[src]
P: DerefMut + Debug,
P::Target: Clear,
impl<P, Q> PartialEq<ClearOnDrop<Q>> for ClearOnDrop<P> where
P: DerefMut + PartialEq<Q>,
P::Target: Clear,
Q: DerefMut,
Q::Target: Clear,
[src]
P: DerefMut + PartialEq<Q>,
P::Target: Clear,
Q: DerefMut,
Q::Target: Clear,
fn eq(&self, other: &ClearOnDrop<Q>) -> bool
[src]
fn ne(&self, other: &ClearOnDrop<Q>) -> bool
[src]
impl<P> Eq for ClearOnDrop<P> where
P: DerefMut + Eq,
P::Target: Clear,
[src]
P: DerefMut + Eq,
P::Target: Clear,
impl<P> Ord for ClearOnDrop<P> where
P: DerefMut + Ord,
P::Target: Clear,
[src]
P: DerefMut + Ord,
P::Target: Clear,
fn cmp(&self, other: &Self) -> Ordering
[src]
fn max(self, other: Self) -> Self
1.21.0[src]
fn min(self, other: Self) -> Self
1.21.0[src]
fn clamp(self, min: Self, max: Self) -> Self
[src]
impl<P, Q> PartialOrd<ClearOnDrop<Q>> for ClearOnDrop<P> where
P: DerefMut + PartialOrd<Q>,
P::Target: Clear,
Q: DerefMut,
Q::Target: Clear,
[src]
P: DerefMut + PartialOrd<Q>,
P::Target: Clear,
Q: DerefMut,
Q::Target: Clear,
fn partial_cmp(&self, other: &ClearOnDrop<Q>) -> Option<Ordering>
[src]
fn lt(&self, other: &ClearOnDrop<Q>) -> bool
[src]
fn le(&self, other: &ClearOnDrop<Q>) -> bool
[src]
fn gt(&self, other: &ClearOnDrop<Q>) -> bool
[src]
fn ge(&self, other: &ClearOnDrop<Q>) -> bool
[src]
impl<P> Deref for ClearOnDrop<P> where
P: DerefMut,
P::Target: Clear,
[src]
P: DerefMut,
P::Target: Clear,
type Target = P::Target
The resulting type after dereferencing.
fn deref(&self) -> &Self::Target
[src]
impl<P> DerefMut for ClearOnDrop<P> where
P: DerefMut,
P::Target: Clear,
[src]
P: DerefMut,
P::Target: Clear,
impl<P> Drop for ClearOnDrop<P> where
P: DerefMut,
P::Target: Clear,
[src]
P: DerefMut,
P::Target: Clear,
impl<P> Hash for ClearOnDrop<P> where
P: DerefMut + Hash,
P::Target: Clear,
[src]
P: DerefMut + Hash,
P::Target: Clear,
fn hash<H: Hasher>(&self, state: &mut H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<P, T: ?Sized> AsRef<T> for ClearOnDrop<P> where
P: DerefMut + AsRef<T>,
P::Target: Clear,
[src]
P: DerefMut + AsRef<T>,
P::Target: Clear,
impl<P, T: ?Sized> AsMut<T> for ClearOnDrop<P> where
P: DerefMut + AsMut<T>,
P::Target: Clear,
[src]
P: DerefMut + AsMut<T>,
P::Target: Clear,
impl<P> Clone for ClearOnDrop<P> where
P: DerefMut + Clone,
P::Target: Clear,
[src]
P: DerefMut + Clone,
P::Target: Clear,
fn clone(&self) -> Self
[src]
fn clone_from(&mut self, source: &Self)
[src]
impl<P, T: ?Sized> Borrow<T> for ClearOnDrop<P> where
P: DerefMut + Borrow<T>,
P::Target: Clear,
T: Clear,
[src]
P: DerefMut + Borrow<T>,
P::Target: Clear,
T: Clear,
impl<P, T: ?Sized> BorrowMut<T> for ClearOnDrop<P> where
P: DerefMut + BorrowMut<T>,
P::Target: Clear,
T: Clear,
[src]
P: DerefMut + BorrowMut<T>,
P::Target: Clear,
T: Clear,
fn borrow_mut(&mut self) -> &mut T
[src]
Auto Trait Implementations
impl<P> Unpin for ClearOnDrop<P> where
P: Unpin,
P: Unpin,
impl<P> Send for ClearOnDrop<P> where
P: Send,
P: Send,
impl<P> Sync for ClearOnDrop<P> where
P: Sync,
P: Sync,
Blanket Implementations
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,