Skip to content

Commit 1e27efe

Browse files
authored
Make a minor optimization to AuthOptionResolver (#2557)
1 parent eff7437 commit 1e27efe

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

rust-runtime/aws-smithy-runtime-api/src/client/auth/option_resolver.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use crate::client::orchestrator::{
77
AuthOptionResolver, AuthOptionResolverParams, BoxError, HttpAuthOption,
88
};
9+
use std::borrow::Cow;
910

1011
/// New-type around a `Vec<HttpAuthOption>` that implements `AuthOptionResolver`.
1112
///
@@ -23,11 +24,11 @@ impl AuthOptionListResolver {
2324
}
2425

2526
impl AuthOptionResolver for AuthOptionListResolver {
26-
fn resolve_auth_options(
27-
&self,
27+
fn resolve_auth_options<'a>(
28+
&'a self,
2829
_params: &AuthOptionResolverParams,
29-
) -> Result<Vec<HttpAuthOption>, BoxError> {
30-
Ok(self.auth_options.clone())
30+
) -> Result<Cow<'a, [HttpAuthOption]>, BoxError> {
31+
Ok(Cow::Borrowed(&self.auth_options))
3132
}
3233
}
3334

rust-runtime/aws-smithy-runtime-api/src/client/orchestrator.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use crate::type_erasure::{TypeErasedBox, TypedBox};
1111
use aws_smithy_http::body::SdkBody;
1212
use aws_smithy_http::property_bag::PropertyBag;
1313
use std::any::Any;
14+
use std::borrow::Cow;
1415
use std::fmt::Debug;
1516
use std::future::Future;
1617
use std::pin::Pin;
@@ -72,17 +73,17 @@ impl AuthOptionResolverParams {
7273
}
7374

7475
pub trait AuthOptionResolver: Send + Sync + Debug {
75-
fn resolve_auth_options(
76-
&self,
76+
fn resolve_auth_options<'a>(
77+
&'a self,
7778
params: &AuthOptionResolverParams,
78-
) -> Result<Vec<HttpAuthOption>, BoxError>;
79+
) -> Result<Cow<'a, [HttpAuthOption]>, BoxError>;
7980
}
8081

8182
impl AuthOptionResolver for Box<dyn AuthOptionResolver> {
82-
fn resolve_auth_options(
83-
&self,
83+
fn resolve_auth_options<'a>(
84+
&'a self,
8485
params: &AuthOptionResolverParams,
85-
) -> Result<Vec<HttpAuthOption>, BoxError> {
86+
) -> Result<Cow<'a, [HttpAuthOption]>, BoxError> {
8687
(**self).resolve_auth_options(params)
8788
}
8889
}

rust-runtime/aws-smithy-runtime/src/client/orchestrator/auth.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub(super) async fn orchestrate_auth(
2424
.map_err(construction_failure)?;
2525
let identity_resolvers = cfg.identity_resolvers();
2626

27-
for option in auth_options {
27+
for option in auth_options.as_ref() {
2828
let scheme_id = option.scheme_id();
2929
let scheme_properties = option.properties();
3030
if let Some(auth_scheme) = cfg.http_auth_schemes().scheme(scheme_id) {

0 commit comments

Comments
 (0)