Function aws_credential_types::token_fn::provide_token_fn

source ·
pub fn provide_token_fn<'c, T, F>(f: T) -> ProvideTokenFn<'c, T>
where T: Fn() -> F + Send + Sync + 'c, F: Future<Output = Result> + Send + 'static,
Expand description

Returns a new token provider built with the given closure. This allows you to create an ProvideToken implementation from an async block that returns a crate::provider::token::Result.

§Examples

use aws_credential_types::Token;
use aws_credential_types::token_fn::provide_token_fn;

async fn load_token() -> Token {
    todo!()
}

provide_token_fn(|| async {
    // Async process to retrieve a token goes here
    let token = load_token().await;
    Ok(token)
});