use crate::client::orchestrator::Future;
use aws_smithy_types::config_bag::{Storable, StoreReplace};
use aws_smithy_types::endpoint::Endpoint;
use aws_smithy_types::type_erasure::TypeErasedBox;
use std::fmt;
use std::sync::Arc;
#[derive(Debug)]
pub struct EndpointResolverParams(TypeErasedBox);
impl EndpointResolverParams {
pub fn new<T: fmt::Debug + Send + Sync + 'static>(params: T) -> Self {
Self(TypeErasedBox::new(params))
}
pub fn get<T: fmt::Debug + Send + Sync + 'static>(&self) -> Option<&T> {
self.0.downcast_ref()
}
}
impl Storable for EndpointResolverParams {
type Storer = StoreReplace<Self>;
}
pub trait EndpointResolver: Send + Sync + fmt::Debug {
fn resolve_endpoint(&self, params: &EndpointResolverParams) -> Future<Endpoint>;
}
#[derive(Clone, Debug)]
pub struct SharedEndpointResolver(Arc<dyn EndpointResolver>);
impl SharedEndpointResolver {
pub fn new(endpoint_resolver: impl EndpointResolver + 'static) -> Self {
Self(Arc::new(endpoint_resolver))
}
}
impl EndpointResolver for SharedEndpointResolver {
fn resolve_endpoint(&self, params: &EndpointResolverParams) -> Future<Endpoint> {
self.0.resolve_endpoint(params)
}
}