Struct aws_smithy_runtime_api::config_bag::ConfigBag
source · pub struct ConfigBag { /* private fields */ }Expand description
Layered Configuration Structure
ConfigBag is the “unlocked” form of the bag. Only the top layer of the bag may be unlocked.
Implementations§
source§impl ConfigBag
impl ConfigBag
pub fn base() -> Self
pub fn store_put<T>(&mut self, item: T) -> &mut Selfwhere T: Storable<Storer = StoreReplace<T>>,
pub fn store_or_unset<T>(&mut self, item: Option<T>) -> &mut Selfwhere T: Storable<Storer = StoreReplace<T>>,
sourcepub fn store_append<T>(&mut self, item: T) -> &mut Selfwhere
T: Storable<Storer = StoreAppend<T>>,
pub fn store_append<T>(&mut self, item: T) -> &mut Selfwhere T: Storable<Storer = StoreAppend<T>>,
This can only be used for types that use StoreAppend
use aws_smithy_runtime_api::config_bag::{ConfigBag, Storable, StoreAppend, StoreReplace};
let mut bag = ConfigBag::base();
#[derive(Debug, PartialEq, Eq)]
struct Interceptor(&'static str);
impl Storable for Interceptor {
type Storer = StoreAppend<Interceptor>;
}
bag.store_append(Interceptor("123"));
bag.store_append(Interceptor("456"));
assert_eq!(
bag.load::<Interceptor>().collect::<Vec<_>>(),
vec![&Interceptor("456"), &Interceptor("123")]
);pub fn clear<T>(&mut self)where T: Storable<Storer = StoreAppend<T>>,
pub fn load<T: Storable>(&self) -> <T::Storer as Store>::ReturnedType<'_>
sourcepub fn get<T: Send + Sync + Debug + 'static>(&self) -> Option<&T>
pub fn get<T: Send + Sync + Debug + 'static>(&self) -> Option<&T>
Retrieve the value of type T from the bag if exists
sourcepub fn get_mut<T>(&mut self) -> Option<&mut T>where
T: Storable<Storer = StoreReplace<T>> + Send + Sync + Debug + Clone + 'static,
pub fn get_mut<T>(&mut self) -> Option<&mut T>where T: Storable<Storer = StoreReplace<T>> + Send + Sync + Debug + Clone + 'static,
Returns a mutable reference to T if it is stored in the top layer of the bag
sourcepub fn get_mut_or_default<T>(&mut self) -> &mut Twhere
T: Storable<Storer = StoreReplace<T>> + Send + Sync + Debug + Clone + Default + 'static,
pub fn get_mut_or_default<T>(&mut self) -> &mut Twhere T: Storable<Storer = StoreReplace<T>> + Send + Sync + Debug + Clone + Default + 'static,
Returns a mutable reference to T if it is stored in the top layer of the bag
- If
Tis in a deeper layer of the bag, that value will be cloned and inserted into the top layer - If
Tis not present in the bag, theDefaultimplementation will be used.
sourcepub fn get_mut_or_else<T>(&mut self, default: impl Fn() -> T) -> &mut Twhere
T: Storable<Storer = StoreReplace<T>> + Send + Sync + Debug + Clone + 'static,
pub fn get_mut_or_else<T>(&mut self, default: impl Fn() -> T) -> &mut Twhere T: Storable<Storer = StoreReplace<T>> + Send + Sync + Debug + Clone + 'static,
Returns a mutable reference to T if it is stored in the top layer of the bag
- If
Tis in a deeper layer of the bag, that value will be cloned and inserted into the top layer - If
Tis not present in the bag,defaultwill be used to construct a new value
sourcepub fn put<T: Send + Sync + Debug + 'static>(&mut self, value: T) -> &mut Self
pub fn put<T: Send + Sync + Debug + 'static>(&mut self, value: T) -> &mut Self
Insert value into the bag
sourcepub fn freeze(self) -> FrozenConfigBag
pub fn freeze(self) -> FrozenConfigBag
Freeze this layer by wrapping it in an Arc
This prevents further items from being added to this layer, but additional layers can be added to the bag.
sourcepub fn with_fn(
self,
name: &'static str,
next: impl Fn(&mut ConfigBag)
) -> ConfigBag
pub fn with_fn( self, name: &'static str, next: impl Fn(&mut ConfigBag) ) -> ConfigBag
Add another layer to this configuration bag
Hint: If you want to re-use this layer, call freeze first.
use aws_smithy_runtime_api::config_bag::ConfigBag;
let bag = ConfigBag::base();
let first_layer = bag.with_fn("a", |b: &mut ConfigBag| { b.put("a"); }).freeze();
let second_layer = first_layer.with_fn("other", |b: &mut ConfigBag| { b.put(1i32); });
// The number is only in the second layer
assert_eq!(first_layer.get::<i32>(), None);
assert_eq!(second_layer.get::<i32>(), Some(&1));
// The string is in both layers
assert_eq!(first_layer.get::<&'static str>(), Some(&"a"));
assert_eq!(second_layer.get::<&'static str>(), Some(&"a"));pub fn add_layer(self, name: impl Into<Cow<'static, str>>) -> ConfigBag
pub fn sourced_get<T: Store>(&self) -> T::ReturnedType<'_>
Trait Implementations§
source§impl ConfigBagAccessors for ConfigBag
impl ConfigBagAccessors for ConfigBag
fn auth_option_resolver_params(&self) -> &AuthOptionResolverParams
fn set_auth_option_resolver_params( &mut self, auth_option_resolver_params: AuthOptionResolverParams )
fn auth_option_resolver(&self) -> &dyn AuthOptionResolver
fn set_auth_option_resolver( &mut self, auth_option_resolver: impl AuthOptionResolver + 'static )
fn endpoint_resolver_params(&self) -> &EndpointResolverParams
fn set_endpoint_resolver_params( &mut self, endpoint_resolver_params: EndpointResolverParams )
fn endpoint_resolver(&self) -> &dyn EndpointResolver
fn set_endpoint_resolver( &mut self, endpoint_resolver: impl EndpointResolver + 'static )
fn identity_resolvers(&self) -> &IdentityResolvers
fn set_identity_resolvers(&mut self, identity_resolvers: IdentityResolvers)
fn connection(&self) -> &dyn Connection
fn set_connection(&mut self, connection: impl Connection + 'static)
fn http_auth_schemes(&self) -> &HttpAuthSchemes
fn set_http_auth_schemes(&mut self, http_auth_schemes: HttpAuthSchemes)
fn request_serializer(&self) -> &dyn RequestSerializer
fn set_request_serializer( &mut self, request_serializer: impl RequestSerializer + 'static )
fn response_deserializer(&self) -> &dyn ResponseDeserializer
fn set_response_deserializer( &mut self, response_deserializer: impl ResponseDeserializer + 'static )
fn retry_classifiers(&self) -> &RetryClassifiers
fn set_retry_classifiers(&mut self, retry_classifiers: RetryClassifiers)
fn retry_strategy(&self) -> &dyn RetryStrategy
fn set_retry_strategy(&mut self, retry_strategy: impl RetryStrategy + 'static)
fn request_time(&self) -> Option<RequestTime>
fn set_request_time(&mut self, request_time: RequestTime)
fn sleep_impl(&self) -> Option<Arc<dyn AsyncSleep>>
fn set_sleep_impl(&mut self, sleep_impl: Option<Arc<dyn AsyncSleep>>)
Auto Trait Implementations§
impl !RefUnwindSafe for ConfigBag
impl Send for ConfigBag
impl Sync for ConfigBag
impl Unpin for ConfigBag
impl !UnwindSafe for ConfigBag
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more