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
sourceimpl Extensions
impl Extensions
sourcepub fn new() -> Extensions
pub fn new() -> Extensions
Creates an empty Extensions
.
sourcepub fn insert<T: 'static>(&mut self, val: T) -> Option<T>
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);
sourcepub fn contains<T: 'static>(&self) -> bool
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>());
sourcepub fn get<T: 'static>(&self) -> Option<&T>
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));
sourcepub fn get_mut<T: 'static>(&mut self) -> Option<&mut T>
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));
sourcepub fn remove<T: 'static>(&mut self) -> Option<T>
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>());
sourcepub fn clear(&mut self)
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>());
sourcepub fn extend(&mut self, other: Extensions)
pub fn extend(&mut self, other: Extensions)
Extends self with the items from another Extensions
.
Trait Implementations
sourceimpl Debug for Extensions
impl Debug for Extensions
sourceimpl Default for Extensions
impl Default for Extensions
sourcefn default() -> Extensions
fn default() -> Extensions
Returns the “default value” for a type. Read more
Auto Trait Implementations
impl !RefUnwindSafe for Extensions
impl !Send for Extensions
impl !Sync for Extensions
impl Unpin for Extensions
impl !UnwindSafe for Extensions
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
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
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more