pub struct Slice<'a, V> where
V: ?Sized, { /* private fields */ }
Implementations
sourceimpl<'a, V: HasDrop> Slice<'a, V>
impl<'a, V: HasDrop> Slice<'a, V>
sourcepub fn from_slice<T: Elem>(slice: &[T]) -> Self where
V: VTable<T>,
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.
sourceimpl<'a, V: ?Sized + HasDrop> Slice<'a, V>
impl<'a, V: ?Sized + HasDrop> Slice<'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 [MaybeUninit<u8>],
elem: ElemInfo,
vtable: impl Into<VTableRef<'a, V>>
) -> Self
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.
sourcepub fn upcast<U: From<V>>(self) -> Slice<'a, U> where
V: Clone,
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
sourcepub fn check<T: Any>(&self) -> Option<&Self>
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.
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 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>(&self) -> Option<Iter<'_, T>>
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]);
}
sourcepub fn as_slice<T: Any>(&self) -> Option<&[T]>
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.
sourcepub fn iter(&self) -> impl Iterator<Item = ValueRef<'_, V>>
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]);
}
pub fn into_iter(self) -> impl Iterator<Item = ValueRef<'a, V>> where
V: Clone,
pub fn chunks_exact(
&self,
chunk_size: usize
) -> impl Iterator<Item = Slice<'_, V>>
pub fn split_at(&self, mid: usize) -> (Slice<'_, V>, Slice<'_, 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 subslice<I>(&self, i: I) -> Slice<'_, V> where
I: SliceIndex<[MaybeUninit<u8>], Output = [MaybeUninit<u8>]> + ScaleRange,
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.
sourcepub fn into_subslice<I>(self, i: I) -> Slice<'a, V> where
I: SliceIndex<[MaybeUninit<u8>], Output = [MaybeUninit<u8>]> + ScaleRange,
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.
sourceimpl<'a, V: ?Sized + HasClone + HasDrop> Slice<'a, V>
impl<'a, V: ?Sized + HasClone + HasDrop> Slice<'a, V>
Trait Implementations
sourceimpl<'a, T, V> From<&'a [T]> for Slice<'a, V> where
T: Elem,
V: VTable<T> + HasDrop,
impl<'a, T, V> From<&'a [T]> for Slice<'a, V> where
T: Elem,
V: VTable<T> + HasDrop,
Convert a &[T]
to a Slice
.
impl<'a, V: ?Sized + HasDrop + HasSend> Send for Slice<'a, V>
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> where
V: UnwindSafe + RefUnwindSafe,
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> CloneBytes for T where
T: 'static + Clone,
impl<T> CloneBytes for T where
T: 'static + Clone,
unsafe fn clone_bytes(src: &[MaybeUninit<u8>]) -> Box<[MaybeUninit<u8>], Global>
unsafe fn clone_from_bytes(dst: &mut [MaybeUninit<u8>], src: &[MaybeUninit<u8>])
unsafe fn clone_into_raw_bytes(
src: &[MaybeUninit<u8>],
dst: &mut [MaybeUninit<u8>]
)
sourceimpl<T> DebugBytes for T where
T: 'static + Debug,
impl<T> DebugBytes for T where
T: 'static + Debug,
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
sourceimpl<T> DowncastSync for T where
T: Any + Send + Sync,
impl<T> DowncastSync for T where
T: Any + Send + Sync,
sourceimpl<T> DropBytes for T where
T: 'static,
impl<T> DropBytes for T where
T: 'static,
unsafe fn drop_bytes(bytes: &mut [MaybeUninit<u8>])
sourceimpl<T> PartialEqBytes for T where
T: 'static + PartialEq<T>,
impl<T> PartialEqBytes for T where
T: 'static + PartialEq<T>,
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more