pub struct ConfigBag { /* private fields */ }
Expand description

Layered configuration structure

See the module docs for more documentation.

Implementations§

§

impl ConfigBag

pub fn base() -> ConfigBag

Create a new config bag “base”.

pub fn of_layers(layers: impl IntoIterator<Item = Layer>) -> ConfigBag

Create a ConfigBag consisting of the given layers.

pub fn push_layer(&mut self, layer: Layer) -> &mut ConfigBag

Add the given layer to the config bag.

pub fn push_shared_layer(&mut self, layer: FrozenLayer) -> &mut ConfigBag

Add a frozen/shared layer to the config bag.

pub fn interceptor_state(&mut self) -> &mut Layer

Return a reference to the mutable interceptor state.

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

Load a value (or values) of type T depending on how T implements [Storable]

pub fn get_mut<T>(&mut self) -> Option<&mut T>where T: Send + Sync + Debug + Clone + 'static + Storable<Storer = StoreReplace<T>>,

Return a mutable reference to T if it is stored in the top layer of the bag

pub fn get_mut_or_default<T>(&mut self) -> &mut Twhere T: Send + Sync + Debug + Clone + Default + 'static + Storable<Storer = StoreReplace<T>>,

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.

pub fn get_mut_or_else<T>(&mut self, default: impl Fn() -> T) -> &mut Twhere T: Send + Sync + Debug + Clone + 'static + Storable<Storer = StoreReplace<T>>,

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

pub fn with_fn( self, name: impl Into<Cow<'static, str>>, next: impl Fn(&mut Layer) ) -> ConfigBag

Add another layer to this configuration bag

Hint: If you want to re-use this layer, call freeze first.

Examples
use aws_smithy_types::config_bag::{ConfigBag, Layer, Storable, StoreReplace};

#[derive(Debug, Eq, PartialEq)]
struct ExampleStr(&'static str);
impl Storable for ExampleStr {
    type Storer = StoreReplace<Self>;
}

#[derive(Debug, Eq, PartialEq)]
struct ExampleInt(i32);
impl Storable for ExampleInt {
    type Storer = StoreReplace<Self>;
}

let mut bag = ConfigBag::base();
bag = bag.with_fn("first", |layer: &mut Layer| { layer.store_put(ExampleStr("a")); });

// We can now load the example string out
assert_eq!(bag.load::<ExampleStr>(), Some(&ExampleStr("a")));

// But there isn't a number stored in the bag yet
assert_eq!(bag.load::<ExampleInt>(), None);

// Add a layer with an example int
bag = bag.with_fn("second", |layer: &mut Layer| { layer.store_put(ExampleInt(1)); });

// Now the example int can be retrieved
assert_eq!(bag.load::<ExampleInt>(), Some(&ExampleInt(1)));

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

Add a new layer with name after freezing the top layer so far

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

Return a value (or values) of type T depending on how it has been stored in a ConfigBag

It flexibly chooses to return a single value vs. an iterator of values depending on how T implements a [Store] trait.

Trait Implementations§

§

impl Debug for ConfigBag

§

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

Formats the value using the given formatter. Read more

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
§

impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

§

impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere T: 'a,

§

fn implicit( self, class: Class, constructed: bool, tag: u32 ) -> TaggedParser<'a, Implicit, Self, E>

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> Same<T> for T

§

type Output = T

Should always be Self
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.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

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