use super::{Completer, Directive};
use orphan_crippler::Sender;
use std::{fmt::Debug, num::NonZeroUsize};
pub trait Controller {
type Directive: Directive;
type DirectiveAdaptor: DirectiveAdaptor<Self::Directive> + Send + 'static;
type Error: Debug;
type Event;
type Pointers: IntoIterator<Item = AddOrRemovePtr>;
fn directive_adaptor(&self) -> Self::DirectiveAdaptor;
fn loop_cycle(&self) -> Result<LoopCycle<Self::Event, Self::Directive>, Self::Error>;
fn process_directive<C: Completer>(
&self,
directive: Self::Directive,
completer: &mut C,
) -> Self::Pointers;
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub enum AddOrRemovePtr {
DoNothing,
AddPtr(NonZeroUsize, usize),
RemovePtr(NonZeroUsize),
}
impl Default for AddOrRemovePtr {
#[inline]
fn default() -> Self {
AddOrRemovePtr::DoNothing
}
}
pub enum LoopCycle<Event, Directive> {
Break,
Continue(Event),
Directive(Sender<Directive>),
}
pub trait DirectiveAdaptor<Directive> {
fn send(&mut self, directive: Sender<Directive>);
}