use crate::provider::token::Result as TokenResult;
use crate::provider::Result as CredsResult;
use aws_smithy_async::future::now_or_later::NowOrLater;
use std::future::Future;
use std::pin::Pin;
use std::task::{Context, Poll};
type BoxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + Send + 'a>>;
#[derive(Debug)]
pub struct ProvideCredentials<'a>(NowOrLater<CredsResult, BoxFuture<'a, CredsResult>>);
impl<'a> ProvideCredentials<'a> {
pub fn new(future: impl Future<Output = CredsResult> + Send + 'a) -> Self {
ProvideCredentials(NowOrLater::new(Box::pin(future)))
}
pub fn ready(credentials: CredsResult) -> Self {
ProvideCredentials(NowOrLater::ready(credentials))
}
}
impl Future for ProvideCredentials<'_> {
type Output = CredsResult;
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
Pin::new(&mut self.0).poll(cx)
}
}
#[derive(Debug)]
pub struct ProvideToken<'a>(NowOrLater<TokenResult, BoxFuture<'a, TokenResult>>);
impl<'a> ProvideToken<'a> {
pub fn new(future: impl Future<Output = TokenResult> + Send + 'a) -> Self {
ProvideToken(NowOrLater::new(Box::pin(future)))
}
pub fn ready(credentials: TokenResult) -> Self {
ProvideToken(NowOrLater::ready(credentials))
}
}
impl Future for ProvideToken<'_> {
type Output = TokenResult;
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
Pin::new(&mut self.0).poll(cx)
}
}