zeroize 0.2.0

Securely zero memory while avoiding compiler optimizations: unified 'secure_zero_memory()' wrapper for secure intrinsic functions for zeroing memory, using FFI to invoke OS intrinsics on stable (with support for Linux, Windows, OS X/iOS, FreeBSD, OpenBSD, NetBSD, DragonflyBSD), or the unstable 'volatile_set_memory()` intrinsic on nightly. No insecure fallbacks, no dependencies, no std, no functionality besides securely zeroing memory.
Documentation
use super::secure_zero_memory;

/// Trait for securely erasing types from memory
pub trait Zeroize {
    /// Zero out this object from memory (using Rust or OS intrinsics which
    /// ensure the zeroization operation is not "optimized away")
    fn zeroize(&mut self);
}

// Zeroize implementations for the most common types we might want it for

impl<T> Zeroize for T
where
    T: AsMut<[u8]>,
{
    fn zeroize(&mut self) {
        secure_zero_memory(self.as_mut());
    }
}

#[cfg(test)]
mod tests {
    use super::Zeroize;

    #[test]
    fn zeroize_slice() {
        let mut arr = [42; 3];
        arr.zeroize();
        assert_eq!(arr, [0, 0, 0]);
    }

    #[test]
    fn zeroize_vec() {
        let mut arr = vec![42; 3];
        arr.zeroize();
        assert_eq!(arr.as_slice(), [0, 0, 0]);
    }
}