use std::future::Future;
use std::pin::Pin;
use crate::error::Result;
pub trait CredentialProvider<C>: Send + Sync {
fn credentials(&self) -> impl Future<Output = Result<C>> + Send;
}
impl<C, F, Fut> CredentialProvider<C> for F
where
F: Fn() -> Fut + Send + Sync,
Fut: Future<Output = Result<C>> + Send,
{
fn credentials(&self) -> impl Future<Output = Result<C>> + Send {
self()
}
}
pub(crate) trait ErasedCredentialProvider<C>: Send + Sync {
fn credentials_erased(&self) -> Pin<Box<dyn Future<Output = Result<C>> + Send + '_>>;
}
impl<C: 'static, T: CredentialProvider<C>> ErasedCredentialProvider<C> for T {
fn credentials_erased(&self) -> Pin<Box<dyn Future<Output = Result<C>> + Send + '_>> {
Box::pin(self.credentials())
}
}