Trait DynFieldHelpers

Source
pub trait DynFieldHelpers<K = ()>: VirtualDynField<K>
where K: DiscriminantTag,
{ // Provided methods fn index_get(&self, index: usize) -> Option<Self::Some> where Self::Some: Clone { ... } fn iter(&self) -> impl Iterator<Item = Self::Some> where Self::Some: Clone { ... } fn iter_mut<F>(&mut self, f: F) -> Result<(), ()> where F: FnMut(&mut Self::Some) { ... } fn index_set(&mut self, index: usize, value: Self::Some) -> Result<(), ()> where Self::Some: Default { ... } fn get(&self) -> Option<Self::Some> { ... } fn set(&mut self, v: Self::Some) where Self::Some: Delimited { ... } }
Expand description

Helper methods for accessing and mutating values in a VirtualDynField.

These helpers operate on dynamically shaped fields with vector-like semantics:

  • collections may grow or shrink (within bounds)
  • indexing and iteration are supported
  • mutations may reallocate or fail due to bounds

All operations are performed via tagged conversions.

§Default Discriminant

  • K = (): operates on a single default field, meaning one virtual field is assumed.

Provided Methods§

Source

fn index_get(&self, index: usize) -> Option<Self::Some>
where Self::Some: Clone,

Returns the element at index from the field interpreted as Many.

§Behavior
  • Returns Some(V) if the field contains a collection and index is in bounds
  • Returns None if the field is None, Some, or out of bounds
Source

fn iter(&self) -> impl Iterator<Item = Self::Some>
where Self::Some: Clone,

Returns an iterator over elements in the field interpreted as Many.

If the field is not Many, the iterator will be empty.

Source

fn iter_mut<F>(&mut self, f: F) -> Result<(), ()>
where F: FnMut(&mut Self::Some),

Applies a mutable operation to each element in the field interpreted as Many.

After mutation, the updated collection is written back to the container.

§Errors
  • Returns Err(()) if conversion back into the representation fails
Source

fn index_set(&mut self, index: usize, value: Self::Some) -> Result<(), ()>
where Self::Some: Default,

Sets the element at index in the field interpreted as Many.

If the field is not currently a collection or is too short, it is extended with default values.

§Errors
  • Returns Err(()) if conversion back fails
Source

fn get(&self) -> Option<Self::Some>

Retrieves the value of the field interpreted as Some.

§Behavior
  • Returns Some(V) if the field contains a single value
  • Returns None otherwise
Source

fn set(&mut self, v: Self::Some)
where Self::Some: Delimited,

Sets the field to a single value (Some).

Replaces any existing representation.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<T, K> DynFieldHelpers<K> for T

Blanket impl for all VirtualDynField types.

This trait is not intended to be implemented manually. It exists as an ergonomic replacement for free helper functions.

All methods have default implementations, making this forward-compatible: new helpers can be added without breaking existing code.