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

source

pub fn base() -> Self

source

pub fn store_put<T>(&mut self, item: T) -> &mut Selfwhere T: Storable<Storer = StoreReplace<T>>,

source

pub fn store_or_unset<T>(&mut self, item: Option<T>) -> &mut Selfwhere T: Storable<Storer = StoreReplace<T>>,

source

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")]
);
source

pub fn clear<T>(&mut self)where T: Storable<Storer = StoreAppend<T>>,

source

pub fn load<T: Storable>(&self) -> <T::Storer as Store>::ReturnedType<'_>

source

pub fn get<T: Send + Sync + Debug + 'static>(&self) -> Option<&T>

Retrieve the value of type T from the bag if exists

source

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

source

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 T is in a deeper layer of the bag, that value will be cloned and inserted into the top layer
  • If T is not present in the bag, the Default implementation will be used.
source

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 T is in a deeper layer of the bag, that value will be cloned and inserted into the top layer
  • If T is not present in the bag, default will be used to construct a new value
source

pub fn put<T: Send + Sync + Debug + 'static>(&mut self, value: T) -> &mut Self

Insert value into the bag

source

pub fn unset<T: Send + Sync + Debug + 'static>(&mut self) -> &mut Self

Remove T from this bag

source

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.

source

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"));
source

pub fn add_layer(self, name: impl Into<Cow<'static, str>>) -> ConfigBag

source

pub fn sourced_get<T: Store>(&self) -> T::ReturnedType<'_>

Trait Implementations§

source§

impl ConfigBagAccessors for ConfigBag

source§

fn auth_option_resolver_params(&self) -> &AuthOptionResolverParams

source§

fn set_auth_option_resolver_params( &mut self, auth_option_resolver_params: AuthOptionResolverParams )

source§

fn auth_option_resolver(&self) -> &dyn AuthOptionResolver

source§

fn set_auth_option_resolver( &mut self, auth_option_resolver: impl AuthOptionResolver + 'static )

source§

fn endpoint_resolver_params(&self) -> &EndpointResolverParams

source§

fn set_endpoint_resolver_params( &mut self, endpoint_resolver_params: EndpointResolverParams )

source§

fn endpoint_resolver(&self) -> &dyn EndpointResolver

source§

fn set_endpoint_resolver( &mut self, endpoint_resolver: impl EndpointResolver + 'static )

source§

fn identity_resolvers(&self) -> &IdentityResolvers

source§

fn set_identity_resolvers(&mut self, identity_resolvers: IdentityResolvers)

source§

fn connection(&self) -> &dyn Connection

source§

fn set_connection(&mut self, connection: impl Connection + 'static)

source§

fn http_auth_schemes(&self) -> &HttpAuthSchemes

source§

fn set_http_auth_schemes(&mut self, http_auth_schemes: HttpAuthSchemes)

source§

fn request_serializer(&self) -> &dyn RequestSerializer

source§

fn set_request_serializer( &mut self, request_serializer: impl RequestSerializer + 'static )

source§

fn response_deserializer(&self) -> &dyn ResponseDeserializer

source§

fn set_response_deserializer( &mut self, response_deserializer: impl ResponseDeserializer + 'static )

source§

fn retry_classifiers(&self) -> &RetryClassifiers

source§

fn set_retry_classifiers(&mut self, retry_classifiers: RetryClassifiers)

source§

fn retry_strategy(&self) -> &dyn RetryStrategy

source§

fn set_retry_strategy(&mut self, retry_strategy: impl RetryStrategy + 'static)

source§

fn request_time(&self) -> Option<RequestTime>

source§

fn set_request_time(&mut self, request_time: RequestTime)

source§

fn sleep_impl(&self) -> Option<Arc<dyn AsyncSleep>>

source§

fn set_sleep_impl(&mut self, sleep_impl: Option<Arc<dyn AsyncSleep>>)

source§

impl Debug for ConfigBag

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl From<ConfigBag> for FrozenConfigBag

source§

fn from(bag: ConfigBag) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more