use crate::scheduler::action::{Context, Options};
use crate::scheduler::signal::Id;
use super::descriptor::Descriptor;
mod handler;
mod kind;
pub use handler::{Handler, Iter};
pub use kind::{Kind, Source, Worker};
#[derive(Debug)]
pub struct Node<I> {
descriptor: Descriptor,
kind: Kind<I>,
}
impl<I> Node<I>
where
I: Id,
{
#[must_use]
pub fn new<K>(descriptor: Descriptor, kind: K) -> Self
where
K: Into<Kind<I>>,
{
Self { descriptor, kind: kind.into() }
}
#[inline]
pub fn execute(&mut self, ctx: Context<I>) -> Iter<'_, I> {
match &mut self.kind {
Kind::Source(source) => source.execute(ctx),
Kind::Worker(worker) => worker.execute(ctx),
}
}
}
#[allow(clippy::must_use_candidate)]
impl<I> Node<I> {
#[inline]
pub fn descriptor(&self) -> &Descriptor {
&self.descriptor
}
pub fn options(&self) -> &Options {
match &self.kind {
Kind::Source(source) => source.options(),
Kind::Worker(worker) => worker.options(),
}
}
pub fn as_source_mut(&mut self) -> Option<&mut Source<I>> {
if let Kind::Source(source) = &mut self.kind {
Some(source)
} else {
None
}
}
pub fn as_worker_mut(&mut self) -> Option<&mut Worker<I>> {
if let Kind::Worker(worker) = &mut self.kind {
Some(worker)
} else {
None
}
}
}