use interface::{Data, Read, UniqueIdentifier, Write};
use super::OutputRx;
pub trait AddActorInput<U, C, const NI: usize, const NO: usize>
where
C: Read<U>,
U: 'static + UniqueIdentifier,
{
fn add_input(&mut self, rx: flume::Receiver<Data<U>>, hash: u64);
}
pub trait TryIntoInputs<U, CO, const NO: usize, const N: usize>
where
U: 'static + UniqueIdentifier,
CO: 'static + Write<U>,
{
fn into_input<CI>(self, actor: &mut impl AddActorInput<U, CI, NO, N>) -> Self
where
CI: 'static + Read<U>,
Self: Sized;
}
impl<U, CO, const NO: usize, const NI: usize, const N: usize> TryIntoInputs<U, CO, NO, N>
for std::result::Result<(), OutputRx<U, CO, NI, NO>>
where
U: 'static + UniqueIdentifier,
CO: 'static + Write<U>,
{
fn into_input<CI>(mut self, actor: &mut impl AddActorInput<U, CI, NO, N>) -> Self
where
CI: 'static + Read<U>,
{
let Err(OutputRx {
hash, ref mut rxs, ..
}) = self
else {
panic!(r#"Input receivers have been exhausted"#)
};
let Some(recv) = rxs.pop() else {
panic!(r#"Input receivers is empty"#)
};
actor.add_input(recv, hash);
if rxs.is_empty() {
Ok(())
} else {
self
}
}
}