logo
pub enum Variable<T, E = CredentialsError> {
    Static(T),
    Dynamic(Arc<dyn Fn() -> Result<T, E> + Send + Sync>),
    Fallback(Box<Variable<T, E>>, Box<Variable<T, E>>),
}
Expand description

Variable is an abstraction over parameters to credential providers, allowing to abstract on how (source) and when (time) parameter values are resolved. A lot of credentials providers use external information sources such as environment variables or files to obtain parameter values needed to produce AWS credentials.

Information Sources

  • In memory values (static)
  • Environment variables (dynamic)
  • Files (dynamic)

Resolving Behaviour

  • Static variables always resolve to the same value.
  • Dynamic variables can resolve to different values over time.

Most prominent examples for dynamic variables are parameters which read their value from environment variables or files.

Variants

Static(T)

Static variable always resolving to the same given value.

Dynamic(Arc<dyn Fn() -> Result<T, E> + Send + Sync>)

Dynamic variable can resolve to different values over time.

Fallback(Box<Variable<T, E>>, Box<Variable<T, E>>)

Fallback try variables in given order returning the value of the first variable that does resolve.

Implementations

Variable which statically resolves to a provided (in-memory) value.

Resolve the variable’s value.

Combine this Variable with a fallback Variable. Resolving the variable’s value will be done lazily, stopping on the first Variable that successfuly resolves.

Example Usage
let primary: Variable<String> = Variable::from_env_var("AWS_SECRET_ACCESS_KEY");
let fallback = Variable::from_env_var("AWS_SECRET_KEY");
let aws_secret_access_key = primary.or(fallback);

Variable which dynamically resolves to the value returned from the provided closure. Use this constructor function to create dynamically resolving Variables with custom logic.

Variable which dynamically resolves to the value of a given environment variable.

Variable which dynamically resolves to the value of a given environment variable.

Variable which dynamically resolves to the value of an UTF-8 encoded text file (removing all leading and trailing whitespaces.

Variable which dynamically resolves to the value of a binary file.

Trait Implementations

Custom Clone implementation as type parameter E doesn’t have to be cloneable.

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Converts to this type from the input type.

Converts to this type from the input type.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Converts to this type from the input type.

Returns the argument unchanged.

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

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

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

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

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

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