pub trait VirtualStaticField<Discriminant: DiscriminantTag = ()>: Default {
type None: Delimited;
type Some: Delimited;
type Many: Collection<Self::Some>;
type Repr: Delimited + Default + FromTag<Self::None, NoneTag> + TryIntoTag<Self::None, NoneTag> + FromTag<Self::Some, SomeTag> + TryIntoTag<Self::Some, SomeTag> + FromTag<Self::Many, ManyTag> + TryIntoTag<Self::Many, ManyTag>;
// Required methods
fn access(&self) -> Self::Repr;
fn mutate(&mut self, v: Self::Repr);
}Expand description
A discriminant-keyed virtual field abstraction with statically determined cardinality.
This trait models a field whose structure is fully determined at compile time, rather than deferred.
§Model
A VirtualStaticField behaves like a field in a logical record,
where:
- cardinality is fixed or constrained at compile time
- storage shape is predetermined
- no dynamic resizing or growth is expected
Similar to VirtualDynField (but not dynamically sized):
- the implementor defines the backing representation (
Repr) - the caller selects the interpretation (
None,Some,Many)
§Representation Semantics
The Many form is expected to have array-like semantics:
- fixed size
- no resizing or allocation
- capacity encoded directly in the type
This makes VirtualStaticField suitable for:
- compile-time enforced layouts
- fixed schemas
- zero-overhead representations
§Discriminant
The Discriminant acts as a type-level key, allowing multiple independent
fields to coexist without ambiguity.
§Design
As with dynamic fields, responsibilities are separated:
- Implementor (Storage Layer)
- defines representation (
Repr)
- defines representation (
- Caller (Shape Layer)
- selects cardinality and interpretation
The key difference is that structure is not deferred, but fully determined at compile time.
§When to Use
Use this trait when:
- structure is known and fixed upfront
- dynamic resizing is unnecessary or undesirable
- compile-time guarantees are preferred over flexibility
§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 Many: Collection<Self::Some>
type Many: Collection<Self::Some>
A collection of Some.
Must support indexed access and have a statically determined size (array-like semantics).
Sourcetype Repr: Delimited + Default + FromTag<Self::None, NoneTag> + TryIntoTag<Self::None, NoneTag> + FromTag<Self::Some, SomeTag> + TryIntoTag<Self::Some, SomeTag> + FromTag<Self::Many, ManyTag> + TryIntoTag<Self::Many, ManyTag>
type Repr: Delimited + Default + FromTag<Self::None, NoneTag> + TryIntoTag<Self::None, NoneTag> + FromTag<Self::Some, SomeTag> + TryIntoTag<Self::Some, SomeTag> + FromTag<Self::Many, ManyTag> + TryIntoTag<Self::Many, ManyTag>
Opaque storage backing the virtual field.
Encodes the field state and supports tagged conversions
between None, Some, and Many.
Unlike dynamic fields, this representation is expected to be fully determined at compile time and not rely on dynamic resizing or buffering.
Required Methods§
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 VirtualStaticField for ()
No-op VirtualStaticField implementation for unit.
impl VirtualStaticField for ()
No-op VirtualStaticField implementation for unit.
Represents an allocation with no storage and zero capacity.