mod service_name;
pub use service_name::{InvalidServiceName, ServiceName};
mod endpoints;
pub use endpoints::{Endpoints, EndpointsBuilder};
mod regions_provider_endpoints;
pub use regions_provider_endpoints::RegionsProviderEndpoints;
mod bucket_domains_provider;
pub use bucket_domains_provider::{BucketDomainsProvider, BucketDomainsQueryer, BucketDomainsQueryerBuilder};
mod endpoints_cache;
use super::{super::ApiResult, Endpoint};
use auto_impl::auto_impl;
use dyn_clonable::clonable;
use std::{borrow::Cow, fmt, mem::take};
#[cfg(feature = "async")]
type BoxFuture<'a, T> = std::pin::Pin<Box<dyn std::future::Future<Output = T> + 'a + Send>>;
#[clonable]
#[auto_impl(&, &mut, Box, Rc, Arc)]
pub trait EndpointsProvider: Clone + fmt::Debug + Send + Sync {
fn get_endpoints<'e>(&'e self, options: GetOptions<'_>) -> ApiResult<Cow<'e, Endpoints>>;
#[inline]
#[cfg(feature = "async")]
#[cfg_attr(feature = "docs", doc(cfg(feature = "async")))]
fn async_get_endpoints<'a>(&'a self, options: GetOptions<'a>) -> BoxFuture<'a, ApiResult<Cow<'a, Endpoints>>> {
Box::pin(async move { self.get_endpoints(options) })
}
}
#[derive(Copy, Clone, Debug, Default)]
pub struct GetOptions<'a> {
service_names: &'a [ServiceName],
}
impl<'a> GetOptions<'a> {
#[inline]
pub fn builder() -> GetOptionsBuilder<'a> {
Default::default()
}
#[inline]
pub fn service_names(&'a self) -> &'a [ServiceName] {
self.service_names
}
}
#[derive(Clone, Debug, Default)]
pub struct GetOptionsBuilder<'a>(GetOptions<'a>);
impl<'a> GetOptionsBuilder<'a> {
#[inline]
pub fn service_names(&mut self, service_names: &'a [ServiceName]) -> &mut Self {
self.0.service_names = service_names;
self
}
#[inline]
pub fn build(&mut self) -> GetOptions<'a> {
take(&mut self.0)
}
}
impl EndpointsProvider for Endpoint {
#[inline]
fn get_endpoints<'e>(&'e self, _services: GetOptions<'_>) -> ApiResult<Cow<'e, Endpoints>> {
Ok(Cow::Owned(Endpoints::builder(self.to_owned()).build()))
}
}
impl EndpointsProvider for Endpoints {
#[inline]
fn get_endpoints<'e>(&'e self, _services: GetOptions<'_>) -> ApiResult<Cow<'e, Endpoints>> {
Ok(Cow::Borrowed(self))
}
}