redoubt_zero_core/
pointers.rs

1// Copyright (c) 2025-2026 Federico Hoerth <memparanoid@gmail.com>
2// SPDX-License-Identifier: GPL-3.0-only
3// See LICENSE in the repository root for full license text.
4
5//! Trait implementations for raw pointers.
6//!
7//! Provides `ZeroizationProbe`, `ZeroizeMetadata`, and `FastZeroizable`
8//! implementations for `*mut T` and `*const T`.
9
10use core::ptr;
11
12use crate::traits::{FastZeroizable, ZeroizationProbe, ZeroizeMetadata};
13
14// *mut T
15
16impl<T> ZeroizationProbe for *mut T {
17    #[inline(always)]
18    fn is_zeroized(&self) -> bool {
19        self.is_null()
20    }
21}
22
23impl<T> ZeroizeMetadata for *mut T {
24    const CAN_BE_BULK_ZEROIZED: bool = false;
25}
26
27impl<T> FastZeroizable for *mut T {
28    #[inline(always)]
29    fn fast_zeroize(&mut self) {
30        unsafe {
31            ptr::write_volatile(self, ptr::null_mut());
32        }
33    }
34}
35
36// *const T
37
38impl<T> ZeroizationProbe for *const T {
39    #[inline(always)]
40    fn is_zeroized(&self) -> bool {
41        self.is_null()
42    }
43}
44
45impl<T> ZeroizeMetadata for *const T {
46    const CAN_BE_BULK_ZEROIZED: bool = false;
47}
48
49impl<T> FastZeroizable for *const T {
50    #[inline(always)]
51    fn fast_zeroize(&mut self) {
52        unsafe {
53            ptr::write_volatile(self, ptr::null());
54        }
55    }
56}