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

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);

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 [][..]));

Returns the number of elements in the slice.

Returns true if the slice has a length of 0.

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

Returns some mutable reference to the original slice if the elements are of type T, or None if they are not.

Returns this SliceAnyMut as an immutable SliceAny.

Trait Implementations

Formats the value using the given formatter. Read more

Converts to this type from the input type.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.