secure_gate/
fixed.rs

1// src/fixed.rs
2use core::ops::{Deref, DerefMut};
3
4use crate::{Expose, ExposeMut};
5
6pub struct Fixed<T>(pub T); // ← pub field
7
8impl<T> Fixed<T> {
9    pub fn new(value: T) -> Self {
10        Fixed(value)
11    }
12}
13
14impl<T> Deref for Fixed<T> {
15    type Target = T;
16    #[inline(always)]
17    fn deref(&self) -> &T {
18        &self.0
19    }
20}
21
22impl<T> DerefMut for Fixed<T> {
23    #[inline(always)]
24    fn deref_mut(&mut self) -> &mut T {
25        &mut self.0
26    }
27}
28
29impl<T> core::fmt::Debug for Fixed<T> {
30    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
31        f.write_str("[REDACTED]")
32    }
33}
34
35impl<T> Fixed<T> {
36    pub fn view(&self) -> Expose<'_, T> {
37        Expose(&self.0)
38    }
39
40    pub fn view_mut(&mut self) -> ExposeMut<'_, T> {
41        ExposeMut(&mut self.0)
42    }
43}
44
45impl<T> Fixed<T> {
46    pub fn into_inner(self) -> T {
47        self.0
48    }
49}
50
51// From impls for common sizes (no orphan rule issue)
52macro_rules! impl_from_array {
53    ($($N:literal),*) => {$(
54        impl From<[u8; $N]> for Fixed<[u8; $N]> {
55            fn from(arr: [u8; $N]) -> Self {
56                Self::new(arr)
57            }
58        }
59    )*}
60}
61impl_from_array!(12, 16, 24, 32, 64);