Struct RoutingFrame

Source
pub struct RoutingFrame {
    pub here: Vec<usize>,
    pub selection: Selection,
    pub slice: Arc<Slice>,
    pub dim: usize,
}
Expand description

RoutingFrame captures the state of a selection being evaluated: the current coordinate (here), the remaining selection to apply, the shape and layout information (slice), and the current dimension (dim).

Each frame represents an independent routing decision and produces zero or more new frames via next_steps.

Fields§

§here: Vec<usize>

The current coordinate in the mesh where this frame is being evaluated.

This is the source location for the next routing step.

§selection: Selection

The residual selection expression describing where routing should continue.

At each step, only the current dimension (tracked by dim) of this selection is considered.

§slice: Arc<Slice>

The shape and layout of the full multidimensional space being routed.

This determines the bounds and stride information used to compute coordinates and flat indices.

§dim: usize

The current axis of traversal within the selection and slice.

Routing proceeds dimension-by-dimension; this value tracks how many dimensions have already been routed.

Implementations§

Source§

impl RoutingFrame

Source

pub fn root(selection: Selection, slice: Slice) -> Self

Constructs the initial frame at the root coordinate (all zeros). Selections are expanded as necessary to ensure they have depth equal to the slice dimensionality. See the docs for canonicalize_to_dimensions for the rules.

§Canonical Handling of Zero-Dimensional Slices

A Slice with zero dimensions represents the empty product ∏_{i=1}^{0} Xᵢ, which has exactly one element: the empty tuple. To maintain uniform routing semantics, we canonically embed such 0D slices as 1D slices of extent 1:

Slice::new(offset, [1], [1])

This embedding preserves the correct number of addressable points and allows the routing machinery to proceed through the usual recursive strategy without introducing special cases. The selected coordinate is vec![0], and dim = 0 proceeds as usual. This makes the routing logic consistent with evaluation and avoids edge case handling throughout the codebase.

Source

pub fn advance(&self, here: Vec<usize>, selection: Selection) -> Self

Produces a new frame advanced to the next dimension with updated position and selection.

Source

pub fn with_selection(&self, selection: Selection) -> Self

Returns a new frame with the same position and dimension but a different selection.

Source

pub fn action(&self) -> RoutingAction

Determines the appropriate routing action for this frame.

Returns RoutingAction::Deliver if the message should be delivered at this coordinate, or RoutingAction::Forward if it should be routed further.

Source

pub fn location(&self) -> Result<usize, SliceError>

Returns the location of this frame in the underlying slice.

Source§

impl RoutingFrame

Source

pub fn next_steps( &self, _chooser: &mut dyn FnMut(&Choice) -> usize, f: &mut dyn FnMut(RoutingStep) -> ControlFlow<()>, ) -> ControlFlow<()>

Visits the next routing steps from this frame using a callback-based traversal. This method structurally recurses on the Selection expression, yielding RoutingSteps via the f callback. Early termination is supported via ControlFlow::Break.

Compared to the (old, now removed) [next_steps] method, this avoids intermediate allocation, supports interruptibility, and allows policy-driven handling of RoutingStep::Choices via the chooser callback.


§Traversal Strategy

The traversal proceeds dimension-by-dimension, structurally mirroring the shape of the selection expression:

At each step, only the current dimension (tracked via self.dim) is evaluated. Future dimensions remain untouched until deeper recursion.


§Evaluation Semantics
  • Selection::True No further routing is performed — if this frame is at the final dimension, delivery occurs.

  • Selection::False No match — routing halts.

  • Selection::All / Selection::Range Emits one RoutingStep::Forward per matching index, each advancing to the next dimension with the inner selection.

  • Selection::Union Evaluates both branches independently and emits all resulting steps.

  • Selection::Intersection Emits only those steps where both branches produce the same coordinate, combining the residual selections at that point.

  • Selection::Any Randomly selects one index and emits a single RoutingStep::Forward.

  • Selection::Choice Defers decision to the caller by invoking the chooser function, which resolves the candidate index.


§Delivery Semantics

Message delivery is determined by RoutingFrame::deliver_here, which returns true when:

  • The frame’s selection is Selection::True, and
  • All dimensions have been traversed (dim == slice.num_dim()).

§Panics

Panics if slice.num_dim() == 0. Use a canonical embedding (e.g., 0D → 1D) before calling this (see e.g. RoutingFrame::root).


§Summary
  • Structure-driven: Mirrors the shape of the selection expression.
  • Compositional: Each variant defines its own traversal behavior.
  • Interruptible: Early termination is supported via ControlFlow.
  • Minimally allocating: Avoids intermediate buffers in most cases; only Selection::Intersection allocates temporary state for pairwise matching.
  • Policy-ready: Integrates with runtime routing policies via the chooser.
Source

pub fn deliver_here(&self) -> bool

Returns true if this frame represents a terminal delivery point — i.e., the selection is True and all dimensions have been traversed.

Source

pub fn should_route(&self) -> bool

Returns true if the message has not yet reached its final destination and should be forwarded to the next routing step.

Source§

impl RoutingFrame

Source

pub fn trace_route(&self, dest: &[usize]) -> Option<Vec<Vec<usize>>>

Traces the unique routing path to the given destination coordinate.

Returns Some(vec![root, ..., dest]) if dest is selected, or None if not.

Trait Implementations§

Source§

impl Clone for RoutingFrame

Source§

fn clone(&self) -> RoutingFrame

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for RoutingFrame

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for RoutingFrame

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for RoutingFrame

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,