Enum rusoto_credential::Variable[][src]

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>>),
}

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

Resolving Behaviour

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

impl<T: Clone, E> Variable<T, E>[src]

pub fn with_value<V: Into<T>>(value: V) -> Self[src]

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

pub fn resolve(&self) -> Result<T, E>[src]

Resolve the variable’s value.

pub fn or(self, other: Variable<T, E>) -> Self[src]

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);

impl<T: 'static, E: 'static> Variable<T, E>[src]

pub fn dynamic(f: impl Fn() -> Result<T, E> + Send + Sync + 'static) -> Self[src]

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

impl<T, E> Variable<T, E> where
    T: From<String> + 'static,
    E: From<VarError> + 'static, 
[src]

pub fn from_env_var<K: AsRef<OsStr>>(key: K) -> Self[src]

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

impl<T, E> Variable<Option<T>, E> where
    T: From<String> + 'static,
    E: From<VarError> + 'static, 
[src]

pub fn from_env_var_optional<K: AsRef<OsStr>>(key: K) -> Self[src]

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

impl<T, E> Variable<T, E> where
    T: From<String> + 'static,
    E: From<Error> + From<FromUtf8Error> + 'static, 
[src]

pub fn from_text_file<K: AsRef<Path>>(file: K) -> Self[src]

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

impl<T, E> Variable<T, E> where
    T: From<Vec<u8>> + 'static,
    E: From<Error> + 'static, 
[src]

pub fn from_binary_file<K: AsRef<Path>>(file: K) -> Self[src]

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

Trait Implementations

impl<T: Clone, E> Clone for Variable<T, E>[src]

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

impl<T: Debug, E> Debug for Variable<T, E>[src]

impl<E> From<&'_ str> for Variable<String, E>[src]

impl<T, E> From<T> for Variable<T, E> where
    T: Clone
[src]

Auto Trait Implementations

impl<T, E = CredentialsError> !RefUnwindSafe for Variable<T, E>

impl<T, E> Send for Variable<T, E> where
    T: Send

impl<T, E> Sync for Variable<T, E> where
    T: Sync

impl<T, E> Unpin for Variable<T, E> where
    T: Unpin

impl<T, E = CredentialsError> !UnwindSafe for Variable<T, E>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<!> for T[src]

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.