Enum Secret

Source
pub enum Secret {
    Empty,
    Raw(String),
    Command(Command),
    Keyring(KeyringEntry),
}
Expand description

The secret.

A secret can be retrieved either from a raw string, from a shell command or from a keyring entry.

Variants§

§

Empty

The secret is empty.

§

Raw(String)

The secret is contained in a raw string.

This variant is not safe to use and therefore not recommended. Yet it works well for testing purpose.

§

Command(Command)

The secret is exposed by the given shell command.

This variant takes the secret from the first line returned by the given shell command.

See process-lib.

§

Keyring(KeyringEntry)

The secret is contained in the user’s global keyring at the given entry.

See keyring-lib.

Implementations§

Source§

impl Secret

Source

pub fn new() -> Self

Creates a new empty secret.

Source

pub fn new_raw(raw: impl ToString) -> Self

Creates a new secret from the given raw string.

Source

pub fn new_command(cmd: impl ToString) -> Self

Creates a new secret from the given shell command.

Source

pub fn new_keyring_entry(entry: KeyringEntry) -> Self

Creates a new secret from the given keyring entry.

Source

pub fn try_new_keyring_entry( entry: impl TryInto<KeyringEntry, Error = Error>, ) -> Result<Self>

Tries to create a new secret from the given entry.

Source

pub fn is_empty(&self) -> bool

Returns true if the secret is empty.

Source

pub async fn get(&self) -> Result<String>

Gets the secret value.

The command-based secret execute its shell command and returns the output, and the keyring-based secret retrieves the value from the global keyring using its inner key.

Source

pub async fn find(&self) -> Result<Option<String>>

Finds the secret value.

Like Secret::get, but returns None if the secret value is not found or empty.

Source

pub async fn set(&mut self, secret: impl ToString) -> Result<String>

Updates the secret value.

This is only applicable for raw secrets and keyring-based secrets. A secret value cannot be changed for command-base secrets, since the value is the output of the command.

Source

pub async fn set_if_keyring(&self, secret: impl ToString) -> Result<String>

Updates the secret value of the keyring-based secret only.

This function as no effect on other secret variants.

Source

pub async fn delete(&mut self) -> Result<()>

Deletes the secret value and make the current secret empty.

Source

pub async fn delete_if_keyring(&self) -> Result<()>

Deletes the secret value of keyring-based secrets only.

This function has no effect on other variants.

Source

pub fn replace_if_empty(&mut self, new: Self)

Replaces empty secret variant with the given one.

This function has no effect on other variants.

Source

pub fn replace_with_keyring_if_empty( &mut self, entry: impl ToString, ) -> Result<()>

Replaces empty secret variant with a keyring one.

This function has no effect on other variants.

Trait Implementations§

Source§

impl Clone for Secret

Source§

fn clone(&self) -> Secret

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Secret

Source§

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

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

impl Default for Secret

Source§

fn default() -> Secret

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Secret

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for Secret

Source§

fn eq(&self, other: &Secret) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Secret

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for Secret

Source§

impl StructuralPartialEq for Secret

Auto Trait Implementations§

§

impl Freeze for Secret

§

impl !RefUnwindSafe for Secret

§

impl Send for Secret

§

impl Sync for Secret

§

impl Unpin for Secret

§

impl !UnwindSafe for Secret

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> NoneValue for T
where T: Default,

Source§

type NoneType = T

Source§

fn null_value() -> T

The none-equivalent value.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,