Struct dync::Slice

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

Implementations§

source§

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

source

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

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

source§

impl<'a, V: ?Sized + HasDrop> Slice<'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 [MaybeUninit<u8>], elem: ElemInfo, vtable: impl Into<VTableRef<'a, V>> ) -> Self

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

Upcast the Slice into a more general base Slice.

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) -> 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 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. Returns None if the given type T doesn’t match the internal.

Examples
use dync::SliceDrop;
let vec = vec![1.0_f32, 23.0, 0.01, 42.0, 11.43];
let buf: SliceDrop = vec.as_slice().into();
for (i, &val) in buf.iter_as::<f32>().unwrap().enumerate() {
    assert_eq!(val, vec[i]);
}
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: Elem>(&self, i: usize) -> Option<&T>

Get i’th element of the buffer.

source

pub fn iter(&self) -> impl Iterator<Item = ValueRef<'_, 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::SliceDrop;
let vec = vec![1.0_f32, 23.0, 0.01, 42.0, 11.43];
let buf: SliceDrop = vec.as_slice().into();
for (i, val) in buf.iter().enumerate() {
    assert_eq!(val.downcast::<f32>().unwrap(), &vec[i]);
}
source

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

source

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

source

pub fn split_at(&self, mid: usize) -> (Slice<'_, V>, Slice<'_, 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 subslice<I>(&self, i: I) -> Slice<'_, 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) -> Slice<'a, V>
where I: SliceIndex<[MaybeUninit<u8>], Output = [MaybeUninit<u8>]> + ScaleRange,

Convert this slice into an immutable subslice representing the given range of indices.

source§

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

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 buffer 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> Clone for Slice<'a, V>
where V: ?Sized + Clone,

source§

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

Returns a copy 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, V: ?Sized + HasDrop + HasDebug> Debug for Slice<'a, V>

source§

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

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

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

Convert a &[T] to a Slice.

source§

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

Converts to this type from the input type.
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, V> From<Slice<'a, V>> for Meta<VTableRef<'a, V>>

source§

fn from(slice: Slice<'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 Slice<'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 Slice<'a, V>

source§

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

Auto Trait Implementations§

§

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

§

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

§

impl<'a, V: ?Sized> UnwindSafe for Slice<'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> 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> ToOwned for T
where T: Clone,

§

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

§

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,