pub struct SliceAnyMut<'a, B: ?Sized = dyn Any + Send + Sync> { /* private fields */ }Expand description
A type-erased mutable slice.
Semantically &mut [dyn Any].
§Examples
use list_any::SliceAnyMut;
let mut data = *b"hello";
let mut slice_any: SliceAnyMut = SliceAnyMut::from(&mut data[..]);
let new_ref = slice_any.downcast_mut::<u8>().unwrap();
new_ref[1] = b'a';
assert_eq!(&data, b"hallo");Implementations§
Source§impl<'a> SliceAnyMut<'a>
impl<'a> SliceAnyMut<'a>
Sourcepub fn opaque() -> Self
pub fn opaque() -> Self
Create a SliceAnyMut with a length of 0, for which downcasting will
always return None.
use list_any::SliceAnyMut;
let mut slice = SliceAnyMut::opaque();
assert_eq!(slice.downcast_mut::<f64>(), None);
assert_eq!(slice.downcast_mut::<u32>(), None);
assert_eq!(slice.downcast_mut::<()>(), None);Sourcepub fn deferred() -> Self
pub fn deferred() -> Self
Create a SliceAnyMut with a length of 0, for which downcasting will
always return Some.
use list_any::SliceAnyMut;
let mut slice = SliceAnyMut::deferred();
assert_eq!(slice.downcast_mut::<f64>(), Some(&mut [][..]));
assert_eq!(slice.downcast_mut::<u32>(), Some(&mut [][..]));
assert_eq!(slice.downcast_mut::<()>(), Some(&mut [][..]));Source§impl<'a, B: ?Sized> SliceAnyMut<'a, B>
impl<'a, B: ?Sized> SliceAnyMut<'a, B>
Sourcepub fn type_id_of_element(&self) -> TypeId
pub fn type_id_of_element(&self) -> TypeId
Returns the TypeId of the elements contained in this slice.
§Examples
use core::any::TypeId;
use list_any::SliceAnyMut;
let mut data = *b"hello";
let slice_any: SliceAnyMut = SliceAnyMut::from(&mut data[..]);
assert_eq!(slice_any.type_id_of_element(), TypeId::of::<u8>());Sourcepub fn downcast_mut<T: AnyBound<B>>(&mut self) -> Option<&mut [T]>
pub fn downcast_mut<T: AnyBound<B>>(&mut self) -> Option<&mut [T]>
Returns some mutable reference to the original slice if the elements
are of type T, or None if they are not.
Sourcepub fn as_slice_any(&self) -> SliceAny<'_>
pub fn as_slice_any(&self) -> SliceAny<'_>
Returns this SliceAnyMut as an immutable SliceAny.
Trait Implementations§
impl<'a, B: ?Sized + Send + Sync> Send for SliceAnyMut<'a, B>
impl<'a, B: ?Sized + Sync> Sync for SliceAnyMut<'a, B>
Auto Trait Implementations§
impl<'a, B> Freeze for SliceAnyMut<'a, B>where
B: ?Sized,
impl<'a, B> RefUnwindSafe for SliceAnyMut<'a, B>where
B: RefUnwindSafe + ?Sized,
impl<'a, B> Unpin for SliceAnyMut<'a, B>where
B: ?Sized,
impl<'a, B = dyn Any + Sync + Send> !UnwindSafe for SliceAnyMut<'a, B>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more