use core::{fmt::Debug, ops::AddAssign};
use crate::{WithWorkContextProvider, WithWorkInputOutput, WorkContextProvider};
pub trait ScheduledWork: WithWorkInputOutput + WithWorkContextProvider {
fn tick(
&mut self,
input: Self::Tick,
context: &mut <Self::WorkContextProvider as WorkContextProvider>::Item<'_>,
) -> WorkResult;
fn on_scheduled_hook(&mut self, tick_input: Self::Tick);
}
#[derive(Debug)]
pub enum WorkResult {
Done,
Pending,
}
impl AddAssign for WorkResult {
fn add_assign(&mut self, rhs: Self) {
let change = match self {
Self::Pending => Some(rhs),
Self::Done => match rhs {
Self::Pending => None,
_ => Some(rhs),
},
};
if let Some(change) = change {
*self = change;
}
}
}