Skip to main content

vihaco_runtime/
field.rs

1// SPDX-FileCopyrightText: 2026 The vihaco Authors
2// SPDX-License-Identifier: MIT
3
4/// Access a composite field route and describe its child type and source spellings.
5///
6/// Each eligible field has a nominal marker generated by the composite macro.
7/// Use [`crate::field!`] to name a field or an arbitrarily nested route, such as
8/// `field!(Composite::field::nested)`. The marker need not be named directly.
9/// The child is the exact authored field type in the parent declaration scope.
10/// Imported aliases and associated/generic child types retain Rust identity.
11/// Ordinary state fields do not participate in field routes or capability lifting.
12/// Without `program-image-execution`, legacy `#[loadable]` fields also stop route
13/// traversal and capability lifting; their sections are loaded separately.
14///
15/// Use this trait in bounds on consumers of field routes. Implementations are
16/// supplied by [`crate::composite`] and the generated route traversal.
17pub trait Field<F> {
18    /// The exact type of the final child selected by the route.
19    type Child;
20    /// Borrow the selected child for the lifetime of this composite borrow.
21    fn get(&self) -> &Self::Child;
22    /// Mutably borrow the selected child for the lifetime of this composite borrow.
23    fn get_mut(&mut self) -> &mut Self::Child;
24    /// Canonical name of the final field first, then its aliases in declaration order.
25    const SOURCE: &'static [&'static str];
26}