1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-12-21 23:56:35 +00:00
This commit is contained in:
Rob Ede 2021-07-14 00:36:00 +01:00
parent 9e685fc5fb
commit e6290dfd09
No known key found for this signature in database
GPG key ID: 97C636207D3EF933

View file

@ -168,12 +168,15 @@ pub trait CloneAny: Any + CloneToAny {}
impl<T: Any + Clone> CloneAny for T {}
impl Clone for Box<dyn CloneAny> {
#[inline]
fn clone(&self) -> Self {
(**self).clone_to_clone_any()
}
}
trait UncheckedAnyExt {
/// # Safety
/// TODO
#[inline]
unsafe fn downcast_unchecked<T: 'static>(self: Box<Self>) -> Box<T> {
Box::from_raw(Box::into_raw(self) as *mut T)
@ -183,6 +186,8 @@ trait UncheckedAnyExt {
impl UncheckedAnyExt for dyn CloneAny {}
fn downcast_cloneable<T: 'static>(boxed: Box<dyn CloneAny>) -> T {
// Safety:
// TODO
*unsafe { UncheckedAnyExt::downcast_unchecked::<T>(boxed) }
}
@ -356,26 +361,26 @@ mod tests {
assert_eq!(extensions.get_mut(), Some(&mut 20u8));
}
#[test]
fn test_drain_from() {
let mut ext = Extensions::new();
ext.insert(2isize);
// #[test]
// fn test_drain_from() {
// let mut ext = Extensions::new();
// ext.insert(2isize);
let mut more_ext = Extensions::new();
// let mut more_ext = Extensions::new();
more_ext.insert(5isize);
more_ext.insert(5usize);
// more_ext.insert(5isize);
// more_ext.insert(5usize);
assert_eq!(ext.get::<isize>(), Some(&2isize));
assert_eq!(ext.get::<usize>(), None);
assert_eq!(more_ext.get::<isize>(), Some(&5isize));
assert_eq!(more_ext.get::<usize>(), Some(&5usize));
// assert_eq!(ext.get::<isize>(), Some(&2isize));
// assert_eq!(ext.get::<usize>(), None);
// assert_eq!(more_ext.get::<isize>(), Some(&5isize));
// assert_eq!(more_ext.get::<usize>(), Some(&5usize));
ext.drain_from(&mut more_ext);
// ext.drain_from(&mut more_ext);
assert_eq!(ext.get::<isize>(), Some(&5isize));
assert_eq!(ext.get::<usize>(), Some(&5usize));
assert_eq!(more_ext.get::<isize>(), None);
assert_eq!(more_ext.get::<usize>(), None);
}
// assert_eq!(ext.get::<isize>(), Some(&5isize));
// assert_eq!(ext.get::<usize>(), Some(&5usize));
// assert_eq!(more_ext.get::<isize>(), None);
// assert_eq!(more_ext.get::<usize>(), None);
// }
}