From 44040090a7fedc8ecf3f03c7553eaf1b54e98273 Mon Sep 17 00:00:00 2001 From: Jeffrey Burdges Date: Sun, 15 Jan 2017 11:52:17 -0500 Subject: [PATCH] Replace Default with Copy See https://github.com/cesarb/clear_on_drop/issues/3 --- src/clear_on_drop.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/clear_on_drop.rs b/src/clear_on_drop.rs index 2c4bbbf..26b92c4 100644 --- a/src/clear_on_drop.rs +++ b/src/clear_on_drop.rs @@ -8,13 +8,13 @@ use hide::hide_mem; /// This struct contains a reference to a memory location, either as a /// mutable borrow (`&mut T`), or as a owned container (`Box` or /// similar). When this struct is dropped, the referenced location is -/// overwritten with its `Default` value. +/// overwritten with zeros. /// /// # Example /// /// ``` /// # use clear_on_drop::ClearOnDrop; -/// #[derive(Default)] +/// #[derive(Debug, Clone, Copy)] /// struct MyData { /// value: u32, /// } @@ -29,12 +29,12 @@ use hide::hide_mem; /// ``` pub struct ClearOnDrop - where T: Default, P: Deref + DerefMut { + where T: Copy, P: Deref + DerefMut { _place: P, } impl ClearOnDrop - where T: Default, P: Deref + DerefMut { + where T: Copy, P: Deref + DerefMut { /// Creates a new `ClearOnDrop` which clears `place` on drop. /// /// The `place` parameter can be a `&mut T`, a `Box`, or other @@ -46,7 +46,7 @@ impl ClearOnDrop } impl fmt::Debug for ClearOnDrop - where T: Default, P: Deref + DerefMut + fmt::Debug { + where T: Copy, P: Deref + DerefMut + fmt::Debug { #[inline] fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fmt::Debug::fmt(&self._place, f) @@ -54,7 +54,7 @@ impl fmt::Debug for ClearOnDrop } impl Deref for ClearOnDrop - where T: Default, P: Deref + DerefMut { + where T: Copy, P: Deref + DerefMut { type Target = T; #[inline] @@ -64,7 +64,7 @@ impl Deref for ClearOnDrop } impl DerefMut for ClearOnDrop - where T: Default, P: Deref + DerefMut { + where T: Copy, P: Deref + DerefMut { #[inline] fn deref_mut(&mut self) -> &mut Self::Target { DerefMut::deref_mut(&mut self._place) @@ -72,7 +72,7 @@ impl DerefMut for ClearOnDrop } impl Drop for ClearOnDrop - where T: Default, P: Deref + DerefMut { + where T: Copy, P: Deref + DerefMut { #[inline] fn drop(&mut self) { let place = self.deref_mut(); @@ -85,9 +85,9 @@ impl Drop for ClearOnDrop mod tests { use super::ClearOnDrop; - #[derive(Debug, Default)] + #[derive(Debug, Copy, Clone, Default)] struct Place { - data: [u32; 4], + pub data: [u32; 4], } const DATA: [u32; 4] = [0x01234567, 0x89abcdef, 0xfedcba98, 0x76543210];