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///
13/// Use this trait in bounds on consumers of field routes. Implementations are
14/// supplied by [`crate::composite`] and the generated route traversal.
15pub trait Field<F> {
16    /// The exact type of the final child selected by the route.
17    type Child;
18    /// Borrow the selected child for the lifetime of this composite borrow.
19    fn get(&self) -> &Self::Child;
20    /// Mutably borrow the selected child for the lifetime of this composite borrow.
21    fn get_mut(&mut self) -> &mut Self::Child;
22    /// Canonical name of the final field first, then its aliases in declaration order.
23    const SOURCE: &'static [&'static str];
24}