SliceAnyMut

Struct SliceAnyMut 

Source
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>

Source

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

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>

Source

pub fn len(&self) -> usize

Returns the number of elements in the slice.

Source

pub fn is_empty(&self) -> bool

Returns true if the slice has a length of 0.

Source

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

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.

Source

pub fn as_slice_any(&self) -> SliceAny<'_>

Returns this SliceAnyMut as an immutable SliceAny.

Trait Implementations§

Source§

impl<'a, B: Debug + ?Sized> Debug for SliceAnyMut<'a, B>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a, B: ?Sized, T: AnyBound<B>> From<&'a mut [T]> for SliceAnyMut<'a, B>

Source§

fn from(slice: &mut [T]) -> Self

Converts to this type from the input type.
Source§

impl<'a, B: ?Sized + Send + Sync> Send for SliceAnyMut<'a, B>

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> AnyBound<dyn Any> for T
where T: Any,

Source§

impl<T> AnyBound<dyn Any + Send> for T
where T: Any + Send,

Source§

impl<T> AnyBound<dyn Any + Sync + Send> for T
where T: Any + Send + Sync,

Source§

impl<T> AnyBound<dyn Any + Sync> for T
where T: Any + Sync,