Skip to main content

Secret

Struct Secret 

Source
pub struct Secret(/* private fields */);
Available on crate feature alloc only.
Expand description

A text field that holds a secret (a password, a token).

No Display, no Clone (a clone is a second copy to wipe), no way to take the String out: expose is the only way to read it, which makes every read easy to find in review. The bytes are wiped on drop with crypt-io’s volatile wipe; Debug prints Secret(..).

§Examples

use form_net::Secret;

let s = Secret::from(String::from("hunter2"));
assert_eq!(s.expose(), "hunter2");
assert_eq!(format!("{s:?}"), "Secret(..)");

Implementations§

Source§

impl Secret

Source

pub fn expose(&self) -> &str

The secret text.

Source

pub fn len(&self) -> usize

Its length in bytes.

Source

pub fn is_empty(&self) -> bool

Whether it is empty.

Trait Implementations§

Source§

impl Debug for Secret

Source§

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

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

impl Drop for Secret

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl From<String> for Secret

Source§

fn from(s: String) -> Secret

Converts to this type from the input type.
Source§

impl FromField for Secret

Source§

type Slot = Option<Secret>

What has arrived so far.
Source§

fn accept_text(slot: &mut Self::Slot, value: &str) -> Result<(), ValueError>

Takes one text value. Read more
Source§

fn finish(slot: Self::Slot) -> Result<Self, ValueError>

The value, once every field has arrived. Read more
Source§

fn accept_file( slot: &mut Self::Slot, file: FileValue<'_>, ) -> Result<(), ValueError>

Takes one file. Read more

Auto Trait Implementations§

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.