Struct SystemOrder

pub struct SystemOrder { /* private fields */ }

Implementations§

§

impl SystemOrder

pub fn add(&mut self, name: &str) -> Result<(), OrderError>

pub fn add_checked(&mut self, name: &str) -> Result<(), OrderDiagnostic>

Register a system, returning its name and a remedy on failure. Validation and failure atomicity are identical to Self::add.

use ferravex_engine::system_order::{OrderDiagnostic, SystemOrder};
let mut order = SystemOrder::default();
order.add_checked("input")?;
assert_eq!(order.add_checked("input"), Err(OrderDiagnostic::Duplicate {
    name: "input".into(),
}));

pub fn before(&mut self, first: &str, second: &str) -> Result<(), OrderError>

Declare first before second. Both names must already be registered. Cycles are accepted here and reported by Self::resolve. To reject them without changing the graph, use Self::before_checked.

pub fn before_checked( &mut self, first: &str, second: &str, ) -> Result<(), OrderDiagnostic>

Declare first before second only if the resulting graph is acyclic. Reports every missing endpoint, or a named cycle path. On any error the graph is unchanged, including existing copies of the requested edge. Repeating an edge succeeds if the graph is acyclic. A pre-existing cycle created with Self::before is also an error, even for a repeated edge.

use ferravex_engine::system_order::{OrderDiagnostic, SystemOrder};
let mut order = SystemOrder::default();
order.add_checked("input")?;
order.add_checked("render")?;
order.before_checked("input", "render")?;
let error = order.before_checked("render", "input").unwrap_err();
assert_eq!(error, OrderDiagnostic::Cycle {
    path: vec!["input".into(), "render".into(), "input".into()],
});
assert_eq!(order.resolve_checked()?, ["input", "render"]);

pub fn resolve(&self) -> Result<Vec<&str>, OrderError>

Resolve execution order, breaking ties by earliest registration among all currently ready systems. Disconnected systems participate in the same rule.

pub fn resolve_checked(&self) -> Result<Vec<&str>, OrderDiagnostic>

Resolve in the same order as Self::resolve, with a named cycle on error. Cycle discovery visits systems and outgoing dependencies in registration order, so the chosen path is independent of edge insertion order. When several cycles exist, the first found cycle is reported, not necessarily the shortest one. The graph is never changed.

use ferravex_engine::system_order::{OrderDiagnostic, SystemOrder};
let mut order = SystemOrder::default();
order.add_checked("audio")?;
order.before("audio", "audio").unwrap();
assert_eq!(order.resolve_checked(), Err(OrderDiagnostic::Cycle {
    path: vec!["audio".into(), "audio".into()],
}));

pub fn resolve_layers(&self) -> Result<Vec<Vec<&str>>, OrderDiagnostic>

Resolve dependency layers, ordered from prerequisites to dependents. Layer zero contains every system without prerequisites. Each other system appears exactly once, one layer after its deepest direct prerequisite. Systems within a layer use registration order, independent of the order in which dependencies were declared. An empty graph returns no layers.

Flattening these layers produces a valid topological order, but may differ from Self::resolve, which immediately considers newly ready systems. No systems execute here and shared resource access is not analyzed.

A cycle anywhere in the graph returns the same named diagnostic as Self::resolve_checked, without a partial result or graph mutation. Missing endpoints are rejected when declaring dependencies with Self::before_checked, so the stored graph cannot contain missing nodes. Allocates layer and working storage bounded by the 256 registered systems; returned names borrow from the graph.

use ferravex_engine::system_order::{OrderDiagnostic, SystemOrder};
let mut order = SystemOrder::default();
for name in ["render", "input", "physics", "audio"] {
    order.add_checked(name)?;
}
order.before_checked("input", "physics")?;
order.before_checked("physics", "render")?;
assert_eq!(order.resolve_layers()?, vec![
    vec!["input", "audio"], vec!["physics"], vec!["render"],
]);
assert_eq!(order.resolve_checked()?, ["input", "physics", "render", "audio"]);

pub fn inspect_layers( &self, ) -> Result<Vec<Vec<OrderedSystem<'_>>>, OrderDiagnostic>

Inspect dependency layers and each system’s direct prerequisites. Layers and their systems have exactly Self::resolve_layers’s ordering and cycle diagnostics. Each prerequisite list uses registration order, just as in Self::inspect; transitive dependencies are not repeated. No graph state is changed or cached, including on failure. Allocates storage bounded by the registered systems and declared edges, and borrows all names from the graph.

use ferravex_engine::system_order::{OrderDiagnostic, OrderedSystem, SystemOrder};
let mut order = SystemOrder::default();
for name in ["draw", "update", "input"] {
    order.add_checked(name)?;
}
order.before_checked("input", "update")?;
order.before_checked("update", "draw")?;
let layers = order.inspect_layers()?;
assert_eq!(layers[2], vec![OrderedSystem {
    name: "draw", prerequisites: vec!["update"],
}]);
assert_eq!(layers[1][0].prerequisites, ["input"]);

pub fn inspect(&self) -> Result<Vec<OrderedSystem<'_>>, OrderDiagnostic>

Inspect the resolved execution order and each system’s direct prerequisites. The returned list uses Self::resolve’s tie-break rule. Each prerequisite list uses registration order, irrespective of edge insertion order. Allocates the inspection result and borrows the registered names.

use ferravex_engine::system_order::{OrderDiagnostic, OrderedSystem, SystemOrder};
let mut order = SystemOrder::default();
order.add_checked("draw")?;
order.add_checked("update")?;
order.before_checked("update", "draw")?;
assert_eq!(order.inspect()?, vec![
    OrderedSystem { name: "update", prerequisites: vec![] },
    OrderedSystem { name: "draw", prerequisites: vec!["update"] },
]);

Trait Implementations§

§

impl Default for SystemOrder

§

fn default() -> SystemOrder

Returns the “default value” for a type. 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> 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, 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.