Trait qiniu_http_client::RegionsProvider
source · pub trait RegionsProvider: DynClone + Debug + Sync + Send {
fn get(&self, opts: GetOptions) -> ApiResult<GotRegion>;
fn get_all(&self, opts: GetOptions) -> ApiResult<GotRegions> { ... }
fn async_get(&self, opts: GetOptions) -> BoxFuture<'_, ApiResult<GotRegion>> { ... }
fn async_get_all(
&self,
opts: GetOptions
) -> BoxFuture<'_, ApiResult<GotRegions>> { ... }
}
Expand description
区域信息获取接口
可以获取一个区域也可以获取多个区域
同时提供阻塞获取接口和异步获取接口,异步获取接口则需要启用 async
功能
Required Methods§
sourcefn get(&self, opts: GetOptions) -> ApiResult<GotRegion>
fn get(&self, opts: GetOptions) -> ApiResult<GotRegion>
返回七牛区域信息
该方法的异步版本为 Self::async_get
。
Provided Methods§
sourcefn get_all(&self, opts: GetOptions) -> ApiResult<GotRegions>
fn get_all(&self, opts: GetOptions) -> ApiResult<GotRegions>
返回多个七牛区域信息
该方法的异步版本为 Self::async_get_all
。
Examples found in repository?
src/regions/regions_provider/mod.rs (line 66)
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 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342
fn async_get_all(&self, opts: GetOptions) -> BoxFuture<'_, ApiResult<GotRegions>> {
Box::pin(async move { self.get_all(opts) })
}
}
/// 获取区域信息的选项
#[derive(Copy, Clone, Debug, Default)]
pub struct GetOptions {}
/// 获取的区域信息
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct GotRegion {
region: Region,
lifetime: Option<Duration>,
got_at: SystemTime,
}
impl From<GotRegion> for Region {
#[inline]
fn from(result: GotRegion) -> Self {
result.region
}
}
impl From<Region> for GotRegion {
#[inline]
fn from(region: Region) -> Self {
Self {
region,
got_at: SystemTime::now(),
lifetime: None,
}
}
}
impl GotRegion {
/// 获取的区域信息
#[inline]
pub fn region(&self) -> &Region {
&self.region
}
/// 获取的区域信息的可变引用
#[inline]
pub fn region_mut(&mut self) -> &mut Region {
&mut self.region
}
/// 获取的生命周期
#[inline]
pub fn lifetime(&self) -> Option<Duration> {
self.lifetime
}
/// 获取的生命周期的可变引用
#[inline]
pub fn lifetime_mut(&mut self) -> &mut Option<Duration> {
&mut self.lifetime
}
/// 转换为区域信息
#[inline]
pub fn into_region(self) -> Region {
self.region
}
}
impl IsCacheValid for GotRegion {
fn is_valid(&self) -> bool {
if let Some(lifetime) = self.lifetime {
if let Ok(elapsed) = self.got_at.elapsed() {
elapsed <= lifetime
} else {
false // 如果发生时间倒流,则立即判定为 INVALID
}
} else {
true
}
}
}
impl PartialEq for GotRegion {
#[inline]
fn eq(&self, other: &Self) -> bool {
self.region == other.region
}
}
impl Eq for GotRegion {}
impl Deref for GotRegion {
type Target = Region;
#[inline]
fn deref(&self) -> &Self::Target {
self.region()
}
}
impl DerefMut for GotRegion {
#[inline]
fn deref_mut(&mut self) -> &mut Self::Target {
self.region_mut()
}
}
impl RegionsProvider for Region {
#[inline]
fn get(&self, _opts: GetOptions) -> ApiResult<GotRegion> {
Ok(self.to_owned().into())
}
}
impl RegionsProvider for GotRegion {
#[inline]
fn get(&self, _opts: GetOptions) -> ApiResult<GotRegion> {
Ok(self.to_owned())
}
}
/// 获取的区域列表信息
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct GotRegions {
regions: Vec<Region>,
lifetime: Option<Duration>,
got_at: SystemTime,
}
impl From<GotRegions> for Vec<Region> {
#[inline]
fn from(results: GotRegions) -> Self {
results.regions
}
}
impl From<Vec<Region>> for GotRegions {
#[inline]
fn from(regions: Vec<Region>) -> Self {
Self {
regions,
got_at: SystemTime::now(),
lifetime: None,
}
}
}
impl FromIterator<Region> for GotRegions {
#[inline]
fn from_iter<T: IntoIterator<Item = Region>>(iter: T) -> Self {
Vec::from_iter(iter).into()
}
}
impl Extend<Region> for GotRegions {
#[inline]
fn extend<T: IntoIterator<Item = Region>>(&mut self, iter: T) {
self.regions.extend(iter)
}
}
impl<'a> IntoIterator for &'a GotRegions {
type Item = &'a Region;
type IntoIter = std::slice::Iter<'a, Region>;
#[inline]
fn into_iter(self) -> Self::IntoIter {
self.regions.iter()
}
}
impl IntoIterator for GotRegions {
type Item = Region;
type IntoIter = std::vec::IntoIter<Region>;
#[inline]
fn into_iter(self) -> Self::IntoIter {
self.regions.into_iter()
}
}
impl GotRegions {
/// 获取的区域信息列表
#[inline]
pub fn regions(&self) -> &[Region] {
&self.regions
}
/// 获取的区域信息列表的可变引用
#[inline]
pub fn regions_mut(&mut self) -> &mut Vec<Region> {
&mut self.regions
}
/// 获取的生命周期
#[inline]
pub fn lifetime(&self) -> Option<Duration> {
self.lifetime
}
/// 获取的生命周期的可变引用
#[inline]
pub fn lifetime_mut(&mut self) -> &mut Option<Duration> {
&mut self.lifetime
}
/// 转换为区域信息列表
#[inline]
pub fn into_regions(self) -> Vec<Region> {
self.regions
}
}
impl IsCacheValid for GotRegions {
#[inline]
fn is_valid(&self) -> bool {
if let Some(lifetime) = self.lifetime {
if let Ok(elapsed) = self.got_at.elapsed() {
elapsed <= lifetime
} else {
false // 如果发生时间倒流,则立即判定为 INVALID
}
} else {
true
}
}
}
impl PartialEq for GotRegions {
#[inline]
fn eq(&self, other: &Self) -> bool {
self.regions == other.regions
}
}
impl Eq for GotRegions {}
impl AsRef<[Region]> for GotRegions {
#[inline]
fn as_ref(&self) -> &[Region] {
self.regions()
}
}
impl AsMut<[Region]> for GotRegions {
#[inline]
fn as_mut(&mut self) -> &mut [Region] {
self.regions_mut()
}
}
impl Deref for GotRegions {
type Target = [Region];
#[inline]
fn deref(&self) -> &Self::Target {
self.regions()
}
}
impl DerefMut for GotRegions {
#[inline]
fn deref_mut(&mut self) -> &mut Self::Target {
self.regions_mut()
}
}
impl RegionsProvider for GotRegions {
#[inline]
fn get(&self, opts: GetOptions) -> ApiResult<GotRegion> {
self.get_all(opts).map(|regions| {
regions
.into_regions()
.into_iter()
.next()
.expect("Regions are empty")
.into()
})
}
More examples
src/regions/regions_provider/all_regions_provider.rs (line 81)
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301
fn get(&self, opts: GetOptions) -> ApiResult<GotRegion> {
self.get_all(opts)
.map(|regions| regions.try_into().expect("Regions API returns empty regions"))
}
fn get_all(&self, opts: GetOptions) -> ApiResult<GotRegions> {
self.cache.get(&self.cache_key, || self.provider.get_all(opts))
}
#[inline]
#[cfg(feature = "async")]
#[cfg_attr(feature = "docs", doc(cfg(feature = "async")))]
fn async_get(&self, opts: GetOptions) -> BoxFuture<'_, ApiResult<GotRegion>> {
Box::pin(async move {
self.async_get_all(opts)
.await
.map(|regions| regions.try_into().expect("Regions API returns empty regions"))
})
}
#[inline]
#[cfg(feature = "async")]
#[cfg_attr(feature = "docs", doc(cfg(feature = "async")))]
fn async_get_all(&self, opts: GetOptions) -> BoxFuture<'_, ApiResult<GotRegions>> {
Box::pin(async move {
self.cache
.async_get(&self.cache_key, self.provider.async_get_all(opts))
.await
})
}
}
/// 七牛所有区域信息查询构建器
#[derive(Clone, Debug)]
pub struct AllRegionsProviderBuilder {
cache_lifetime: Duration,
shrink_interval: Duration,
http_client: Option<HttpClient>,
uc_endpoints: Option<Endpoints>,
credential_provider: Box<dyn CredentialProvider>,
}
impl AllRegionsProviderBuilder {
/// 缓存时长
#[inline]
pub fn cache_lifetime(mut self, cache_lifetime: Duration) -> Self {
self.cache_lifetime = cache_lifetime;
self
}
/// 清理间隔时长
#[inline]
pub fn shrink_interval(mut self, shrink_interval: Duration) -> Self {
self.shrink_interval = shrink_interval;
self
}
/// 设置 HTTP 客户端
#[inline]
pub fn http_client(mut self, http_client: HttpClient) -> Self {
self.http_client = Some(http_client);
self
}
/// 是否启用 HTTPS 协议
///
/// 默认为 HTTPS 协议
pub fn use_https(self, use_https: bool) -> Self {
self.http_client(HttpClient::build_default().use_https(use_https).build())
}
/// 设置存储空间管理终端地址列表
#[inline]
pub fn uc_endpoints(mut self, uc_endpoints: impl Into<Endpoints>) -> Self {
self.uc_endpoints = Some(uc_endpoints.into());
self
}
/// 从文件系统加载或构建七牛所有区域查询器
///
/// 可以选择是否启用自动持久化缓存功能
pub fn load_or_create_from(self, path: impl AsRef<Path>, auto_persistent: bool) -> AllRegionsProvider {
AllRegionsProvider {
cache: RegionsCache::load_or_create_from(
path.as_ref(),
auto_persistent,
self.cache_lifetime,
self.shrink_interval,
),
cache_key: self.new_cache_key(),
provider: self.new_regions_provider(),
}
}
/// 从默认文件系统路径加载或构建七牛所有区域查询器,并启用自动持久化缓存功能
#[inline]
pub fn build(self) -> AllRegionsProvider {
self.default_load_or_create_from(true)
}
/// 从默认文件系统路径加载或构建七牛所有区域查询器
///
/// 可以选择是否启用自动持久化缓存功能
pub fn default_load_or_create_from(self, auto_persistent: bool) -> AllRegionsProvider {
AllRegionsProvider {
cache: RegionsCache::default_load_or_create_from(
auto_persistent,
self.cache_lifetime,
self.shrink_interval,
),
cache_key: self.new_cache_key(),
provider: self.new_regions_provider(),
}
}
/// 构建七牛所有区域查询器
///
/// 不启用文件系统持久化缓存
pub fn in_memory(self) -> AllRegionsProvider {
AllRegionsProvider {
cache: RegionsCache::in_memory(self.cache_lifetime, self.shrink_interval),
cache_key: self.new_cache_key(),
provider: self.new_regions_provider(),
}
}
fn new_cache_key(&self) -> CacheKey {
CacheKey::new_from_endpoint(
if let Some(uc_endpoints) = self.uc_endpoints.as_ref() {
uc_endpoints
} else {
Endpoints::public_uc_endpoints()
},
None,
)
}
fn new_regions_provider(self) -> inner::AllRegionsProvider {
let mut builder = inner::AllRegionsProvider::builder(self.credential_provider);
if let Some(http_client) = self.http_client {
builder = builder.http_client(http_client);
}
if let Some(uc_endpoints) = self.uc_endpoints {
builder = builder.uc_endpoints(uc_endpoints);
}
builder.build()
}
}
mod inner {
use super::super::{
super::{
super::{ApiResult, Authorization, HttpClient, Response, ResponseError},
Endpoints, ServiceName,
},
structs::ResponseBody,
GetOptions, GotRegion, GotRegions, Region, RegionsProvider,
};
use qiniu_credential::CredentialProvider;
use std::{convert::TryFrom, fmt::Debug};
#[cfg(feature = "async")]
use futures::future::BoxFuture;
#[derive(Debug, Clone)]
pub(super) struct AllRegionsProvider {
credential_provider: Box<dyn CredentialProvider>,
http_client: HttpClient,
uc_endpoints: Endpoints,
}
impl AllRegionsProvider {
#[inline]
pub(super) fn builder(credential_provider: impl CredentialProvider + 'static) -> AllRegionsProviderBuilder {
AllRegionsProviderBuilder::new(credential_provider)
}
fn do_sync_query(&self) -> ApiResult<GotRegions> {
handle_response_body(
self.http_client
.get(&[ServiceName::Uc], &self.uc_endpoints)
.path("/regions")
.authorization(Authorization::v2(&self.credential_provider))
.accept_json()
.call()?
.parse_json::<ResponseBody>()?,
)
}
#[cfg(feature = "async")]
async fn do_async_query(&self) -> ApiResult<GotRegions> {
handle_response_body(
self.http_client
.async_get(&[ServiceName::Uc], &self.uc_endpoints)
.path("/regions")
.authorization(Authorization::v2(&self.credential_provider))
.accept_json()
.call()
.await?
.parse_json::<ResponseBody>()
.await?,
)
}
}
fn handle_response_body(response: Response<ResponseBody>) -> ApiResult<GotRegions> {
let (parts, body) = response.into_parts_and_body();
let hosts = body.into_hosts();
let min_lifetime = hosts.iter().map(|host| host.lifetime()).min();
let mut got_regions = hosts
.into_iter()
.map(|host| Region::try_from(host).map_err(|err| ResponseError::from_endpoint_parse_error(err, &parts)))
.collect::<ApiResult<GotRegions>>()?;
*got_regions.lifetime_mut() = min_lifetime;
Ok(got_regions)
}
impl RegionsProvider for AllRegionsProvider {
fn get(&self, opts: GetOptions) -> ApiResult<GotRegion> {
self.get_all(opts)
.map(|regions| regions.try_into().expect("Regions API returns empty regions"))
}
sourcefn async_get(&self, opts: GetOptions) -> BoxFuture<'_, ApiResult<GotRegion>>
fn async_get(&self, opts: GetOptions) -> BoxFuture<'_, ApiResult<GotRegion>>
Available on crate feature
async
only.异步返回七牛区域信息
sourcefn async_get_all(&self, opts: GetOptions) -> BoxFuture<'_, ApiResult<GotRegions>>
fn async_get_all(&self, opts: GetOptions) -> BoxFuture<'_, ApiResult<GotRegions>>
Available on crate feature
async
only.异步返回多个七牛区域信息
Examples found in repository?
src/regions/regions_provider/all_regions_provider.rs (line 94)
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316
fn async_get(&self, opts: GetOptions) -> BoxFuture<'_, ApiResult<GotRegion>> {
Box::pin(async move {
self.async_get_all(opts)
.await
.map(|regions| regions.try_into().expect("Regions API returns empty regions"))
})
}
#[inline]
#[cfg(feature = "async")]
#[cfg_attr(feature = "docs", doc(cfg(feature = "async")))]
fn async_get_all(&self, opts: GetOptions) -> BoxFuture<'_, ApiResult<GotRegions>> {
Box::pin(async move {
self.cache
.async_get(&self.cache_key, self.provider.async_get_all(opts))
.await
})
}
}
/// 七牛所有区域信息查询构建器
#[derive(Clone, Debug)]
pub struct AllRegionsProviderBuilder {
cache_lifetime: Duration,
shrink_interval: Duration,
http_client: Option<HttpClient>,
uc_endpoints: Option<Endpoints>,
credential_provider: Box<dyn CredentialProvider>,
}
impl AllRegionsProviderBuilder {
/// 缓存时长
#[inline]
pub fn cache_lifetime(mut self, cache_lifetime: Duration) -> Self {
self.cache_lifetime = cache_lifetime;
self
}
/// 清理间隔时长
#[inline]
pub fn shrink_interval(mut self, shrink_interval: Duration) -> Self {
self.shrink_interval = shrink_interval;
self
}
/// 设置 HTTP 客户端
#[inline]
pub fn http_client(mut self, http_client: HttpClient) -> Self {
self.http_client = Some(http_client);
self
}
/// 是否启用 HTTPS 协议
///
/// 默认为 HTTPS 协议
pub fn use_https(self, use_https: bool) -> Self {
self.http_client(HttpClient::build_default().use_https(use_https).build())
}
/// 设置存储空间管理终端地址列表
#[inline]
pub fn uc_endpoints(mut self, uc_endpoints: impl Into<Endpoints>) -> Self {
self.uc_endpoints = Some(uc_endpoints.into());
self
}
/// 从文件系统加载或构建七牛所有区域查询器
///
/// 可以选择是否启用自动持久化缓存功能
pub fn load_or_create_from(self, path: impl AsRef<Path>, auto_persistent: bool) -> AllRegionsProvider {
AllRegionsProvider {
cache: RegionsCache::load_or_create_from(
path.as_ref(),
auto_persistent,
self.cache_lifetime,
self.shrink_interval,
),
cache_key: self.new_cache_key(),
provider: self.new_regions_provider(),
}
}
/// 从默认文件系统路径加载或构建七牛所有区域查询器,并启用自动持久化缓存功能
#[inline]
pub fn build(self) -> AllRegionsProvider {
self.default_load_or_create_from(true)
}
/// 从默认文件系统路径加载或构建七牛所有区域查询器
///
/// 可以选择是否启用自动持久化缓存功能
pub fn default_load_or_create_from(self, auto_persistent: bool) -> AllRegionsProvider {
AllRegionsProvider {
cache: RegionsCache::default_load_or_create_from(
auto_persistent,
self.cache_lifetime,
self.shrink_interval,
),
cache_key: self.new_cache_key(),
provider: self.new_regions_provider(),
}
}
/// 构建七牛所有区域查询器
///
/// 不启用文件系统持久化缓存
pub fn in_memory(self) -> AllRegionsProvider {
AllRegionsProvider {
cache: RegionsCache::in_memory(self.cache_lifetime, self.shrink_interval),
cache_key: self.new_cache_key(),
provider: self.new_regions_provider(),
}
}
fn new_cache_key(&self) -> CacheKey {
CacheKey::new_from_endpoint(
if let Some(uc_endpoints) = self.uc_endpoints.as_ref() {
uc_endpoints
} else {
Endpoints::public_uc_endpoints()
},
None,
)
}
fn new_regions_provider(self) -> inner::AllRegionsProvider {
let mut builder = inner::AllRegionsProvider::builder(self.credential_provider);
if let Some(http_client) = self.http_client {
builder = builder.http_client(http_client);
}
if let Some(uc_endpoints) = self.uc_endpoints {
builder = builder.uc_endpoints(uc_endpoints);
}
builder.build()
}
}
mod inner {
use super::super::{
super::{
super::{ApiResult, Authorization, HttpClient, Response, ResponseError},
Endpoints, ServiceName,
},
structs::ResponseBody,
GetOptions, GotRegion, GotRegions, Region, RegionsProvider,
};
use qiniu_credential::CredentialProvider;
use std::{convert::TryFrom, fmt::Debug};
#[cfg(feature = "async")]
use futures::future::BoxFuture;
#[derive(Debug, Clone)]
pub(super) struct AllRegionsProvider {
credential_provider: Box<dyn CredentialProvider>,
http_client: HttpClient,
uc_endpoints: Endpoints,
}
impl AllRegionsProvider {
#[inline]
pub(super) fn builder(credential_provider: impl CredentialProvider + 'static) -> AllRegionsProviderBuilder {
AllRegionsProviderBuilder::new(credential_provider)
}
fn do_sync_query(&self) -> ApiResult<GotRegions> {
handle_response_body(
self.http_client
.get(&[ServiceName::Uc], &self.uc_endpoints)
.path("/regions")
.authorization(Authorization::v2(&self.credential_provider))
.accept_json()
.call()?
.parse_json::<ResponseBody>()?,
)
}
#[cfg(feature = "async")]
async fn do_async_query(&self) -> ApiResult<GotRegions> {
handle_response_body(
self.http_client
.async_get(&[ServiceName::Uc], &self.uc_endpoints)
.path("/regions")
.authorization(Authorization::v2(&self.credential_provider))
.accept_json()
.call()
.await?
.parse_json::<ResponseBody>()
.await?,
)
}
}
fn handle_response_body(response: Response<ResponseBody>) -> ApiResult<GotRegions> {
let (parts, body) = response.into_parts_and_body();
let hosts = body.into_hosts();
let min_lifetime = hosts.iter().map(|host| host.lifetime()).min();
let mut got_regions = hosts
.into_iter()
.map(|host| Region::try_from(host).map_err(|err| ResponseError::from_endpoint_parse_error(err, &parts)))
.collect::<ApiResult<GotRegions>>()?;
*got_regions.lifetime_mut() = min_lifetime;
Ok(got_regions)
}
impl RegionsProvider for AllRegionsProvider {
fn get(&self, opts: GetOptions) -> ApiResult<GotRegion> {
self.get_all(opts)
.map(|regions| regions.try_into().expect("Regions API returns empty regions"))
}
#[inline]
fn get_all(&self, _opts: GetOptions) -> ApiResult<GotRegions> {
self.do_sync_query().map(GotRegions::from)
}
#[cfg(feature = "async")]
#[cfg_attr(feature = "docs", doc(cfg(feature = "async")))]
fn async_get(&self, opts: GetOptions) -> BoxFuture<'_, ApiResult<GotRegion>> {
Box::pin(async move {
self.async_get_all(opts)
.await
.map(|regions| regions.try_into().expect("Regions API returns empty regions"))
})
}
More examples
Trait Implementations§
source§impl<'clone> Clone for Box<dyn RegionsProvider + 'clone>
impl<'clone> Clone for Box<dyn RegionsProvider + 'clone>
Implementations on Foreign Types§
source§impl<'a, T: 'a + RegionsProvider + ?Sized> RegionsProvider for &'a Twhere
&'a T: DynClone + Debug + Sync + Send,
impl<'a, T: 'a + RegionsProvider + ?Sized> RegionsProvider for &'a Twhere
&'a T: DynClone + Debug + Sync + Send,
fn get(&self, opts: GetOptions) -> ApiResult<GotRegion>
fn get_all(&self, opts: GetOptions) -> ApiResult<GotRegions>
source§fn async_get(&self, opts: GetOptions) -> BoxFuture<'_, ApiResult<GotRegion>>
fn async_get(&self, opts: GetOptions) -> BoxFuture<'_, ApiResult<GotRegion>>
Available on crate feature
async
only.source§fn async_get_all(&self, opts: GetOptions) -> BoxFuture<'_, ApiResult<GotRegions>>
fn async_get_all(&self, opts: GetOptions) -> BoxFuture<'_, ApiResult<GotRegions>>
Available on crate feature
async
only.source§impl<'a, T: 'a + RegionsProvider + ?Sized> RegionsProvider for &'a mut Twhere
&'a mut T: DynClone + Debug + Sync + Send,
impl<'a, T: 'a + RegionsProvider + ?Sized> RegionsProvider for &'a mut Twhere
&'a mut T: DynClone + Debug + Sync + Send,
fn get(&self, opts: GetOptions) -> ApiResult<GotRegion>
fn get_all(&self, opts: GetOptions) -> ApiResult<GotRegions>
source§fn async_get(&self, opts: GetOptions) -> BoxFuture<'_, ApiResult<GotRegion>>
fn async_get(&self, opts: GetOptions) -> BoxFuture<'_, ApiResult<GotRegion>>
Available on crate feature
async
only.source§fn async_get_all(&self, opts: GetOptions) -> BoxFuture<'_, ApiResult<GotRegions>>
fn async_get_all(&self, opts: GetOptions) -> BoxFuture<'_, ApiResult<GotRegions>>
Available on crate feature
async
only.source§impl<T: RegionsProvider + ?Sized> RegionsProvider for Box<T>where
Box<T>: DynClone + Debug + Sync + Send,
impl<T: RegionsProvider + ?Sized> RegionsProvider for Box<T>where
Box<T>: DynClone + Debug + Sync + Send,
fn get(&self, opts: GetOptions) -> ApiResult<GotRegion>
fn get_all(&self, opts: GetOptions) -> ApiResult<GotRegions>
source§fn async_get(&self, opts: GetOptions) -> BoxFuture<'_, ApiResult<GotRegion>>
fn async_get(&self, opts: GetOptions) -> BoxFuture<'_, ApiResult<GotRegion>>
Available on crate feature
async
only.source§fn async_get_all(&self, opts: GetOptions) -> BoxFuture<'_, ApiResult<GotRegions>>
fn async_get_all(&self, opts: GetOptions) -> BoxFuture<'_, ApiResult<GotRegions>>
Available on crate feature
async
only.source§impl<T: RegionsProvider + ?Sized> RegionsProvider for Rc<T>where
Rc<T>: DynClone + Debug + Sync + Send,
impl<T: RegionsProvider + ?Sized> RegionsProvider for Rc<T>where
Rc<T>: DynClone + Debug + Sync + Send,
fn get(&self, opts: GetOptions) -> ApiResult<GotRegion>
fn get_all(&self, opts: GetOptions) -> ApiResult<GotRegions>
source§fn async_get(&self, opts: GetOptions) -> BoxFuture<'_, ApiResult<GotRegion>>
fn async_get(&self, opts: GetOptions) -> BoxFuture<'_, ApiResult<GotRegion>>
Available on crate feature
async
only.source§fn async_get_all(&self, opts: GetOptions) -> BoxFuture<'_, ApiResult<GotRegions>>
fn async_get_all(&self, opts: GetOptions) -> BoxFuture<'_, ApiResult<GotRegions>>
Available on crate feature
async
only.source§impl<T: RegionsProvider + ?Sized> RegionsProvider for Arc<T>where
Arc<T>: DynClone + Debug + Sync + Send,
impl<T: RegionsProvider + ?Sized> RegionsProvider for Arc<T>where
Arc<T>: DynClone + Debug + Sync + Send,
fn get(&self, opts: GetOptions) -> ApiResult<GotRegion>
fn get_all(&self, opts: GetOptions) -> ApiResult<GotRegions>
source§fn async_get(&self, opts: GetOptions) -> BoxFuture<'_, ApiResult<GotRegion>>
fn async_get(&self, opts: GetOptions) -> BoxFuture<'_, ApiResult<GotRegion>>
Available on crate feature
async
only.source§fn async_get_all(&self, opts: GetOptions) -> BoxFuture<'_, ApiResult<GotRegions>>
fn async_get_all(&self, opts: GetOptions) -> BoxFuture<'_, ApiResult<GotRegions>>
Available on crate feature
async
only.