Macro field
field!() { /* proc-macro */ }Expand description
Name a composite field or nested route as a marker type.
Write field!(Machine::controller::cpu) with the composite declaration name
first, followed by Rust field names. The generated namespace must be in scope;
renamed composite imports and root type aliases are not discovered automatically.
For generic roots, supply their arguments: field!(Machine<T>::controller::cpu).
The macro checks the route through CheckedRoute before resolving to its
unchanged nominal marker type. An unused type alias may defer that check.
Nested routes compose nominal markers with FieldPath and project the final
child. Route SOURCE describes the final field, not the full source prefix.
Ordinary state and source aliases are not field targets.
Child namespaces follow their authored type paths. Alternate type spellings need matching companion namespace reexports. Inventory generation requires a named child declaration; it cannot infer bare generic or associated children.
use vihaco_runtime::{composite, field};
use vihaco_runtime::Field;
#[composite]
struct Leaf { state: u8 }
#[composite]
struct Controller { #[device(1)] cpu: Leaf }
#[composite]
struct Machine {
#[device(7)] controller: Controller,
}
type Route = field!(Machine::controller::cpu);
type Child = <Machine as Field<Route>>::Child;
fn main() {
let _: Child = Leaf { state: 0 };
}Name an eligible composite field or nested route in type position.