mirror of https://github.com/fafhrd91/actix-web
Update return type of Extensions::insert to match documented behavior
This is a breaking change, but Extensions::insert was strictly less useful with the previous behavior.
This commit is contained in:
parent
c2c71cc626
commit
c214c1c82c
|
@ -2,6 +2,9 @@
|
||||||
|
|
||||||
## Unreleased - 2020-xx-xx
|
## Unreleased - 2020-xx-xx
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
* Change the return type of `Extensions::insert` from `()` to `Option<T>`
|
||||||
|
|
||||||
## 2.0.0 - 2020-09-11
|
## 2.0.0 - 2020-09-11
|
||||||
* No significant changes from `2.0.0-beta.4`.
|
* No significant changes from `2.0.0-beta.4`.
|
||||||
|
|
|
@ -24,8 +24,10 @@ impl Extensions {
|
||||||
///
|
///
|
||||||
/// If a extension of this type already existed, it will
|
/// If a extension of this type already existed, it will
|
||||||
/// be returned.
|
/// be returned.
|
||||||
pub fn insert<T: 'static>(&mut self, val: T) {
|
pub fn insert<T: 'static>(&mut self, val: T) -> Option<T> {
|
||||||
self.map.insert(TypeId::of::<T>(), Box::new(val));
|
self.map
|
||||||
|
.insert(TypeId::of::<T>(), Box::new(val))
|
||||||
|
.and_then(|boxed| boxed.downcast().ok().map(|boxed| *boxed))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Check if container contains entry
|
/// Check if container contains entry
|
||||||
|
|
|
@ -63,7 +63,7 @@ pub(crate) struct Data<T>(pub(crate) T);
|
||||||
|
|
||||||
impl<T: Clone + 'static> DataFactory for Data<T> {
|
impl<T: Clone + 'static> DataFactory for Data<T> {
|
||||||
fn set(&self, ext: &mut Extensions) {
|
fn set(&self, ext: &mut Extensions) {
|
||||||
ext.insert(self.0.clone())
|
ext.insert(self.0.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue