Enum rusoto_credential::Variable
source · [−]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
sourceimpl<T: Clone, E> Variable<T, E>
impl<T: Clone, E> Variable<T, E>
sourcepub fn with_value<V: Into<T>>(value: V) -> Self
pub fn with_value<V: Into<T>>(value: V) -> Self
Variable which statically resolves to a provided (in-memory) value.
sourcepub fn or(self, other: Variable<T, E>) -> Self
pub fn or(self, other: Variable<T, E>) -> Self
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);
sourceimpl<T, E> Variable<T, E> where
T: From<String> + 'static,
E: From<VarError> + 'static,
impl<T, E> Variable<T, E> where
T: From<String> + 'static,
E: From<VarError> + 'static,
sourcepub fn from_env_var<K: AsRef<OsStr>>(key: K) -> Self
pub fn from_env_var<K: AsRef<OsStr>>(key: K) -> Self
Variable which dynamically resolves to the value of a given environment variable.
sourceimpl<T, E> Variable<Option<T>, E> where
T: From<String> + 'static,
E: From<VarError> + 'static,
impl<T, E> Variable<Option<T>, E> where
T: From<String> + 'static,
E: From<VarError> + 'static,
sourcepub fn from_env_var_optional<K: AsRef<OsStr>>(key: K) -> Self
pub fn from_env_var_optional<K: AsRef<OsStr>>(key: K) -> Self
Variable which dynamically resolves to the value of a given environment variable.
Trait Implementations
sourceimpl<T: Clone, E> Clone for Variable<T, E>
impl<T: Clone, E> Clone for Variable<T, E>
Custom Clone implementation as type parameter E doesn’t have to be cloneable.
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
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
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more