Skip to main content

Dispatcher

Struct Dispatcher 

Source
pub struct Dispatcher<const N: usize, const E: usize, I: Index = usize> { /* private fields */ }
Expand description

Fixed-capacity online dispatcher for up to N time points and E adjacency entries, storing internal handles as I (see Index).

§Examples

use temporal_control::{DispatchEdge, Dispatcher, PointKind, Ticks, TimePoint};

// 5 <= t_1 - t_0 <= 15
let points = [PointKind::Executable; 2];
let edges = [
    DispatchEdge { from: TimePoint(0), to: TimePoint(1), weight: Ticks(15) },
    DispatchEdge { from: TimePoint(1), to: TimePoint(0), weight: Ticks(-5) },
];
let mut d = Dispatcher::<2, 4>::new(&points, &edges, &[]).expect("fits");
let mut out = [TimePoint(0); 2];

assert_eq!(d.step(Ticks(0), &[], &mut out), Ok(1)); // t_0 = 0
assert_eq!(d.step(Ticks(4), &[], &mut out), Ok(0)); // too early for t_1
assert_eq!(d.step(Ticks(5), &[], &mut out), Ok(1)); // t_1 = 5
assert!(d.is_complete());

Implementations§

Source§

impl<const N: usize, const E: usize, I: Index> Dispatcher<N, E, I>

Source

pub const EMPTY: Self

A dispatcher with no network loaded, usable in const and static initialisers.

Flight software typically places the dispatcher in statically allocated memory once and then calls Self::load for every new plan, so the (possibly large) structure is never built on the stack and returned by value. With no network loaded the dispatcher has no points, Self::is_complete is true and every point handle is unknown.

§Examples
use temporal_control::{DispatchEdge, Dispatcher, PointKind, Ticks, TimePoint};

// Built at compile time; a flight build would put this behind its own cell type.
static IDLE: Dispatcher<8, 32> = Dispatcher::EMPTY;
assert!(IDLE.is_complete());

let mut d = Dispatcher::<8, 32>::EMPTY;
let edges = [DispatchEdge { from: TimePoint(0), to: TimePoint(1), weight: Ticks(10) }];
d.load(&[PointKind::Executable; 2], &edges, &[]).expect("fits");
assert!(!d.is_complete());
Source

pub fn new( points: &[PointKind], edges: &[DispatchEdge], waits: &[Wait], ) -> Result<Self, DispatchError>

Validates a dispatchable network and loads it into a new dispatcher.

Shorthand for Self::EMPTY followed by Self::load. The dispatcher is returned by value; for large capacities on a small stack prefer Self::load on a dispatcher in static memory.

§Errors

As for Self::load.

Source

pub fn load( &mut self, points: &[PointKind], edges: &[DispatchEdge], waits: &[Wait], ) -> Result<(), DispatchError>

Validates a dispatchable network and loads it in place, replacing any earlier network and execution state.

This is the onboard trust boundary: every index, bound and capacity is checked, and nothing is assumed about how the network was produced. Validation completes before the first write, so a rejected network leaves the dispatcher exactly as it was (still executing the previous plan, if any). Loading needs no stack memory proportional to N or E.

§Errors
Source

pub fn load_encoded(&mut self, bytes: &[u8]) -> Result<(), DecodeError>

Validates an encoded dispatchable network and loads it in place, without copying it anywhere first.

bytes must be exactly one encoding as written by encoding::encode_into (see encoding for the format). Header, length and CRC-32 are checked first, then every record, then the network as in Self::load. As there, a rejected encoding leaves the dispatcher exactly as it was. Never panics on any input.

§Examples
use temporal_control::dispatch::encoding;
use temporal_control::{DecodeError, DispatchEdge, Dispatcher, PointKind, Ticks, TimePoint};

let points = [PointKind::Executable; 2];
let edges = [DispatchEdge { from: TimePoint(0), to: TimePoint(1), weight: Ticks(10) }];
let mut buf = [0u8; 128];
let len = encoding::encode_into(&points, &edges, &[], &mut buf).expect("fits");

let mut d = Dispatcher::<4, 8>::EMPTY;
d.load_encoded(&buf[..len]).expect("valid");
assert_eq!(d.window(TimePoint(1)), Some((None, None)));

buf[30] ^= 0x10;
assert_eq!(d.load_encoded(&buf[..len]), Err(DecodeError::ChecksumMismatch));
§Errors

Any DecodeError; DecodeError::Network wraps the errors of Self::load.

Source

pub fn observe( &mut self, tp: TimePoint, now: Ticks, ) -> Result<(), DispatchError>

Records that contingent point tp was observed at now.

The observation is recorded and propagated even when it violates an assumption, so that monitoring continues; the violation is then reported as an error.

§Errors
Source

pub fn can_execute(&self, tp: TimePoint, now: Ticks) -> bool

Whether executable point tp may execute at now.

Source

pub fn execute( &mut self, tp: TimePoint, now: Ticks, ) -> Result<(), DispatchError>

Executes tp at now and propagates to its neighbors.

§Errors
Source

pub fn check_deadlines(&mut self, now: Ticks) -> Result<(), DispatchError>

Advances the clock to now and reports deadlines that have passed.

§Errors
Source

pub fn step( &mut self, now: Ticks, observed: &[TimePoint], out: &mut [TimePoint], ) -> Result<usize, DispatchError>

Runs one tick with the as-soon-as-possible policy.

Order: record every point in observed at now, check deadlines, then execute every point that may execute at now, repeating until none is left. Executed points are written to out; the return value is their number.

§Errors

Any error of Self::observe or Self::check_deadlines, which stops the tick, and DispatchError::OutputFull if out cannot hold the next executed point (that point is not executed). A buffer of N entries never fills up.

Source

pub fn next_wakeup(&self) -> Option<Ticks>

Earliest time at or after the latest call at which some executable point could execute without new observations, or None if none can.

An executive may sleep until then unless an observation arrives first.

Source

pub fn time(&self, tp: TimePoint) -> Option<Ticks>

Time at which tp happened, or None if it has not (or is unknown).

Source

pub fn window(&self, tp: TimePoint) -> Option<(Option<Ticks>, Option<Ticks>)>

Current window (lb, ub) of tp; None bounds are infinite. None for unknown handles.

Source

pub fn is_complete(&self) -> bool

Whether every time point has happened.

Trait Implementations§

Source§

impl<const N: usize, const E: usize, I: Clone + Index> Clone for Dispatcher<N, E, I>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<const N: usize, const E: usize, I: Debug + Index> Debug for Dispatcher<N, E, I>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<const N: usize, const E: usize, I> Forget for Dispatcher<N, E, I>

§

impl<const N: usize, const E: usize, I> Freeze for Dispatcher<N, E, I>
where [Kind<I>; N]: Freeze, [Option<Ticks>; N]: Freeze, [I; N]: Freeze, [Entry<I>; E]: Freeze,

§

impl<const N: usize, const E: usize, I> Move for Dispatcher<N, E, I>

§

impl<const N: usize, const E: usize, I> RefUnwindSafe for Dispatcher<N, E, I>
where [Kind<I>; N]: RefUnwindSafe, [Option<Ticks>; N]: RefUnwindSafe, [I; N]: RefUnwindSafe, [Entry<I>; E]: RefUnwindSafe,

§

impl<const N: usize, const E: usize, I> Send for Dispatcher<N, E, I>
where [Kind<I>; N]: Send, [Option<Ticks>; N]: Send, [I; N]: Send, [Entry<I>; E]: Send,

§

impl<const N: usize, const E: usize, I> Sync for Dispatcher<N, E, I>
where [Kind<I>; N]: Sync, [Option<Ticks>; N]: Sync, [I; N]: Sync, [Entry<I>; E]: Sync,

§

impl<const N: usize, const E: usize, I> Unpin for Dispatcher<N, E, I>
where [Kind<I>; N]: Unpin, [Option<Ticks>; N]: Unpin, [I; N]: Unpin, [Entry<I>; E]: Unpin,

§

impl<const N: usize, const E: usize, I> UnsafeUnpin for Dispatcher<N, E, I>
where [Kind<I>; N]: UnsafeUnpin, [Option<Ticks>; N]: UnsafeUnpin, [I; N]: UnsafeUnpin, [Entry<I>; E]: UnsafeUnpin,

§

impl<const N: usize, const E: usize, I> UnwindSafe for Dispatcher<N, E, I>
where [Kind<I>; N]: UnwindSafe, [Option<Ticks>; N]: UnwindSafe, [I; N]: UnwindSafe, [Entry<I>; E]: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.