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
- 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 variable always resolving to the same given value.
Dynamic variable can resolve to different values over time.
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][−]
T: From<String> + 'static,
E: From<VarError> + 'static,
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][−]
T: From<String> + 'static,
E: From<VarError> + 'static,
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][−]
T: From<String> + 'static,
E: From<Error> + From<FromUtf8Error> + 'static,
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][−]
T: From<Vec<u8>> + 'static,
E: From<Error> + 'static,
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][+]
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][+]
T: Clone,
Auto Trait Implementations
impl<T, E = CredentialsError> !RefUnwindSafe for Variable<T, E>
impl<T, E> Send for Variable<T, E> where
T: Send,
T: Send,
impl<T, E> Sync for Variable<T, E> where
T: Sync,
T: Sync,
impl<T, E> Unpin for Variable<T, E> where
T: Unpin,
T: Unpin,
impl<T, E = CredentialsError> !UnwindSafe for Variable<T, E>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src][+]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src][+]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src][+]
T: ?Sized,
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][+]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src][+]
T: Clone,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src][+]
U: Into<T>,
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src][+]
U: TryFrom<T>,