Struct dync::Slice

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

Implementations

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

Convert this collection into its raw components.

This function exists mainly to enable the into_dyn macro until CoerceUnsized is stabilized.

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.

Upcast the Slice into a more general base Slice.

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

Check if the current buffer contains elements of the specified type.

Returns Some(self) if the type matches and None otherwise.

Construct a clone of the current slice with a reduced lifetime.

This is equivalent to calling subslice with the entire range.

Get the TypeId of data stored within this buffer.

Get the number of elements stored in this buffer.

Check if there are any elements stored in this buffer.

Get the size of the element type in bytes.

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]);
}

Borrow this slice as a typed slice.

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

Get i’th element of the buffer.

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]);
}

Get a reference to a value stored in this container at index i.

Get an immutable subslice representing the given range of indices.

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

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.

Clones contents of self into the given Vec.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Convert a &[T] to a Slice.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

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

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

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s. Read more

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

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.