DynamicNoClone

Struct DynamicNoClone 

Source
pub struct DynamicNoClone<T: ?Sized>(/* private fields */);
Expand description

Non-cloneable heap-allocated secret wrapper.

This is a thin newtype over Dynamic<T> that deliberately omits Clone. Use this for dynamic secrets where duplication must be prevented.

Converts from Dynamic<T> via .no_clone().

§Examples

use secure_gate::{Dynamic, DynamicNoClone};
let secret = Dynamic::new("hunter2".to_string());
let no_clone: DynamicNoClone<String> = secret.no_clone();
// no_clone cannot be cloned
assert_eq!(no_clone.expose_secret(), "hunter2");

Implementations§

Source§

impl<T: ?Sized> DynamicNoClone<T>

Source

pub fn new(value: Box<T>) -> Self

Wrap a boxed value in a non-cloneable dynamic secret.

§Example
use secure_gate::DynamicNoClone;
let boxed = Box::new("secret".to_string());
let no_clone = DynamicNoClone::new(boxed);
Source

pub const fn expose_secret(&self) -> &T

Expose the inner value for read-only access.

This is the only way to read the secret — loud and auditable.

§Example
use secure_gate::DynamicNoClone;
let secret = DynamicNoClone::new(Box::new("hunter2".to_string()));
assert_eq!(secret.expose_secret(), "hunter2");
Source

pub fn expose_secret_mut(&mut self) -> &mut T

Expose the inner value for mutable access.

This is the only way to mutate the secret — loud and auditable.

§Example
use secure_gate::DynamicNoClone;
let mut secret = DynamicNoClone::new(Box::new("hello".to_string()));
secret.expose_secret_mut().push_str(" world");
assert_eq!(secret.expose_secret(), "hello world");
Source§

impl<T: ?Sized + Zeroize> DynamicNoClone<T>

Source

pub fn zeroize_now(&mut self)

Explicitly zeroize the secret immediately.

This is useful when you want to wipe memory before the value goes out of scope, or when you want to make the zeroization intent explicit in the code.

§Example
use secure_gate::DynamicNoClone;
let mut password = DynamicNoClone::new(Box::new("secret".to_string()));
// ... use password ...
password.zeroize_now();  // Explicit wipe - makes intent clear
Source§

impl DynamicNoClone<String>

Source

pub const fn len(&self) -> usize

Returns the length of the secret string in bytes (UTF-8).

Source

pub const fn is_empty(&self) -> bool

Returns true if the secret string is empty.

Source§

impl<T> DynamicNoClone<Vec<T>>

Source

pub const fn len(&self) -> usize

Returns the length of the secret vector in elements.

Source

pub const fn is_empty(&self) -> bool

Returns true if the secret vector is empty.

Trait Implementations§

Source§

impl<T: ?Sized> Debug for DynamicNoClone<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: ?Sized + Zeroize> Zeroize for DynamicNoClone<T>

Available on crate feature zeroize only.
Source§

fn zeroize(&mut self)

Zero out this object from memory using Rust intrinsics which ensure the zeroization operation is not “optimized away” by the compiler.
Source§

impl<T: ?Sized + Zeroize> ZeroizeOnDrop for DynamicNoClone<T>

Available on crate feature zeroize only.

Auto Trait Implementations§

§

impl<T> Freeze for DynamicNoClone<T>
where T: ?Sized,

§

impl<T> RefUnwindSafe for DynamicNoClone<T>
where T: RefUnwindSafe + ?Sized,

§

impl<T> Send for DynamicNoClone<T>
where T: Send + ?Sized,

§

impl<T> Sync for DynamicNoClone<T>
where T: Sync + ?Sized,

§

impl<T> Unpin for DynamicNoClone<T>
where T: ?Sized,

§

impl<T> UnwindSafe for DynamicNoClone<T>
where T: UnwindSafe + ?Sized,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.