Struct actix_http::Extensions

source ·
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§

source§

impl Extensions

source

pub fn new() -> Extensions

Creates an empty Extensions.

source

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

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

pub fn contains<T: 'static>(&self) -> bool

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

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

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

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

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

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

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

pub fn clear(&mut self)

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

pub fn extend(&mut self, other: Extensions)

Extends self with the items from another Extensions.

Trait Implementations§

source§

impl Debug for Extensions

source§

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

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

impl Default for Extensions

source§

fn default() -> Extensions

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

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where 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 T
where 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 for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where 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 T
where 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<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

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