Struct dync::VecDyn

source ·
pub struct VecDyn<V>
where V: ?Sized + HasDrop,
{ /* private fields */ }

Implementations§

source§

impl<V: HasDrop> VecDyn<V>

source

pub fn with_type<T: Elem>() -> Self
where V: VTable<T>,

Construct an empty vector with a specific pointed-to element type.

source

pub fn with_capacity<T: Elem>(n: usize) -> Self
where V: VTable<T>,

Construct an empty vector with a capacity for a given number of typed pointed-to elements.

source

pub fn from_vec<T: Elem>(vec: Vec<T>) -> Self
where V: VTable<T>,

Construct a VecDyn from a given Vec reusing the space already allocated by the given vector.

source§

impl<V: ?Sized + HasDrop> VecDyn<V>

source

pub fn with_type_from<'a>(other: impl Into<Meta<VTableRef<'a, V>>>) -> Self
where V: Clone + 'a,

Construct a vector with the same type as the given vector without copying its data.

source

pub unsafe fn from_raw_parts(data: VecVoid, vtable: Ptr<V>) -> VecDyn<V>

Construct a VecDyn from raw bytes and type metadata.

Safety

Almost exclusively the only inputs that are safe here are the ones returned by VecDyn::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 into_raw_parts(self) -> (VecVoid, Ptr<V>)

Convert this collection into its raw components.

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

source

pub fn vtable(&self) -> &V

Retrieve the associated virtual function table.

source

pub fn upcast<U: HasDrop + From<V>>(self) -> VecDyn<U>
where V: Clone,

Upcast the VecDyn into a more general base VecDyn.

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

source

pub fn clear(&mut self)

Clear the data buffer without destroying its type information.

source

pub fn push_as<T: Elem>(&mut self, element: T) -> Option<&mut Self>

Add an element to this buffer.

If the type of the given element coincides with the type stored by this buffer, then the modified buffer is returned via a mutable reference. Otherwise, None is returned.

source

pub fn check<T: Elem>(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 check_ref<T: Elem>(&self) -> Option<&Self>

Check if the current buffer contains elements of the specified type. Returns None if the check fails, otherwise a reference to self is returned.

source

pub fn check_mut<T: Elem>(&mut self) -> Option<&mut Self>

Check if the current buffer contains elements of the specified type. Same as check_ref but consumes and produces a mut reference to self.

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: Elem>(&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.

source

pub fn iter_mut_as<T: Elem>(&mut self) -> Option<IterMut<'_, T>>

Return an iterator to a mutable slice representing typed data.

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

source

pub fn into_vec<T: Elem>(self) -> Option<Vec<T>>

An alternative to using the Into trait.

This function helps the compiler determine the type T automatically.

source

pub fn as_slice_as<T: Elem>(&self) -> Option<&[T]>

Convert this buffer into a typed slice. Returs None if the given type T doesn’t match the internal.

source

pub fn as_mut_slice_as<T: Elem>(&mut self) -> Option<&mut [T]>

Convert this buffer into a typed mutable slice. Returs None if the given type T doesn’t match the internal.

source

pub fn get_ref_as<T: Elem>(&self, i: usize) -> Option<&T>

Get a const reference to the i’th element of the buffer.

source

pub fn get_mut_as<T: Elem>(&mut self, i: usize) -> Option<&mut T>

Get a mutable reference to the i’th element of the buffer.

source

pub fn append(&mut self, buf: &mut VecDyn<V>) -> Option<&mut Self>

Move bytes to this buffer.

The given buffer must have the same underlying type as self.

source

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.

source

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.

source

pub fn push<U: ?Sized + HasDrop>( &mut self, value: BoxValue<U> ) -> Option<&mut Self>

Push a value onto this buffer.

If the type of the given value coincides with the type stored by this buffer, then the modified buffer is returned via a mutable reference. Otherwise, None is returned.

Note that the vtables need not patch, only the underlying types are required to match.

source

pub fn push_cloned(&mut self, value: ValueRef<'_, V>) -> Option<&mut Self>
where V: HasClone,

Push a clone of the referenced value to this buffer.

If the type of the given value coincides with the type stored by this buffer, then the modified buffer is returned via a mutable reference. Otherwise, None is returned.

This is more efficient than push since it avoids an extra allocation, however it requires the contained value to be Clone.

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

source

pub fn get_mut(&mut self, i: usize) -> ValueMut<'_, V>

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

source

pub fn iter_mut(&mut self) -> impl Iterator<Item = ValueMut<'_, V>>

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

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

source

pub fn as_slice(&self) -> Slice<'_, V>

source

pub fn as_mut_slice(&mut self) -> SliceMut<'_, V>

source

pub unsafe fn get_unchecked_ref<T: Any>(&self, i: usize) -> &T

Get a const reference to the i’th element of the vector.

This can be used to reinterpret the internal data as a different type. Note that if the size of the given type T doesn’t match the size of the internal type, i will really index the ith T sized chunk in the current vector. See the implementation for details.

Safety

It is assumed that that the vector contains elements of type T and that i is strictly less than the length of this vector, otherwise this function may cause undefined behavior.

This function is a complete opt-out of all safety checks.

source

pub unsafe fn get_unchecked_mut<T: Any>(&mut self, i: usize) -> &mut T

Get a mutable reference to the i’th element of the vector.

This can be used to reinterpret the internal data as a different type. Note that if the size of the given type T doesn’t match the size of the internal type, i will really index the ith T sized chunk in the current vector. See the implementation for details.

Safety

It is assumed that that the vector contains elements of type T and that i is strictly less than the length of this vector, otherwise this function may cause undefined behavior.

This function is opts-out of all safety checks.

source§

impl<V: HasDrop + HasClone> VecDyn<V>

source

pub fn with_size<T: Elem + Clone>(n: usize, def: T) -> Self
where V: VTable<T>,

Construct a typed VecDyn with a given size and filled with the specified default value.

source

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

Construct a buffer from a given slice by cloning the data.

source§

impl<V: ?Sized + HasDrop + HasClone> VecDyn<V>

source

pub fn resize<T: Elem + Clone>( &mut self, new_len: usize, value: T ) -> Option<&mut Self>

Resizes the buffer in-place to store new_len elements and returns an optional mutable reference to Self.

If value does not correspond to the underlying element type, then None is returned and the buffer is left unchanged.

This function has the similar properties to Vec::resize.

source

pub fn fill<T: Elem + Clone>(&mut self, def: T) -> Option<&mut Self>

Fill the current buffer with clones of the given value.

The size of the buffer is left unchanged. If the given type doesn’t match the internal type, None is returned, otherwise a mutable reference to the modified buffer is returned.

source

pub fn append_cloned_to_vec<'a, T: Elem + Clone>( &self, vec: &'a mut Vec<T> ) -> Option<&'a mut Vec<T>>

Append cloned items from this buffer to a given Vec.

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<V: ?Sized + Clone + HasDrop + HasClone> Clone for VecDyn<V>

source§

fn clone(&self) -> Self

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<V: ?Sized + HasDrop + HasDebug> Debug for VecDyn<V>

source§

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

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

impl<V: ?Sized + HasDrop> Drop for VecDyn<V>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

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

Convert a slice to a VecDyn.

source§

fn from(slice: &'a [T]) -> VecDyn<V>

Converts to this type from the input type.
source§

impl<'a, V: Clone + HasDrop> From<&'a VecDyn<V>> for Meta<VTableRef<'a, V>>

source§

fn from(v: &'a VecDyn<V>) -> Self

Converts to this type from the input type.
source§

impl<T: Elem, V: HasDrop + VTable<T>> From<Vec<T>> for VecDyn<V>

Convert a Vec to a buffer.

source§

fn from(vec: Vec<T>) -> VecDyn<V>

Converts to this type from the input type.
source§

impl<T: Elem, V: ?Sized + HasDrop + VTable<T>> From<VecDyn<V>> for Option<Vec<T>>

Convert a buffer to a Vec with an option to fail.

source§

fn from(v: VecDyn<V>) -> Option<Vec<T>>

Converts to this type from the input type.
source§

impl<V: ?Sized + HasDrop + HasHash> Hash for VecDyn<V>

source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<V: ?Sized + HasDrop + HasPartialEq> PartialEq for VecDyn<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<V: ?Sized + HasDrop + HasEq> Eq for VecDyn<V>

source§

impl<V: ?Sized + HasDrop + HasSend> Send for VecDyn<V>

source§

impl<V: ?Sized + HasDrop + HasSync> Sync for VecDyn<V>

Auto Trait Implementations§

§

impl<V: ?Sized> RefUnwindSafe for VecDyn<V>
where V: RefUnwindSafe,

§

impl<V: ?Sized> Unpin for VecDyn<V>

§

impl<V: ?Sized> UnwindSafe for VecDyn<V>
where V: UnwindSafe,

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 + Send + Sync>

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> HashBytes for T
where T: Hash + 'static,

source§

unsafe fn hash_bytes(bytes: &[MaybeUninit<u8>], state: &mut dyn Hasher)

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,