Struct SliceCopy

Source
pub struct SliceCopy<'a, V = ()>
where V: ?Sized,
{ /* private fields */ }

Implementations§

Source§

impl<'a, V> SliceCopy<'a, V>

Source

pub fn from_slice<T: CopyElem>(slice: &[T]) -> Self
where V: VTable<T>,

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

Source§

impl<'a, V: ?Sized> SliceCopy<'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.

§Safety

Calling this function is not inherently unsafe, but using the returned values incorrectly may cause undefined behaviour.

Source

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

Construct a SliceCopy from raw bytes and type metadata.

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

§Safety

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) -> SliceCopy<'a, U>
where V: Clone,

Upcast the SliceCopy into a more general base SliceCopy.

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

Source

pub fn check<T: Any>(&self) -> Option<&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) -> SliceCopy<'_, 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 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>(&self) -> Option<Iter<'_, 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::SliceCopy;
let vec = vec![1.0_f32, 23.0, 0.01, 42.0, 11.43];
let buf = SliceCopy::<()>::from_slice(vec.as_slice());
for (i, &val) in buf.iter_as::<f32>().unwrap().enumerate() {
    assert_eq!(val, vec[i]);
}
Source

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.

Source

pub fn copy_into_vec<T: CopyElem>(&self) -> Option<Vec<T>>

Copies contents of self into the given Vec.

Source

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

Borrow this slice as a typed slice.

Returns None if the given type T doesn’t match the internal.

Source

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

Get i’th element of the buffer.

Source

pub fn iter(&self) -> impl Iterator<Item = CopyValueRef<'_, V>>

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

In contrast to iter, 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.

§Examples
use dync::SliceCopy;
let vec = vec![1.0_f32, 23.0, 0.01, 42.0, 11.43];
let buf: SliceCopy = SliceCopy::from(vec.as_slice());
for (i, val) in buf.iter().enumerate() {
    assert_eq!(val.downcast::<f32>().unwrap(), &vec[i]);
}
Source

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

Source

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

Source

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

Source

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

Get a immutable value reference to the element at index i.

Source

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.

Source

pub fn into_subslice<I>(self, i: I) -> SliceCopy<'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§

Source§

impl<'a, V> Clone for SliceCopy<'a, V>
where V: ?Sized + Clone,

Source§

fn clone(&self) -> SliceCopy<'a, V>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a, T, V> From<&'a [T]> for SliceCopy<'a, V>
where T: CopyElem, V: VTable<T>,

Convert a &[T] to a SliceCopy.

Source§

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

Converts to this type from the input type.
Source§

impl<'b, 'a: 'b, V: ?Sized> From<&'b SliceCopyMut<'a, V>> for SliceCopy<'b, V>

Source§

fn from(s: &'b SliceCopyMut<'a, V>) -> SliceCopy<'b, V>

Converts to this type from the input type.
Source§

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

Source§

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

Converts to this type from the input type.
Source§

impl<'a, V: ?Sized> From<SliceCopyMut<'a, V>> for SliceCopy<'a, V>

Source§

fn from(s: SliceCopyMut<'a, V>) -> SliceCopy<'a, V>

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<'a, V> Freeze for SliceCopy<'a, V>
where V: ?Sized,

§

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

§

impl<'a, V> Send for SliceCopy<'a, V>
where V: Sync + Send + ?Sized,

§

impl<'a, V> Sync for SliceCopy<'a, V>
where V: Sync + ?Sized,

§

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

§

impl<'a, V> UnwindSafe for SliceCopy<'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> CloneBytes for T
where T: Clone + 'static,

Source§

unsafe fn clone_bytes(src: &[MaybeUninit<u8>]) -> Box<[MaybeUninit<u8>]>

Source§

unsafe fn clone_from_bytes(dst: &mut [MaybeUninit<u8>], src: &[MaybeUninit<u8>])

Source§

unsafe fn clone_into_raw_bytes( src: &[MaybeUninit<u8>], dst: &mut [MaybeUninit<u8>], )

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

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

Source§

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

Converts Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.
Source§

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

Converts Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

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

Converts &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)

Converts &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> DowncastSend for T
where T: Any + Send,

Source§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

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

Source§

fn into_any_sync(self: Box<T>) -> Box<dyn Any + Sync + Send>

Converts Box<Trait> (where Trait: DowncastSync) to Box<dyn Any + Send + Sync>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

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

Converts Arc<Trait> (where Trait: DowncastSync) to Arc<Any>, which can then be 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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> Elem for T
where T: Any + DropBytes,