feat(headers): Headers::remove returns the Header
Closes #891 BREAKING CHANGE: `Headers.remove()` used to return a `bool`, it now returns `Option<H>`. To determine if a a header exists, switch to `Headers.has()`.
This commit is contained in:
committed by
Sean McArthur
parent
74136de960
commit
9375addba0
@@ -86,6 +86,20 @@ impl<V: ?Sized + Any + 'static> PtrMapCell<V> {
|
||||
}.map(|val| &mut **val)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn into_value(self, key: TypeId) -> Option<Box<V>> {
|
||||
let map = unsafe { self.0.into_inner() };
|
||||
match map {
|
||||
PtrMap::Empty => None,
|
||||
PtrMap::One(id, v) => if id == key {
|
||||
Some(v)
|
||||
} else {
|
||||
None
|
||||
},
|
||||
PtrMap::Many(mut hm) => hm.remove(&key)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn insert(&self, key: TypeId, val: Box<V>) {
|
||||
let mut map = &mut *self.0.get();
|
||||
|
||||
@@ -82,6 +82,14 @@ impl Item {
|
||||
}
|
||||
self.typed.get_mut(tid).map(|typed| unsafe { typed.downcast_mut_unchecked() })
|
||||
}
|
||||
|
||||
pub fn into_typed<H: Header>(self) -> Option<H> {
|
||||
let tid = TypeId::of::<H>();
|
||||
match self.typed.into_value(tid) {
|
||||
Some(val) => Some(val),
|
||||
None => parse::<H>(self.raw.as_ref().expect("item.raw must exist")).ok()
|
||||
}.map(|typed| unsafe { typed.downcast_unchecked() })
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
||||
Reference in New Issue
Block a user