pub trait VirtualDynField<Discriminant: DiscriminantTag = ()>: Default {
type None: Delimited;
type Some: Delimited;
type Many: Buffer<Self::Some>;
type Repr: Delimited + Default + FromTag<Self::None, NoneTag> + TryIntoTag<Self::None, NoneTag> + FromTag<Self::Some, SomeTag> + TryIntoTag<Self::Some, SomeTag> + TryFromTag<Self::Many, ManyTag> + IntoTag<Self::Many, ManyTag>;
// Required methods
fn access(&self) -> Self::Repr;
fn mutate(&mut self, v: Self::Repr);
fn len(&self) -> usize;
fn min(&self) -> usize;
fn max(&self) -> usize;
}Expand description
A discriminant-keyed virtual field abstraction with flexible cardinality
(None, Some, or Many).
This trait models a field whose structure is deferred and resolved through types rather than fixed upfront.
§Model
A VirtualDynField behaves like a field in a logical record, without
committing to:
- a concrete container (
Option,Vec, etc.) - a fixed cardinality
- or a fixed storage layout
Instead:
- the implementor defines the backing representation (
Repr) - the caller selects the shape (
None,Some, orMany)
§Representation Semantics
The Many form is expected to have vector-like semantics:
- dynamically sized (within bounds)
- growable and shrinkable
- capacity enforced but not encoded in the type shape
This makes VirtualDynField suitable for:
- flexible schemas
- deferred structure
- abstraction across boundaries
§Discriminant
The Discriminant acts as a type-level key, allowing multiple independent
fields to coexist without ambiguity.
§Design
Responsibilities are separated:
- Implementor (Storage Layer)
- defines representation (
Repr)
- defines representation (
- Caller (Shape Layer)
- selects cardinality and interpretation
This decouples logical meaning from physical storage.
§When to Use
Use this trait when:
- structure must remain flexible
- cardinality is not known upfront
- storage must be abstract and composable
§Default Discriminant
Discriminant = (): uses the unit type as a single field key, meaning only one virtual field exists (no disambiguation needed).
Required Associated Types§
Sourcetype Repr: Delimited + Default + FromTag<Self::None, NoneTag> + TryIntoTag<Self::None, NoneTag> + FromTag<Self::Some, SomeTag> + TryIntoTag<Self::Some, SomeTag> + TryFromTag<Self::Many, ManyTag> + IntoTag<Self::Many, ManyTag>
type Repr: Delimited + Default + FromTag<Self::None, NoneTag> + TryIntoTag<Self::None, NoneTag> + FromTag<Self::Some, SomeTag> + TryIntoTag<Self::Some, SomeTag> + TryFromTag<Self::Many, ManyTag> + IntoTag<Self::Many, ManyTag>
Opaque storage backing the virtual field.
Encodes the actual data and must support tagged conversions
to and from None, Some, and Many.
Required Methods§
Sourcefn access(&self) -> Self::Repr
fn access(&self) -> Self::Repr
Returns the current representation of the virtual field.
Interaction is performed via tagged conversions.
Sourcefn mutate(&mut self, v: Self::Repr)
fn mutate(&mut self, v: Self::Repr)
Replaces the current representation.
The provided value must satisfy representation invariants.
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.
Implementations on Foreign Types§
Source§impl VirtualDynField for ()
No-op VirtualDynField implementation for unit.
impl VirtualDynField for ()
No-op VirtualDynField implementation for unit.
Represents an allocation with no storage and zero capacity.