Module any_sync_send

Module any_sync_send 

Source
Expand description

New functions for &(mut) dyn [Any+Sync+Send].

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_sync_send::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_sync_send::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+Sync+Send.
new_mut
Create a mutable dyn slice from a mutable slice of a type that implements Any+Sync+Send.

Type Aliases§

Dyn
An alias for dyn Any+Sync+Send.
Slice
An alias for &dyn [Any+Sync+Send] (DynSlice<Dyn>).
SliceMut
An alias for &mut dyn [Any+Sync+Send] (DynSliceMut<Dyn>).