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.

Source

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

Expose the inner value for mutable access.

Source

pub fn into_inner(self) -> Box<T>

Consume and return the inner Box<T>.

Source§

impl DynamicNoClone<String>

Source

pub fn finish_mut(&mut self) -> &mut String

Get a mutable reference and shrink spare capacity.

Similar to Dynamic::finish_mut().

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 fn finish_mut(&mut self) -> &mut Vec<T>

Get a mutable reference and shrink spare capacity.

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.

Source

pub fn as_slice(&self) -> &[T]

Returns a shared slice of the secret bytes.

Requires explicit intent — consistent with the crate’s philosophy.

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.