1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
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))
}
}