pub type CloneableString = Dynamic<CloneableStringInner>;Expand description
A string wrapped as a cloneable secret.
This type provides a secure wrapper around a String that can be safely cloned
while ensuring the underlying data is properly zeroized when no longer needed.
Use this for sensitive text data like passwords, tokens, or cryptographic passphrases.
§Examples
use secure_gate::CloneableString;
// Create from a string
let password: CloneableString = "secret123".to_string().into();
// Create from a string slice
let token: CloneableString = "token_value".into();
// Access the inner string
let inner = password.expose_inner();
assert_eq!(inner.as_str(), "secret123");Aliased Type§
pub struct CloneableString(/* private fields */);Implementations§
Source§impl CloneableString
impl CloneableString
Sourcepub const fn expose_inner(&self) -> &String
pub const fn expose_inner(&self) -> &String
Returns a reference to the inner string without cloning.
This method provides direct access to the wrapped String.
The reference is valid for the lifetime of the CloneableString.
Sourcepub fn expose_inner_mut(&mut self) -> &mut String
pub fn expose_inner_mut(&mut self) -> &mut String
Returns a mutable reference to the inner string.
This method provides direct mutable access to the wrapped String.
Use this when you need to modify the string contents in-place.
Sourcepub fn init_with<F>(constructor: F) -> Self
pub fn init_with<F>(constructor: F) -> Self
Construct a cloneable string secret by building it in a closure.
This minimizes the time the secret spends on the stack:
- The closure builds a temporary
String. - It is immediately cloned to the heap.
- The temporary is zeroized before returning.
Use this when reading passwords or tokens from user input.
§Example
use secure_gate::CloneableString;
use std::io::{self, Write};
fn read_password() -> io::Result<String> {
let mut input = String::new();
io::stdout().flush()?;
io::stdin().read_line(&mut input)?;
Ok(input.trim_end().to_string())
}
let pw = CloneableString::init_with(|| read_password().unwrap());Sourcepub fn try_init_with<F, E>(constructor: F) -> Result<Self, E>
pub fn try_init_with<F, E>(constructor: F) -> Result<Self, E>
Fallible version of init_with.
Same stack-minimization benefits as init_with, but allows for construction
that may fail with an error. Useful when reading secrets from fallible sources
like files, network connections, or user input that may encounter I/O errors.
Trait Implementations§
Source§impl From<&str> for CloneableString
Wrap a string slice in a CloneableString.
impl From<&str> for CloneableString
Wrap a string slice in a CloneableString.