Struct dync::SliceMut

source ·
pub struct SliceMut<'a, V>
where V: ?Sized,
{ /* private fields */ }

Implementations§

source§

impl<'a, V: HasDrop> SliceMut<'a, V>

source

pub fn from_slice<T: Elem>(slice: &'a mut [T]) -> SliceMut<'a, V>
where V: VTable<T>,

Construct a SliceMut from a given typed slice by reusing the provided memory.

source§

impl<'a, V: ?Sized + HasDrop> SliceMut<'a, V>

source

pub fn into_raw_parts( self ) -> (&'a [MaybeUninit<u8>], ElemInfo, VTableRef<'a, V>)

Convert this collection into its raw components.

This function exists mainly to enable the into_dyn macro until CoerceUnsized is stabilized.

source

pub unsafe fn from_raw_parts( data: &'a mut [MaybeUninit<u8>], elem: ElemInfo, vtable: impl Into<VTableRef<'a, V>> ) -> SliceMut<'a, V>

Construct a SliceMut from raw bytes and type metadata.

Safety

Almost exclusively the only inputs that are safe here are the ones returned by into_raw_parts.

This function should not be used other than in internal APIs. It exists to enable the into_dyn macro until CoerceUsize is stabilized.

source

pub fn upcast<U: From<V>>(self) -> SliceMut<'a, U>
where V: Clone,

Upcast the SliceMut into a more general base SliceMut.

This function converts the underlying virtual function table into a subset of the existing

source

pub fn check<T: Any>(&mut self) -> Option<&mut Self>

Check if the current buffer contains elements of the specified type. Returns Some(self) if the type matches and None otherwise.

source

pub fn reborrow(&self) -> Slice<'_, V>

Construct a clone of the current slice with a reduced lifetime.

This is equivalent to calling subslice with the entire range.

source

pub fn reborrow_mut(&mut self) -> SliceMut<'_, V>

Construct a clone of the current slice with a reduced lifetime.

This is equivalent to calling subslice_mut with the entire range.

source

pub fn swap(&mut self, i: usize, j: usize)

Swap the values at the two given indices.

source

pub fn element_type_id(&self) -> TypeId

Get the TypeId of data stored within this buffer.

source

pub fn len(&self) -> usize

Get the number of elements stored in this buffer.

source

pub fn is_empty(&self) -> bool

Check if there are any elements stored in this buffer.

source

pub fn element_size(&self) -> usize

Get the size of the element type in bytes.

source

pub fn iter_as<T: Any>(&mut self) -> Option<IterMut<'_, T>>

Return an iterator to a slice representing typed data. Returs None if the given type T doesn’t match the internal.

Examples
use dync::SliceMutDrop;
let mut vec = vec![1.0_f32, 23.0, 0.01, 42.0, 11.43];
let mut buf: SliceMutDrop = vec.as_mut_slice().into();
for val in buf.iter_as::<f32>().unwrap() {
    *val += 1.0_f32;
}
source

pub fn as_slice<T: Any>(&mut self) -> Option<&mut [T]>

Convert this SliceMut into a typed slice. Returs None if the given type T doesn’t match the internal.

source

pub fn get_as<T: Elem>(&mut self, i: usize) -> Option<&mut T>

Get i’th element of the buffer.

source

pub fn rotate_left(&mut self, mid: usize)

Rotates the slice in-place such that the first mid elements of the slice move to the end while the last self.len() - mid elements move to the front. After calling rotate_left, the element previously at index mid will become the first element in the slice.

Example
use dync::*;
let mut vec = vec![1u32,2,3,4,5];
let mut buf: SliceMutDrop = vec.as_mut_slice().into();
buf.rotate_left(3);
assert_eq!(buf.as_slice::<u32>().unwrap(), &[4,5,1,2,3]);
source

pub fn rotate_right(&mut self, k: usize)

Rotates the slice in-place such that the first self.len() - k elements of the slice move to the end while the last k elements move to the front. After calling rotate_right, the element previously at index k will become the first element in the slice.

Example
use dync::*;
let mut vec = vec![1u32,2,3,4,5];
let mut buf: SliceMutDrop = vec.as_mut_slice().into();
buf.rotate_right(3);
assert_eq!(buf.as_slice::<u32>().unwrap(), &[3,4,5,1,2]);
source

pub fn iter(&mut self) -> impl Iterator<Item = ValueMut<'_, V>>
where V: Clone,

Return an iterator over untyped value references stored in this slice.

In contrast to iter_as, this function defers downcasting on a per element basis. As a result, this type of iteration is typically less efficient if a typed value is needed for each element.

source

pub fn into_iter(self) -> impl Iterator<Item = ValueMut<'a, V>>
where V: Clone,

source

pub fn chunks_exact( &self, chunk_size: usize ) -> impl Iterator<Item = Slice<'_, V>>

source

pub fn chunks_exact_mut( &mut self, chunk_size: usize ) -> impl Iterator<Item = SliceMut<'_, V>>

source

pub fn split_at(&mut self, mid: usize) -> (SliceMut<'_, V>, SliceMut<'_, V>)

source

pub fn get(&self, i: usize) -> ValueRef<'_, V>

Get a reference to a value stored in this container at index i.

source

pub fn get_mut(&mut self, i: usize) -> ValueMut<'_, V>

Get a mutable reference to a value stored in this container at index i.

source

pub fn subslice<I>(&self, i: I) -> Slice<'_, V>
where I: SliceIndex<[MaybeUninit<u8>], Output = [MaybeUninit<u8>]> + ScaleRange,

Get an immutable subslice from the given range of indices.

source

pub fn subslice_mut<I>(&mut self, i: I) -> SliceMut<'_, V>
where I: SliceIndex<[MaybeUninit<u8>], Output = [MaybeUninit<u8>]> + ScaleRange,

Get a mutable subslice from the given range of indices.

source

pub fn into_subslice<I>(self, i: I) -> SliceMut<'a, V>
where I: SliceIndex<[MaybeUninit<u8>], Output = [MaybeUninit<u8>]> + ScaleRange,

Convert this slice into a mutable subslice from the given range of indices.

source§

impl<'a, V: HasDrop + HasClone> SliceMut<'a, V>

source

pub fn clone_from_slice<T: Elem + Clone>( &mut self, slice: &[T] ) -> Option<&mut Self>

Clone data from a given slice into the current slice.

Panics

This function will panic if the given slice has as different size than current.

source

pub fn append_clone_to_vec<'b, T: Elem + Clone>( &self, vec: &'b mut Vec<T> ) -> Option<&'b mut Vec<T>>

Append cloned items from this slice to a given Vec<T>. Return the mutable reference Some(vec) if type matched the internal type and None otherwise.

source

pub fn clone_into_vec<T: Elem + Clone>(self) -> Option<Vec<T>>

Clones contents of self into the given Vec.

Trait Implementations§

source§

impl<'a, V: ?Sized + HasDrop + HasDebug> Debug for SliceMut<'a, V>

source§

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

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

impl<'b, 'a: 'b, V: ?Sized + HasDrop> From<&'b SliceMut<'a, V>> for Slice<'b, V>

source§

fn from(s: &'b SliceMut<'a, V>) -> Slice<'b, V>

Converts to this type from the input type.
source§

impl<'a, T, V> From<&'a mut [T]> for SliceMut<'a, V>
where T: Elem, V: VTable<T> + HasDrop,

Convert a &mut [T] to a SliceMut.

source§

fn from(s: &'a mut [T]) -> SliceMut<'a, V>

Converts to this type from the input type.
source§

impl<'a, V> From<SliceMut<'a, V>> for Meta<VTableRef<'a, V>>

source§

fn from(slice: SliceMut<'a, V>) -> Self

Converts to this type from the input type.
source§

impl<'a, V: ?Sized> From<SliceMut<'a, V>> for Slice<'a, V>

source§

fn from(s: SliceMut<'a, V>) -> Slice<'a, V>

Converts to this type from the input type.
source§

impl<'a, V: ?Sized + HasDrop + HasPartialEq> PartialEq for SliceMut<'a, V>

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a, V: ?Sized + HasDrop + HasSend> Send for SliceMut<'a, V>

source§

impl<'a, V: ?Sized + HasDrop + HasSync> Sync for SliceMut<'a, V>

Auto Trait Implementations§

§

impl<'a, V: ?Sized> RefUnwindSafe for SliceMut<'a, V>
where V: RefUnwindSafe,

§

impl<'a, V: ?Sized> Unpin for SliceMut<'a, V>

§

impl<'a, V> !UnwindSafe for SliceMut<'a, V>

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> DebugBytes for T
where T: Debug + 'static,

source§

unsafe fn fmt_bytes( bytes: &[MaybeUninit<u8>], f: &mut Formatter<'_> ) -> Result<(), Error>

source§

impl<T> Downcast for T
where T: Any,

source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
source§

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

source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
source§

impl<T> DropBytes for T
where T: 'static,

source§

unsafe fn drop_bytes(bytes: &mut [MaybeUninit<u8>])

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> PartialEqBytes for T
where T: PartialEq + 'static,

source§

unsafe fn eq_bytes(a: &[MaybeUninit<u8>], b: &[MaybeUninit<u8>]) -> bool

source§

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

§

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

§

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> Elem for T
where T: Any + DropBytes,