use std::{num::NonZero, ops::ControlFlow, pin};
use crate::driver::{self, schedule};
use o3::base::{cell::region, num::bounded::U32};
use crate::executor;
mod app;
mod owner;
mod plan;
mod progress;
pub use crate::io::event::{Dispatch, Occupied};
pub use app::{App, Layout};
pub(crate) use owner::{Backing, Draining, Live, Owner, View};
pub use plan::{Census, Flat, Plan, Sweep};
pub use progress::Progress;
pub unsafe trait Drain<'d>: executor::raw::App<'d> {
fn begin(
self: pin::Pin<&mut Self>,
turn: schedule::Turn<'_, 'd>,
driver: &mut driver::life::Lifecycle<'d, impl crate::io::Report>,
);
fn progress(
self: pin::Pin<&Self>,
region: ®ion::Token<region::Identity<'d>>,
state: Option<&mut schedule::Waits<'d>>,
) -> ControlFlow<()>;
fn force(
self: pin::Pin<&mut Self>,
turn: schedule::Turn<'_, 'd>,
driver: &mut driver::life::Lifecycle<'d, impl crate::io::Report>,
);
}
#[derive(Clone, Copy, Debug)]
pub enum Count {
Bounded(U32<0, { schedule::LIMIT as u32 }>),
Excess(NonZero<usize>),
}
impl Count {
pub const fn new(value: usize) -> Self {
match U32::from_usize(value) {
Some(value) => Self::Bounded(value),
None => Self::Excess(NonZero::<usize>::MIN.saturating_add(value - 1)),
}
}
pub const fn get(self) -> usize {
match self {
Self::Bounded(value) => value.into_usize(),
Self::Excess(value) => value.get(),
}
}
pub(in crate::executor::raw) fn admit<E>(self) -> Result<(), executor::InstallError<E>> {
match self {
Self::Bounded(_) => Ok(()),
Self::Excess(count) => Err(executor::InstallError::Coordinators {
count,
limit: schedule::LIMIT,
}),
}
}
}