pub struct VecDyn<V>{ /* private fields */ }
Implementations§
source§impl<V: HasDrop> VecDyn<V>
impl<V: HasDrop> VecDyn<V>
source§impl<V: ?Sized + HasDrop> VecDyn<V>
impl<V: ?Sized + HasDrop> VecDyn<V>
sourcepub fn with_type_from<'a>(other: impl Into<Meta<VTableRef<'a, V>>>) -> Selfwhere
V: Clone + 'a,
pub fn with_type_from<'a>(other: impl Into<Meta<VTableRef<'a, V>>>) -> Selfwhere
V: Clone + 'a,
Construct a vector with the same type as the given vector without copying its data.
sourcepub unsafe fn from_raw_parts(data: VecVoid, vtable: Ptr<V>) -> VecDyn<V>
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.
sourcepub fn into_raw_parts(self) -> (VecVoid, Ptr<V>)
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.
sourcepub fn upcast<U: HasDrop + From<V>>(self) -> VecDyn<U>where
V: Clone,
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
sourcepub fn push_as<T: Elem>(&mut self, element: T) -> Option<&mut Self>
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.
sourcepub fn check<T: Elem>(self) -> Option<Self>
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.
sourcepub fn check_ref<T: Elem>(&self) -> Option<&Self>
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.
sourcepub fn check_mut<T: Elem>(&mut self) -> Option<&mut Self>
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.
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: Elem>(&self) -> Option<Iter<'_, T>>
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.
sourcepub fn iter_mut_as<T: Elem>(&mut self) -> Option<IterMut<'_, T>>
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.
sourcepub fn into_vec<T: Elem>(self) -> Option<Vec<T>>
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.
sourcepub fn as_slice_as<T: Elem>(&self) -> Option<&[T]>
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.
sourcepub fn as_mut_slice_as<T: Elem>(&mut self) -> Option<&mut [T]>
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.
sourcepub fn get_ref_as<T: Elem>(&self, i: usize) -> Option<&T>
pub fn get_ref_as<T: Elem>(&self, i: usize) -> Option<&T>
Get a const
reference to the i
’th element of the buffer.
sourcepub fn get_mut_as<T: Elem>(&mut self, i: usize) -> Option<&mut T>
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.
sourcepub fn append(&mut self, buf: &mut VecDyn<V>) -> Option<&mut Self>
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
.
sourcepub fn rotate_left(&mut self, mid: usize)
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.
sourcepub fn rotate_right(&mut self, k: usize)
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.
sourcepub fn push<U: ?Sized + HasDrop>(
&mut self,
value: BoxValue<U>
) -> Option<&mut Self>
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.
sourcepub fn push_cloned(&mut self, value: ValueRef<'_, V>) -> Option<&mut Self>where
V: HasClone,
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
.
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 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.
sourcepub fn get_mut(&mut self, i: usize) -> ValueMut<'_, V>
pub fn get_mut(&mut self, i: usize) -> ValueMut<'_, V>
Get a mutable reference to a value stored in this container at index i
.
sourcepub fn iter_mut(&mut self) -> impl Iterator<Item = ValueMut<'_, V>>
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.
pub fn as_slice(&self) -> Slice<'_, V>
pub fn as_mut_slice(&mut self) -> SliceMut<'_, V>
sourcepub unsafe fn get_unchecked_ref<T: Any>(&self, i: usize) -> &T
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 i
th 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.
sourcepub unsafe fn get_unchecked_mut<T: Any>(&mut self, i: usize) -> &mut T
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 i
th 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>
impl<V: HasDrop + HasClone> VecDyn<V>
source§impl<V: ?Sized + HasDrop + HasClone> VecDyn<V>
impl<V: ?Sized + HasDrop + HasClone> VecDyn<V>
sourcepub fn resize<T: Elem + Clone>(
&mut self,
new_len: usize,
value: T
) -> Option<&mut Self>
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
.
sourcepub fn fill<T: Elem + Clone>(&mut self, def: T) -> Option<&mut Self>
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.
Trait Implementations§
source§impl<T: Elem, V: ?Sized + HasDrop + VTable<T>> From<VecDyn<V>> for Option<Vec<T>>
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§impl<V: ?Sized + HasDrop + HasPartialEq> PartialEq for VecDyn<V>
impl<V: ?Sized + HasDrop + HasPartialEq> PartialEq for VecDyn<V>
impl<V: ?Sized + HasDrop + HasEq> Eq for VecDyn<V>
impl<V: ?Sized + HasDrop + HasSend> Send for VecDyn<V>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneBytes for Twhere
T: Clone + 'static,
impl<T> CloneBytes for Twhere
T: Clone + 'static,
unsafe fn clone_bytes(src: &[MaybeUninit<u8>]) -> Box<[MaybeUninit<u8>]>
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>] )
source§impl<T> DebugBytes for Twhere
T: Debug + 'static,
impl<T> DebugBytes for Twhere
T: Debug + 'static,
source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.