Struct dync::SliceCopyMut
source · [−]Implementations
sourceimpl<'a, V> SliceCopyMut<'a, V>
impl<'a, V> SliceCopyMut<'a, V>
sourcepub fn from_slice<T: CopyElem>(slice: &'a mut [T]) -> SliceCopyMut<'a, V> where
V: VTable<T>,
pub fn from_slice<T: CopyElem>(slice: &'a mut [T]) -> SliceCopyMut<'a, V> where
V: VTable<T>,
Construct a SliceCopyMut
from a given typed slice by reusing the provided memory.
sourceimpl<'a, V: ?Sized> SliceCopyMut<'a, V>
impl<'a, V: ?Sized> SliceCopyMut<'a, V>
sourcepub fn into_raw_parts(
self
) -> (&'a mut [MaybeUninit<u8>], ElemInfo, VTableRef<'a, V>)
pub fn into_raw_parts(
self
) -> (&'a mut [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>>
) -> SliceCopyMut<'a, V>
pub unsafe fn from_raw_parts(
data: &'a mut [MaybeUninit<u8>],
elem: ElemInfo,
vtable: impl Into<VTableRef<'a, V>>
) -> SliceCopyMut<'a, V>
Construct a SliceCopy
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) -> SliceCopyMut<'a, U> where
V: Clone,
pub fn upcast<U: From<V>>(self) -> SliceCopyMut<'a, U> where
V: Clone,
Upcast the SliceCopyMut
into a more general base SliceCopy
.
This function converts the underlying virtual function table into a subset of the existing
sourcepub fn copy_from_slice<T: CopyElem>(&mut self, slice: &[T]) -> Option<&mut Self>
pub fn copy_from_slice<T: CopyElem>(&mut self, slice: &[T]) -> Option<&mut Self>
Copy data from a given slice into the current slice.
Panics
This function will panic if the given slice has as different size than current.
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) -> SliceCopy<'_, V>
pub fn reborrow(&self) -> SliceCopy<'_, 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) -> SliceCopyMut<'_, V>
pub fn reborrow_mut(&mut self) -> SliceCopyMut<'_, 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 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::SliceCopyMut;
let mut vec = vec![1.0_f32, 23.0, 0.01, 42.0, 11.43];
let mut buf = SliceCopyMut::<()>::from(vec.as_mut_slice());
for val in buf.iter_as::<f32>().unwrap() {
*val += 1.0_f32;
}
sourcepub fn append_copy_to_vec<'b, T: CopyElem>(
&self,
vec: &'b mut Vec<T>
) -> Option<&'b mut Vec<T>>
pub fn append_copy_to_vec<'b, T: CopyElem>(
&self,
vec: &'b mut Vec<T>
) -> Option<&'b mut Vec<T>>
Append copied items from this buffer to a given Vec<T>
. Return the mutable reference
Some(vec)
if type matched the internal type and None
otherwise.
sourcepub fn copy_into_vec<T: CopyElem>(self) -> Option<Vec<T>>
pub fn copy_into_vec<T: CopyElem>(self) -> Option<Vec<T>>
Copies contents of self
into the given Vec
.
sourcepub fn as_slice<T: Any>(&mut self) -> Option<&mut [T]>
pub fn as_slice<T: Any>(&mut self) -> Option<&mut [T]>
Convert this SliceCopyMut
into a typed slice.
Returs None
if the given type T
doesn’t match the internal.
sourcepub fn get_as<T: CopyElem>(&mut self, i: usize) -> Option<&mut T>
pub fn get_as<T: CopyElem>(&mut self, i: usize) -> Option<&mut T>
Get i
’th element of the buffer.
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 = SliceCopyMut::<()>::from_slice(vec.as_mut_slice());
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 = SliceCopyMut::<()>::from_slice(vec.as_mut_slice());
buf.rotate_right(3);
assert_eq!(buf.as_slice::<u32>().unwrap(), &[3,4,5,1,2]);
sourcepub fn iter(&mut self) -> impl Iterator<Item = CopyValueMut<'_, V>>
pub fn iter(&mut self) -> impl Iterator<Item = CopyValueMut<'_, V>>
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 = CopyValueMut<'a, V>> where
V: Clone,
pub fn chunks_exact(
&self,
chunk_size: usize
) -> impl Iterator<Item = SliceCopy<'_, V>>
pub fn chunks_exact_mut(
&mut self,
chunk_size: usize
) -> impl Iterator<Item = SliceCopyMut<'_, V>>
pub fn split_at(
&mut self,
mid: usize
) -> (SliceCopyMut<'_, V>, SliceCopyMut<'_, V>)
sourcepub fn get(&self, i: usize) -> CopyValueRef<'_, V>
pub fn get(&self, i: usize) -> CopyValueRef<'_, V>
Get a immutable value reference to the element at index i
.
sourcepub fn get_mut(&mut self, i: usize) -> CopyValueMut<'_, V>
pub fn get_mut(&mut self, i: usize) -> CopyValueMut<'_, V>
Get a mutable value reference to the element at index i
.
sourcepub fn subslice<I>(&self, i: I) -> SliceCopy<'_, V> where
I: SliceIndex<[MaybeUninit<u8>], Output = [MaybeUninit<u8>]> + ScaleRange,
pub fn subslice<I>(&self, i: I) -> SliceCopy<'_, V> where
I: SliceIndex<[MaybeUninit<u8>], Output = [MaybeUninit<u8>]> + ScaleRange,
Get an immutable subslice representing the given range of indices.
sourcepub fn subslice_mut<I>(&mut self, i: I) -> SliceCopyMut<'_, V> where
I: SliceIndex<[MaybeUninit<u8>], Output = [MaybeUninit<u8>]> + ScaleRange,
pub fn subslice_mut<I>(&mut self, i: I) -> SliceCopyMut<'_, V> where
I: SliceIndex<[MaybeUninit<u8>], Output = [MaybeUninit<u8>]> + ScaleRange,
Get a mutable subslice representing the given range of indices.
sourcepub fn into_subslice<I>(self, i: I) -> SliceCopyMut<'a, V> where
I: SliceIndex<[MaybeUninit<u8>], Output = [MaybeUninit<u8>]> + ScaleRange,
pub fn into_subslice<I>(self, i: I) -> SliceCopyMut<'a, V> where
I: SliceIndex<[MaybeUninit<u8>], Output = [MaybeUninit<u8>]> + ScaleRange,
Conver this slice into a mutable subslice representing the given range of indices.
Trait Implementations
sourceimpl<'a, T, V> From<&'a mut [T]> for SliceCopyMut<'a, V> where
T: CopyElem,
V: VTable<T>,
impl<'a, T, V> From<&'a mut [T]> for SliceCopyMut<'a, V> where
T: CopyElem,
V: VTable<T>,
Convert a &mut [T]
to a SliceCopyMut
.
sourcefn from(s: &'a mut [T]) -> SliceCopyMut<'a, V>
fn from(s: &'a mut [T]) -> SliceCopyMut<'a, V>
Converts to this type from the input type.
sourceimpl<'b, 'a: 'b, V: ?Sized> From<&'b SliceCopyMut<'a, V>> for SliceCopy<'b, V>
impl<'b, 'a: 'b, V: ?Sized> From<&'b SliceCopyMut<'a, V>> for SliceCopy<'b, V>
sourcefn from(s: &'b SliceCopyMut<'a, V>) -> SliceCopy<'b, V>
fn from(s: &'b SliceCopyMut<'a, V>) -> SliceCopy<'b, V>
Converts to this type from the input type.
sourceimpl<'a, V> From<SliceCopyMut<'a, V>> for Meta<VTableRef<'a, V>>
impl<'a, V> From<SliceCopyMut<'a, V>> for Meta<VTableRef<'a, V>>
sourcefn from(slice: SliceCopyMut<'a, V>) -> Self
fn from(slice: SliceCopyMut<'a, V>) -> Self
Converts to this type from the input type.
sourceimpl<'a, V: ?Sized> From<SliceCopyMut<'a, V>> for SliceCopy<'a, V>
impl<'a, V: ?Sized> From<SliceCopyMut<'a, V>> for SliceCopy<'a, V>
sourcefn from(s: SliceCopyMut<'a, V>) -> SliceCopy<'a, V>
fn from(s: SliceCopyMut<'a, V>) -> SliceCopy<'a, V>
Converts to this type from the input type.
Auto Trait Implementations
impl<'a, V: ?Sized> RefUnwindSafe for SliceCopyMut<'a, V> where
V: RefUnwindSafe,
impl<'a, V: ?Sized> Send for SliceCopyMut<'a, V> where
V: Send + Sync,
impl<'a, V: ?Sized> Sync for SliceCopyMut<'a, V> where
V: Sync,
impl<'a, V: ?Sized> Unpin for SliceCopyMut<'a, V>
impl<'a, V = ()> !UnwindSafe for SliceCopyMut<'a, V>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Downcast for T where
T: Any,
impl<T> Downcast for T where
T: Any,
sourcefn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
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
. Read more
sourcefn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
Convert Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
. Read more
sourcefn as_any(&self) -> &(dyn Any + 'static)
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. Read more
sourcefn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
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. Read more