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:
Jonas Platte 2020-10-02 19:00:30 +02:00
parent c2c71cc626
commit c214c1c82c
No known key found for this signature in database
GPG Key ID: 9D5B897BFF66575C
3 changed files with 8 additions and 3 deletions

View File

@ -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`.

View File

@ -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

View File

@ -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());
} }
} }