aboutsummaryrefslogtreecommitdiffstats
path: root/src/node.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/node.rs')
-rw-r--r--src/node.rs32
1 files changed, 23 insertions, 9 deletions
diff --git a/src/node.rs b/src/node.rs
index b63270e..a279eb9 100644
--- a/src/node.rs
+++ b/src/node.rs
@@ -8,6 +8,7 @@ use crate::types::{Type, TypeSignature};
#[derive(Debug, Copy, Clone)]
pub enum CompileError {
MissingArguments,
+ InvalidArguments,
Codegen(fmt::Error),
}
@@ -18,26 +19,39 @@ impl From<fmt::Error> for CompileError {
}
/// an instantiable Node, parametrized by its connected input types
+pub const MAX_INPUTS: usize = 16;
+
#[enum_dispatch]
pub trait ConcreteNode {
- fn max_inputs(&self) -> usize;
- fn num_inputs(&self, _connected: &[Option<Type>]) -> usize {
- self.max_inputs()
- }
-
- // set of possible input type combinations given current connections
- fn signatures_matching(&self, connected: &[Option<Type>]) -> Vec<TypeSignature>;
+ /// given the current connections, which inputs are available?
+ ///
+ /// This can return more inputs than those connected, indicating missing or optional connections.
+ /// This must not fail but fallback to a default signature that allows connections to be made.
+ fn visible_inputs(&self, connected: &[Option<Type>; MAX_INPUTS]) -> Vec<Option<Type>>;
- fn signature(&self, connected: &[Option<Type>]) -> TypeSignature;
+ /// given the current connections, what is this node's signature?
+ ///
+ /// This determines the output types shown and is used for compilation. If no valid signature corresponds
+ /// to the set of inputs, this must fail. If the implementation accepts optional inputs, it may validate
+ /// them here or leave that to be done in `compile`.
+ fn signature(
+ &self,
+ connected: &[Option<Type>; MAX_INPUTS],
+ ) -> Result<TypeSignature, CompileError>;
+ /// generate code for this node.
+ ///
+ /// The number of `inputs` and `outputs` correspond to the types in `signature`.
+ /// This must fail if valid code can not be generated.
fn compile(
&self,
+ f: &mut dyn fmt::Write,
signature: TypeSignature,
inputs: Vec<Option<String>>,
outputs: Vec<String>,
- f: &mut dyn fmt::Write,
) -> Result<(), CompileError>;
+ /// optionaly render additional UI in the body of this node.
fn show_body(&mut self, ui: &mut egui::Ui) -> egui::Response {
ui.response()
}