pub trait ComponentNode: DynPhases {
// Required methods
fn node_name(&self) -> &'static str;
fn children_mut(
&mut self,
) -> Vec<(String, &mut (dyn ComponentNode + 'static))>;
// Provided methods
fn port_slot(&self, name: &str) -> Option<Rc<dyn Any>> { ... }
fn port_infos(&self) -> Vec<PortInfo> { ... }
fn resolve_children(&mut self, ctx: &RustdvCtx) { ... }
fn take_children(&mut self) -> Vec<(String, Box<dyn ComponentNode>)> { ... }
fn restore_children(&mut self, taken: Vec<(String, Box<dyn ComponentNode>)>) { ... }
}Expand description
Structural traversal over the ownership tree (design-doc D5.2).
Generated by #[derive(Component)] for structs whose children are
fields marked #[component]; hand-implementable by design
(OQ-15: the derive is convenience, not requirement).
Required Methods§
Sourcefn node_name(&self) -> &'static str
fn node_name(&self) -> &'static str
The component’s type-level name (hierarchical path is synthesized from field names during traversal).
Sourcefn children_mut(&mut self) -> Vec<(String, &mut (dyn ComponentNode + 'static))>
fn children_mut(&mut self) -> Vec<(String, &mut (dyn ComponentNode + 'static))>
Direct children as (field-derived name, node) pairs, in declaration
order. An owned Vec, not a visit_children-style sync callback:
run_all awaits inside the walk, and a higher-ranked closure
cannot yield a child borrow that outlives the call, so the borrows
have to come back in a value the caller holds. An Option<T> child
created during build (D6) appears here only once it is Some.
Provided Methods§
Sourcefn port_slot(&self, name: &str) -> Option<Rc<dyn Any>>
fn port_slot(&self, name: &str) -> Option<Rc<dyn Any>>
This node’s port binding cell of the given name, erased (D83).
This method is the cast Rust does not have. A parent holds its
children as dyn ComponentNode and cannot recover their concrete
types, but it does not need to: it needs one port, by name, and a trait
method reaches through erasure by definition. #[derive(Component)]
generates the match arm for each #[port(..)] field; the default is
None, for components that declare no ports.
Sourcefn port_infos(&self) -> Vec<PortInfo>
fn port_infos(&self) -> Vec<PortInfo>
Every port this node declares, for the elaboration report.
Sourcefn resolve_children(&mut self, ctx: &RustdvCtx)
fn resolve_children(&mut self, ctx: &RustdvCtx)
Resolve factory overrides for this node’s RustdvComp fields (D75).
The derive generates this to call field.resolve(ctx, "field") for
each RustdvComp field; the default is a no-op for nodes with none.
Called by build_all after build, before descending — so a
swapped-out default’s own phases never run.
Sourcefn take_children(&mut self) -> Vec<(String, Box<dyn ComponentNode>)>
fn take_children(&mut self) -> Vec<(String, Box<dyn ComponentNode>)>
Move this node’s RustdvComp children out, for the run phase (D82b).
Returns owned boxes with no borrow relationship to self, which is what
lets run_all drive a parent’s own run concurrently with its
children’s. The derive generates this for RustdvComp fields; other
child shapes (Option<T>, Vec<T>, plain T) stay in place and are
reached through ComponentNode::children_mut as before.
The default returns nothing, so a hand-written ComponentNode keeps the
old behaviour and still compiles.
Sourcefn restore_children(&mut self, taken: Vec<(String, Box<dyn ComponentNode>)>)
fn restore_children(&mut self, taken: Vec<(String, Box<dyn ComponentNode>)>)
Put back what ComponentNode::take_children removed, in the same order.
Called unconditionally after the run phase — including on error — so the
post-run phases walk a whole tree.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".