Skip to content

Commit c3f7160

Browse files
committed
tweak docs
1 parent 7308bcb commit c3f7160

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

zeroize/src/barrier.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,18 @@
1111
/// implemented using `#[inline(never)]` and `read_volatile`.
1212
///
1313
/// # Examples
14-
/// ```ignore
14+
/// ```
1515
/// use core::num::NonZeroU32;
1616
/// use zeroize::{ZeroizeOnDrop, zeroize_flat_type};
1717
///
18+
/// # type ThirdPartyType = u32;
19+
///
1820
/// struct DataToZeroize {
1921
/// buf: [u8; 32],
22+
/// // `ThirdPartyType` can be a type with private fields
23+
/// // defined in a third-party crate and which does not implement
24+
/// // `Zeroize` or zeroization on drop.
25+
/// data: ThirdPartyType,
2026
/// pos: NonZeroU32,
2127
/// }
2228
///
@@ -25,6 +31,7 @@
2531
/// impl Drop for DataToZeroize {
2632
/// fn drop(&mut self) {
2733
/// self.buf = [0u8; 32];
34+
/// self.data = ThirdPartyType::default();
2835
/// self.pos = NonZeroU32::new(32).unwrap();
2936
/// zeroize::optimization_barrier(self);
3037
/// }
@@ -34,11 +41,15 @@
3441
///
3542
/// let mut data = DataToZeroize {
3643
/// buf: [3u8; 32],
44+
/// data: ThirdPartyType::default(),
3745
/// pos: NonZeroU32::new(32).unwrap(),
3846
/// };
3947
///
4048
/// // data gets zeroized when dropped
4149
/// ```
50+
///
51+
/// Note that erasure of `ThirdPartyType` demonstrated above can be fragile if it contains
52+
/// `MaybeUninit` or `union` data. It also does not perform erasure of types like `Box` or `Vec`.
4253
pub fn optimization_barrier<T: ?Sized>(val: &T) {
4354
#[cfg(all(
4455
not(miri),

0 commit comments

Comments
 (0)