pub struct Configs { /* private fields */ }Expand description
A type map of protocol extensions.
Configs can be used by Request and Response to store
extra data derived from the underlying protocol.
Implementations§
Source§impl Configs
impl Configs
Sourcepub fn insert<T: Send + Sync + Clone + 'static>(&mut self, val: T) -> Option<T>
pub fn insert<T: Send + Sync + Clone + 'static>(&mut self, val: T) -> Option<T>
Insert a type into this Configs.
If an extension of this type already existed, it will be returned.
§Example
let mut cfg = Configs::new();
assert!(cfg.insert(5i32).is_none());
assert!(cfg.insert(4u8).is_none());
assert_eq!(cfg.insert(9i32), Some(5i32));Sourcepub fn get<T: Send + Sync + 'static>(&self) -> Option<&T>
pub fn get<T: Send + Sync + 'static>(&self) -> Option<&T>
Get a reference to a type previously inserted on this Configs.
§Example
let mut cfg = Configs::new();
assert!(cfg.get::<i32>().is_none());
cfg.insert(5i32);
assert_eq!(cfg.get::<i32>(), Some(&5i32));Sourcepub fn remove<T: Send + Sync + Clone + 'static>(&mut self) -> Option<T>
pub fn remove<T: Send + Sync + Clone + 'static>(&mut self) -> Option<T>
Remove a type from this Configs.
If aa extension of this type existed, it will be returned.
§Example
let mut cfg = Configs::new();
cfg.insert(5i32);
assert_eq!(cfg.remove::<i32>(), Some(5i32));
assert!(cfg.get::<i32>().is_none());Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Clear the Configs of all inserted extensions.
§Example
let mut cfg = Configs::new();
cfg.insert(5i32);
cfg.clear();
assert!(cfg.get::<i32>().is_none());Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Check whether the extension set is empty or not.
§Example
let mut cfg = Configs::new();
assert!(cfg.is_empty());
cfg.insert(5i32);
assert!(!cfg.is_empty());Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Get the numer of extensions available.
§Example
let mut cfg = Configs::new();
assert_eq!(cfg.len(), 0);
cfg.insert(5i32);
assert_eq!(cfg.len(), 1);Sourcepub fn extend_from(&mut self, other: &Configs)
pub fn extend_from(&mut self, other: &Configs)
将另一个 Configs 的内容合并进来(浅拷贝 Arc 值)
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Configs
impl !RefUnwindSafe for Configs
impl Send for Configs
impl Sync for Configs
impl Unpin for Configs
impl !UnwindSafe for Configs
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
Mutably borrows from an owned value. Read more