Struct aws_smithy_types::config_bag::ConfigBag
source · pub struct ConfigBag { /* private fields */ }
Expand description
Layered configuration structure
See the module docs for more documentation.
Implementations§
source§impl ConfigBag
impl ConfigBag
sourcepub fn of_layers(layers: impl IntoIterator<Item = Layer>) -> Self
pub fn of_layers(layers: impl IntoIterator<Item = Layer>) -> Self
Create a ConfigBag
consisting of the given layers.
sourcepub fn push_layer(&mut self, layer: Layer) -> &mut Self
pub fn push_layer(&mut self, layer: Layer) -> &mut Self
Add the given layer to the config bag.
Add a frozen/shared layer to the config bag.
sourcepub fn interceptor_state(&mut self) -> &mut Layer
pub fn interceptor_state(&mut self) -> &mut Layer
Return a reference to the mutable interceptor state.
sourcepub fn load<T: Storable>(&self) -> <T::Storer as Store>::ReturnedType<'_>
pub fn load<T: Storable>(&self) -> <T::Storer as Store>::ReturnedType<'_>
Load a value (or values) of type T
depending on how T
implements Storable
sourcepub fn get_mut<T>(&mut self) -> Option<&mut T>
pub fn get_mut<T>(&mut self) -> Option<&mut T>
Return 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 T
pub fn get_mut_or_default<T>(&mut self) -> &mut 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, theDefault
implementation will be used.
sourcepub fn get_mut_or_else<T>(&mut self, default: impl Fn() -> T) -> &mut T
pub fn get_mut_or_else<T>(&mut self, default: impl Fn() -> T) -> &mut 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
sourcepub fn with_fn(
self,
name: impl Into<Cow<'static, str>>,
next: impl Fn(&mut Layer),
) -> ConfigBag
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)));
sourcepub fn add_layer(self, name: impl Into<Cow<'static, str>>) -> ConfigBag
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
sourcepub fn sourced_get<T: Store>(&self) -> T::ReturnedType<'_>
pub fn sourced_get<T: Store>(&self) -> T::ReturnedType<'_>
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§
Auto Trait Implementations§
impl Freeze for ConfigBag
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more