use crate::Sockets;
use std::any::TypeId;
pub struct SocketDescription<T> {
pub(crate) inputs: Vec<TypeId>,
pub(crate) outputs: Vec<OutputSocket<T>>,
}
pub(crate) struct OutputSocket<T> {
pub(crate) type_: TypeId,
pub(crate) buffer: T,
}
impl<T> OutputSocket<T> {
pub fn new<O: Into<T> + 'static>(buffer: O) -> Self {
Self {
type_: TypeId::of::<O>(),
buffer: buffer.into(),
}
}
}
impl<T> SocketDescription<T> {
pub fn new() -> Self {
Self {
inputs: Vec::new(),
outputs: Vec::new(),
}
}
pub fn push_input<I: 'static>(&mut self)
where
T: TryInto<I>,
{
self.inputs.push(TypeId::of::<I>())
}
pub fn push_output<O: Into<T> + Default + 'static>(&mut self) {
self.push_output_with_buffer(O::default())
}
pub fn push_output_with_buffer<O: Into<T> + 'static>(&mut self, buffer: O) {
self.outputs.push(OutputSocket::new(buffer))
}
}
#[enum_delegate::register]
pub trait Node {
type Config;
type Context;
type Data;
fn sockets(&self, config: &Self::Config) -> SocketDescription<Self::Data>;
#[allow(unused_variables)]
fn rt_transfer_state(&mut self, source: Self)
where
Self: Sized,
{
}
fn rt_process(&mut self, context: &Self::Context, sockets: Sockets<Self::Data>);
}