pub struct PokeListLike<'mem, 'facet> { /* private fields */ }Expand description
Lets you mutate a list, array or slice.
Implementations§
Source§impl<'mem, 'facet> PokeListLike<'mem, 'facet>
impl<'mem, 'facet> PokeListLike<'mem, 'facet>
Sourcepub unsafe fn new(value: Poke<'mem, 'facet>, def: ListLikeDef) -> Self
pub unsafe fn new(value: Poke<'mem, 'facet>, def: ListLikeDef) -> Self
Creates a new poke list-like
§Safety
The caller must ensure that def contains valid vtable function pointers that:
- Correctly implement the list-like operations for the actual type
- Do not cause undefined behavior when called
- Return pointers within valid memory bounds
- Match the element type specified in
def.t()
Sourcepub const fn def(&self) -> ListLikeDef
pub const fn def(&self) -> ListLikeDef
Def getter.
Sourcepub fn get(&self, index: usize) -> Option<Peek<'_, 'facet>>
pub fn get(&self, index: usize) -> Option<Peek<'_, 'facet>>
Get a read-only Peek for the item at the specified index.
Sourcepub fn get_mut(&mut self, index: usize) -> Option<Poke<'_, 'facet>>
pub fn get_mut(&mut self, index: usize) -> Option<Poke<'_, 'facet>>
Get a mutable Poke for the item at the specified index.
Sourcepub fn iter_mut(self) -> Result<PokeListLikeIter<'mem, 'facet>, ReflectError>
pub fn iter_mut(self) -> Result<PokeListLikeIter<'mem, 'facet>, ReflectError>
Returns a mutable iterator over the list-like.
Requires contiguous mutable access to the backing storage: the element type must be
sized, and for List the vtable must expose as_mut_ptr. (Array and Slice always
expose as_mut_ptr.) Returns ReflectErrorKind::OperationFailed if either condition
fails; use PokeListLike::get_mut per index when iter_mut is unavailable.
The previous fallback that synthesized a mutable iterator from the list’s iter_vtable
was unsound: that vtable yields PtrConst items backed by shared references, and
writing through them is UB.
Sourcepub fn push<T: Facet<'facet>>(&mut self, value: T) -> Result<(), ReflectError>
pub fn push<T: Facet<'facet>>(&mut self, value: T) -> Result<(), ReflectError>
Push a value onto the end of the list.
Only supported for List variants whose element type provides a push
operation (e.g. Vec<T>). Fails for arrays and slices as their length
is fixed.
Sourcepub fn push_from_heap<const BORROW: bool>(
&mut self,
value: HeapValue<'facet, BORROW>,
) -> Result<(), ReflectError>
pub fn push_from_heap<const BORROW: bool>( &mut self, value: HeapValue<'facet, BORROW>, ) -> Result<(), ReflectError>
Sourcepub fn pop(&mut self) -> Result<Option<HeapValue<'facet, true>>, ReflectError>
pub fn pop(&mut self) -> Result<Option<HeapValue<'facet, true>>, ReflectError>
Pop the last value off the end of the list.
Returns Ok(None) if the list is empty. Only supported for List
variants whose element type provides a pop operation.
Sourcepub fn swap(&mut self, a: usize, b: usize) -> Result<(), ReflectError>
pub fn swap(&mut self, a: usize, b: usize) -> Result<(), ReflectError>
Swap the elements at indices a and b.
For List variants, uses the list’s swap vtable entry if present and
errors otherwise. For Array and Slice variants, performs a generic
byte-swap using the element stride (always available). Returns an error
if either index is out of bounds. Swapping an index with itself is a
no-op.
Sourcepub fn into_inner(self) -> Poke<'mem, 'facet>
pub fn into_inner(self) -> Poke<'mem, 'facet>
Converts this PokeListLike back into a Poke.
Sourcepub fn as_peek_list_like(&self) -> PeekListLike<'_, 'facet>
pub fn as_peek_list_like(&self) -> PeekListLike<'_, 'facet>
Returns a read-only PeekListLike view.