dope-core 0.75.0

Owned native I/O and completion driver for dope
Documentation
use std::{ops, pin};

use crate::driver::{self, life, schedule, settings};

use crate::executor;

/// Application storage metadata independent of lifecycle eligibility.
pub trait Layout<'d> {
    type Scope: driver::route::Selection;
    /// Pre-park state selected once and retained with this pinned application.
    type ParkPlan: executor::raw::Plan;
}

/// # Safety
/// Visit each owner once through unchanged pinned projections, presence, and operation authority.
/// Admission includes every present owner's route, without merging duplicate owners.
/// Keep the root pinned; shutdown preserves client storage and finish destroys dependents before providers.
/// A fixed `Scope` names this owner's admitted completion route.
/// `ParkPlan = ()` runs `park` directly; `Flat` runs the unchanged `census`/`sweep` traversal.
pub unsafe trait App<'d>: Sized + Layout<'d> {
    const ROUTES: settings::Routes;

    /// Routes on which a nested application may observe a completion.
    const DISPATCH_ROUTES: settings::Routes = Self::ROUTES;

    /// Routes whose installed owners may receive activation.
    const WAKE_ROUTES: settings::Routes = settings::Routes::EMPTY;

    /// Upper bound on idle coordinator probes, including delegated probes.
    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(())
    }

    /// # Safety
    /// Traverse the same admitted pinned owners in their census order.
    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 {
            // SAFETY: this leaf retains the census-admitted root and turn.
            unsafe { sweep.leaf(app) };
        }
    }

    /// # Safety
    /// The exact pinned root is installed and admitted. Run this leaf's work
    /// or this aggregate's own coordinator with the same driver and turn.
    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,
    {
    }

    /// Accumulates the routes of the owners actually present in this pinned root.
    fn admit(
        _: pin::Pin<&Self>,
        needs: &mut settings::claim::Needs,
    ) -> Result<(), settings::errors::Claim> {
        *needs = needs.include(settings::claim::Claim::new(Self::ROUTES))?;
        Ok(())
    }

    /// # Safety
    /// All external clients of this exact pinned owner have ended.
    unsafe fn released(_: pin::Pin<&mut Self>) {}

    fn install(_: pin::Pin<&mut Self>, _: life::Install<'_, 'd>) {}

    /// Returns whether a present owner handled this activation. On `false`,
    /// the caller may continue through the remaining owners of the same root.
    ///
    /// # Safety
    /// Use this exact installed pinned root, driver and turn, with a target
    /// belonging to the same driver and declared by `WAKE_ROUTES`.
    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
    }

    /// Resolves overlapping candidate routes against the receivers actually installed in this root.
    fn has_dispatch_owner(_: pin::Pin<&Self>, route: driver::route::Route) -> bool {
        Self::DISPATCH_ROUTES.has_route(route)
    }

    /// A selected receiver consumes the completion or returns it to the driver.
    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)
    }

    /// Reports waits into the same traversal until an owner can run immediately.
    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 = ();
}

// SAFETY: the empty root has no routes, retained owners, or lifecycle work.
unsafe impl<'d> App<'d> for () {
    const ROUTES: settings::Routes = settings::Routes::EMPTY;
}