use std::{ops, pin};
use crate::driver::{self, life, schedule, settings};
use crate::executor;
pub trait Layout<'d> {
type Scope: driver::route::Selection;
type ParkPlan: executor::raw::Plan;
}
pub unsafe trait App<'d>: Sized + Layout<'d> {
const ROUTES: settings::Routes;
const DISPATCH_ROUTES: settings::Routes = Self::ROUTES;
const WAKE_ROUTES: settings::Routes = settings::Routes::EMPTY;
const COORDS: usize = 0;
const PARK: bool = false;
fn census(_: pin::Pin<&Self>, counts: &mut executor::raw::Census) -> Option<()> {
if Self::PARK {
counts.include_leaf(Self::COORDS)?;
}
Some(())
}
unsafe fn sweep<'app, 'driver, 'turn>(
app: pin::Pin<&'app mut Self>,
sweep: &mut executor::raw::Sweep<'driver, 'turn, 'd, impl crate::io::Report>,
) where
'd: 'driver + 'turn,
{
if Self::PARK {
unsafe { sweep.leaf(app) };
}
}
unsafe fn park<'app, 'driver, 'turn>(
_: pin::Pin<&'app mut Self>,
_: schedule::Turn<'turn, 'd>,
_: &'driver mut driver::life::Lifecycle<'d, impl crate::io::Report>,
) where
'd: 'driver + 'turn,
{
}
fn admit(
_: pin::Pin<&Self>,
needs: &mut settings::claim::Needs,
) -> Result<(), settings::errors::Claim> {
*needs = needs.include(settings::claim::Claim::new(Self::ROUTES))?;
Ok(())
}
unsafe fn released(_: pin::Pin<&mut Self>) {}
fn install(_: pin::Pin<&mut Self>, _: life::Install<'_, 'd>) {}
unsafe fn activate<'app, 'driver, 'turn>(
_: pin::Pin<&'app mut Self>,
_: driver::route::Erased<'d, driver::route::kind::Any>,
_: schedule::Turn<'turn, 'd>,
_: &'driver mut driver::life::Lifecycle<'d, impl crate::io::Report>,
) -> bool
where
'd: 'driver + 'turn,
{
false
}
fn has_dispatch_owner(_: pin::Pin<&Self>, route: driver::route::Route) -> bool {
Self::DISPATCH_ROUTES.has_route(route)
}
fn dispatch<'event>(
_: pin::Pin<&mut Self>,
event: executor::raw::Dispatch<'event, 'd, Self::Scope>,
_: schedule::Turn<'_, 'd>,
_: &mut driver::life::Lifecycle<'d, impl crate::io::Report>,
) -> ops::ControlFlow<executor::raw::Dispatch<'event, 'd, Self::Scope>> {
ops::ControlFlow::Break(event)
}
fn progress<const STOP: bool>(
_: pin::Pin<&Self>,
_: executor::raw::Progress<'_, '_, 'd>,
_: Option<&mut schedule::Waits<'d>>,
) -> ops::ControlFlow<()> {
ops::ControlFlow::Continue(())
}
fn shutdown(
_: pin::Pin<&mut Self>,
_: schedule::Turn<'_, 'd>,
_: &mut driver::life::Lifecycle<'d, impl crate::io::Report>,
) {
}
fn finish(
_: pin::Pin<&mut Self>,
_: life::Install<'_, 'd>,
_: &mut life::finish::Finish<'_, 'd, impl crate::io::Report>,
) {
}
}
impl<'d> Layout<'d> for () {
type Scope = std::convert::Infallible;
type ParkPlan = ();
}
unsafe impl<'d> App<'d> for () {
const ROUTES: settings::Routes = settings::Routes::EMPTY;
}