pub trait KeyedNodeTemplate<N, P, K> {
// Required methods
fn node_data(&self) -> N;
fn keyed_ports(&self) -> Vec<(K, P)>;
}Expand description
A reusable component whose pins each carry a key — typically an enum variant — declared alongside their data.
This is the keyed sibling of NodeTemplate. It exists to kill positional
index bookkeeping: the pin’s identity and its data are stated together in
one list, and Graph::instantiate_keyed returns a key → PortId map, so
no call site ever refers to a pin by integer position.
#[derive(PartialEq, Eq, Hash, Clone, Copy)]
enum Pin { Anode, Cathode }
struct Diode;
impl KeyedNodeTemplate<&'static str, &'static str, Pin> for Diode {
fn node_data(&self) -> &'static str { "D" }
fn keyed_ports(&self) -> Vec<(Pin, &'static str)> {
vec![(Pin::Anode, "+"), (Pin::Cathode, "-")]
}
}Required Methods§
Sourcefn keyed_ports(&self) -> Vec<(K, P)>
fn keyed_ports(&self) -> Vec<(K, P)>
Fresh (key, port data) pairs in pinout order. The key is what you’ll
look up by; the data is the port payload.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".