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

A type-map of configuration data.

PropertyBag can be used by Request and Response to store data used to configure the SDK request pipeline.

Implementations§

source§

impl PropertyBag

source

pub fn new() -> PropertyBag

Create an empty PropertyBag.

source

pub fn insert<T: Send + Sync + 'static>(&mut self, val: T) -> Option<T>

Insert a type into this PropertyBag.

If a value of this type already existed, it will be returned.

Examples
let mut props = PropertyBag::new();

#[derive(Debug, Eq, PartialEq)]
struct Endpoint(&'static str);
assert!(props.insert(Endpoint("dynamo.amazon.com")).is_none());
assert_eq!(
    props.insert(Endpoint("kinesis.amazon.com")),
    Some(Endpoint("dynamo.amazon.com"))
);
source

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

Get a reference to a type previously inserted on this PropertyBag.

Examples
let mut props = PropertyBag::new();
assert!(props.get::<i32>().is_none());
props.insert(5i32);

assert_eq!(props.get::<i32>(), Some(&5i32));
source

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

Get a mutable reference to a type previously inserted on this PropertyBag.

Examples
let mut props = PropertyBag::new();
props.insert(String::from("Hello"));
props.get_mut::<String>().unwrap().push_str(" World");

assert_eq!(props.get::<String>().unwrap(), "Hello World");
source

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

Remove a type from this PropertyBag.

If a value of this type existed, it will be returned.

Examples
let mut props = PropertyBag::new();
props.insert(5i32);
assert_eq!(props.remove::<i32>(), Some(5i32));
assert!(props.get::<i32>().is_none());
source

pub fn clear(&mut self)

Clear the PropertyBag of all inserted extensions.

Examples
let mut props = PropertyBag::new();
props.insert(5i32);
props.clear();

assert!(props.get::<i32>().is_none());

Trait Implementations§

source§

impl Debug for PropertyBag

source§

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

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

impl Default for PropertyBag

source§

fn default() -> PropertyBag

Returns the “default value” for a type. Read more
source§

impl From<PropertyBag> for SharedPropertyBag

source§

fn from(bag: PropertyBag) -> 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,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · 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>,

const: unstable · 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.
const: unstable · 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.
const: unstable · 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