pub struct NodeRegistry<S = ()> { /* private fields */ }Expand description
A per-S registry of node factories, named conditions, and mergers.
Registration is fail-fast at graph-build time: unknown type_names, condition names,
or merger names are reported by BspGraph::from_def
as a BspError::ValidationError listing every unknown name.
Implementations§
Source§impl<S> NodeRegistry<S>
impl<S> NodeRegistry<S>
Sourcepub fn register_node(
&mut self,
type_name: impl Into<String>,
factory: impl Fn(&NodeDef, &BspContext) -> Result<Box<dyn BspNode<S>>, BspError> + Send + Sync + 'static,
)
pub fn register_node( &mut self, type_name: impl Into<String>, factory: impl Fn(&NodeDef, &BspContext) -> Result<Box<dyn BspNode<S>>, BspError> + Send + Sync + 'static, )
Registers a node type factory under its type_name.
Sourcepub fn register_condition(
&mut self,
name: impl Into<String>,
f: impl Fn(&S, &ValueStore) -> bool + Send + Sync + 'static,
)
pub fn register_condition( &mut self, name: impl Into<String>, f: impl Fn(&S, &ValueStore) -> bool + Send + Sync + 'static, )
Registers a named condition predicate.
Sourcepub fn register_merger<M: Merger<S> + 'static>(
&mut self,
name: impl Into<String>,
merger: M,
)
pub fn register_merger<M: Merger<S> + 'static>( &mut self, name: impl Into<String>, merger: M, )
Registers a named merger.
Sourcepub fn register_value_factory(
&mut self,
factory: impl Fn(&Value) -> BspValue + Send + Sync + 'static,
)
pub fn register_value_factory( &mut self, factory: impl Fn(&Value) -> BspValue + Send + Sync + 'static, )
Overrides how GraphDef static-input JSON becomes typed
pin values at instantiation.
The default (default_value_factory) produces typed bool / i64 / u64 /
f64 / String values. Override this when your nodes expect different types —
e.g. everything as raw serde_json::Value:
registry.register_value_factory(|v| BspValue::new(v.clone())).
Sourcepub fn contains_node(&self, type_name: &str) -> bool
pub fn contains_node(&self, type_name: &str) -> bool
Returns whether a node type is registered.
Sourcepub fn contains_condition(&self, name: &str) -> bool
pub fn contains_condition(&self, name: &str) -> bool
Returns whether a condition is registered.
Sourcepub fn contains_merger(&self, name: &str) -> bool
pub fn contains_merger(&self, name: &str) -> bool
Returns whether a merger is registered.
Sourcepub fn node_type_names(&self) -> Vec<&str>
pub fn node_type_names(&self) -> Vec<&str>
The registered node type names (the GUI palette catalog).
Sourcepub fn with_node(
self,
type_name: impl Into<String>,
factory: impl Fn(&NodeDef, &BspContext) -> Result<Box<dyn BspNode<S>>, BspError> + Send + Sync + 'static,
) -> Self
pub fn with_node( self, type_name: impl Into<String>, factory: impl Fn(&NodeDef, &BspContext) -> Result<Box<dyn BspNode<S>>, BspError> + Send + Sync + 'static, ) -> Self
Builder variant of NodeRegistry::register_node.
Sourcepub fn with_condition(
self,
name: impl Into<String>,
f: impl Fn(&S, &ValueStore) -> bool + Send + Sync + 'static,
) -> Self
pub fn with_condition( self, name: impl Into<String>, f: impl Fn(&S, &ValueStore) -> bool + Send + Sync + 'static, ) -> Self
Builder variant of NodeRegistry::register_condition.
Sourcepub fn with_merger<M: Merger<S> + 'static>(
self,
name: impl Into<String>,
merger: M,
) -> Self
pub fn with_merger<M: Merger<S> + 'static>( self, name: impl Into<String>, merger: M, ) -> Self
Builder variant of NodeRegistry::register_merger.
Sourcepub fn with_value_factory(
self,
factory: impl Fn(&Value) -> BspValue + Send + Sync + 'static,
) -> Self
pub fn with_value_factory( self, factory: impl Fn(&Value) -> BspValue + Send + Sync + 'static, ) -> Self
Builder variant of NodeRegistry::register_value_factory.