I’m not sure it’s possible to implement Zeroing<T> except as a marker trait in the compiler. Consider:
struct Zeroing<T> { data: T }
impl<T> Deref for Zeroing<T> { ... }
// etc
impl<T> Drop for Zeroing<T> {
fn drop(&mut self) {
// need to drop the value...
let x: T = unsafe { ptr::read(&self.data) };
drop(x);
// now we need to zero: self.data, x, AND wherever x was put when passed to drop.
}
}
It might be possible with negative bounds, implementing for T: !Drop, but I’m not sure. It’d be much easier as a special struct Zeroing<T: Copy> { data: Vec<T> } or Box<T> where T: Copy + ?Sized (as an owned buffer that will be zeroed and never copied).
If we were going to ship something for 1.0, it either needs to be ZeroingBuf { data: Vec<u8> } or a magical lang item.
EDIT: And, a more comprehensive design would have a ZeroSelf trait, so containers like Vec would know how to zero their contents. I think ZeroingBuf is probably a better idea…
EDIT2: To clarify, I think we should totally implement ZeroingBuf for 1.0.