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§
Sourcefn index_get(&self, index: usize) -> Option<Self::Some>
fn index_get(&self, index: usize) -> Option<Self::Some>
Returns the element at index from the field interpreted as Many.
§Behavior
- Returns
Some(V)if the field contains a collection andindexis in bounds - Returns
Noneif the field isNone,Some, or out of bounds
Sourcefn iter(&self) -> impl Iterator<Item = Self::Some>
fn iter(&self) -> impl Iterator<Item = Self::Some>
Returns an iterator over elements in the field interpreted as Many.
If the field is not Many, the iterator will be empty.
Sourcefn iter_mut<F>(&mut self, f: F) -> Result<(), ()>
fn iter_mut<F>(&mut self, f: F) -> Result<(), ()>
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
Sourcefn index_set(&mut self, index: usize, value: Self::Some) -> Result<(), ()>
fn index_set(&mut self, index: usize, value: Self::Some) -> Result<(), ()>
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
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§
impl<T, K> DynFieldHelpers<K> for Twhere
T: VirtualDynField<K>,
K: DiscriminantTag,
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.