pub struct SliceMut<'a, V>where
V: ?Sized,{ /* private fields */ }
Implementations§
source§impl<'a, V: ?Sized + HasDrop> SliceMut<'a, V>
impl<'a, V: ?Sized + HasDrop> SliceMut<'a, V>
sourcepub fn into_raw_parts(
self
) -> (&'a [MaybeUninit<u8>], ElemInfo, VTableRef<'a, V>)
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.
sourcepub unsafe fn from_raw_parts(
data: &'a mut [MaybeUninit<u8>],
elem: ElemInfo,
vtable: impl Into<VTableRef<'a, V>>
) -> SliceMut<'a, V>
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.
sourcepub fn upcast<U: From<V>>(self) -> SliceMut<'a, U>where
V: Clone,
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
sourcepub fn check<T: Any>(&mut self) -> Option<&mut Self>
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.
sourcepub fn reborrow(&self) -> Slice<'_, V>
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.
sourcepub fn reborrow_mut(&mut self) -> SliceMut<'_, V>
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.
sourcepub fn element_type_id(&self) -> TypeId
pub fn element_type_id(&self) -> TypeId
Get the TypeId
of data stored within this buffer.
sourcepub fn element_size(&self) -> usize
pub fn element_size(&self) -> usize
Get the size of the element type in bytes.
sourcepub fn iter_as<T: Any>(&mut self) -> Option<IterMut<'_, T>>
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;
}
sourcepub fn as_slice<T: Any>(&mut self) -> Option<&mut [T]>
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.
sourcepub fn rotate_left(&mut self, mid: usize)
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]);
sourcepub fn rotate_right(&mut self, k: usize)
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]);
sourcepub fn iter(&mut self) -> impl Iterator<Item = ValueMut<'_, V>>where
V: Clone,
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.
pub fn into_iter(self) -> impl Iterator<Item = ValueMut<'a, V>>where
V: Clone,
pub fn chunks_exact( &self, chunk_size: usize ) -> impl Iterator<Item = Slice<'_, V>>
pub fn chunks_exact_mut( &mut self, chunk_size: usize ) -> impl Iterator<Item = SliceMut<'_, V>>
pub fn split_at(&mut self, mid: usize) -> (SliceMut<'_, V>, SliceMut<'_, V>)
sourcepub fn get(&self, i: usize) -> ValueRef<'_, V>
pub fn get(&self, i: usize) -> ValueRef<'_, V>
Get a reference to a value stored in this container at index i
.
sourcepub fn get_mut(&mut self, i: usize) -> ValueMut<'_, V>
pub fn get_mut(&mut self, i: usize) -> ValueMut<'_, V>
Get a mutable reference to a value stored in this container at index i
.
sourcepub fn subslice<I>(&self, i: I) -> Slice<'_, V>
pub fn subslice<I>(&self, i: I) -> Slice<'_, V>
Get an immutable subslice from the given range of indices.
sourcepub fn subslice_mut<I>(&mut self, i: I) -> SliceMut<'_, V>
pub fn subslice_mut<I>(&mut self, i: I) -> SliceMut<'_, V>
Get a mutable subslice from the given range of indices.
sourcepub fn into_subslice<I>(self, i: I) -> SliceMut<'a, V>
pub fn into_subslice<I>(self, i: I) -> SliceMut<'a, V>
Convert this slice into a mutable subslice from the given range of indices.
source§impl<'a, V: HasDrop + HasClone> SliceMut<'a, V>
impl<'a, V: HasDrop + HasClone> SliceMut<'a, V>
sourcepub fn clone_from_slice<T: Elem + Clone>(
&mut self,
slice: &[T]
) -> Option<&mut Self>
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.
Trait Implementations§
source§impl<'a, V: ?Sized + HasDrop + HasPartialEq> PartialEq for SliceMut<'a, V>
impl<'a, V: ?Sized + HasDrop + HasPartialEq> PartialEq for SliceMut<'a, V>
impl<'a, V: ?Sized + HasDrop + HasSend> Send for SliceMut<'a, V>
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> 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
source§impl<T> DebugBytes for Twhere
T: Debug + 'static,
impl<T> DebugBytes for Twhere
T: Debug + 'static,
source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.