Skip to main content

PokeListLike

Struct PokeListLike 

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

Source

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()
Source

pub const fn len(&self) -> usize

Get the length of the list-like.

Source

pub const fn is_empty(&self) -> bool

Returns true if the list-like is empty.

Source

pub const fn def(&self) -> ListLikeDef

Def getter.

Source

pub fn get(&self, index: usize) -> Option<Peek<'_, 'facet>>

Get a read-only Peek for the item at the specified index.

Source

pub fn get_mut(&mut self, index: usize) -> Option<Poke<'_, 'facet>>

Get a mutable Poke for the item at the specified index.

Source

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.

Source

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.

Source

pub fn push_from_heap<const BORROW: bool>( &mut self, value: HeapValue<'facet, BORROW>, ) -> Result<(), ReflectError>

Type-erased push.

Accepts a HeapValue whose shape must match the list’s element type. The value is moved out of the HeapValue into the list.

Source

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.

Source

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.

Source

pub fn into_inner(self) -> Poke<'mem, 'facet>

Converts this PokeListLike back into a Poke.

Source

pub fn as_peek_list_like(&self) -> PeekListLike<'_, 'facet>

Returns a read-only PeekListLike view.

Trait Implementations§

Source§

impl<'mem, 'facet> Debug for PokeListLike<'mem, 'facet>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'mem, 'facet> Freeze for PokeListLike<'mem, 'facet>

§

impl<'mem, 'facet> RefUnwindSafe for PokeListLike<'mem, 'facet>

§

impl<'mem, 'facet> !Send for PokeListLike<'mem, 'facet>

§

impl<'mem, 'facet> !Sync for PokeListLike<'mem, 'facet>

§

impl<'mem, 'facet> Unpin for PokeListLike<'mem, 'facet>

§

impl<'mem, 'facet> UnsafeUnpin for PokeListLike<'mem, 'facet>

§

impl<'mem, 'facet> !UnwindSafe for PokeListLike<'mem, 'facet>

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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

Source§

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.