logo
pub struct Extensions { /* private fields */ }
Expand description

A type map for request extensions.

All entries into this map must be owned types (or static references).

Implementations

Creates an empty Extensions.

Insert an item into the map.

If an item of this type was already stored, it will be replaced and returned.

let mut map = Extensions::new();
assert_eq!(map.insert(""), None);
assert_eq!(map.insert(1u32), None);
assert_eq!(map.insert(2u32), Some(1u32));
assert_eq!(*map.get::<u32>().unwrap(), 2u32);

Check if map contains an item of a given type.

let mut map = Extensions::new();
assert!(!map.contains::<u32>());

assert_eq!(map.insert(1u32), None);
assert!(map.contains::<u32>());

Get a reference to an item of a given type.

let mut map = Extensions::new();
map.insert(1u32);
assert_eq!(map.get::<u32>(), Some(&1u32));

Get a mutable reference to an item of a given type.

let mut map = Extensions::new();
map.insert(1u32);
assert_eq!(map.get_mut::<u32>(), Some(&mut 1u32));

Remove an item from the map of a given type.

If an item of this type was already stored, it will be returned.

let mut map = Extensions::new();

map.insert(1u32);
assert_eq!(map.get::<u32>(), Some(&1u32));

assert_eq!(map.remove::<u32>(), Some(1u32));
assert!(!map.contains::<u32>());

Clear the Extensions of all inserted extensions.

let mut map = Extensions::new();

map.insert(1u32);
assert!(map.contains::<u32>());

map.clear();
assert!(!map.contains::<u32>());

Extends self with the items from another Extensions.

Trait Implementations

Formats the value using the given formatter. Read more

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

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

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

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

Calls U::from(self).

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

Should always be Self

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

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

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