Expand description
New functions for &(mut) dyn [Any].
DynSlice(Mut)<dyn Any>, DynSlice(Mut)<dyn Any + Send> and DynSlice(Mut)<dyn Any + Send + Sync> have a few extra methods:
§Examples
let array: [u8; 4] = [1, 2, 4, 8];
let slice = any::new(&array);
// Assert that the dyn-slice is a slice of `u8`s
assert!(slice.is::<u8>());
// Downcast the dyn-slice to a slice of `u8`s
assert_eq!(slice.downcast::<u8>(), Some(array.as_slice()));let mut array: [u8; 4] = [1, 2, 4, 8];
let mut slice = any::new_mut(&mut array);
// Downcast the mutable dyn-slice to a mutable slice of `u8`s
slice.downcast_mut::<u8>().unwrap()[1] = 255;
assert_eq!(array, [1, 255, 4, 8]);Functions§
- new
- Create a dyn slice from a slice of a type that implements
Any. - new_mut
- Create a mutable dyn slice from a mutable slice of a type that implements
Any.
Type Aliases§
- Dyn
- An alias for
dynAny. - Slice
- An alias for
&dyn [Any](DynSlice<Dyn>). - Slice
Mut - An alias for
&mut dyn [Any](DynSliceMut<Dyn>).