Struct SystemOrder
pub struct SystemOrder { /* private fields */ }Implementations§
§impl SystemOrder
impl SystemOrder
pub fn add(&mut self, name: &str) -> Result<(), OrderError>
pub fn add_checked(&mut self, name: &str) -> Result<(), OrderDiagnostic>
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>
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>
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>
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>
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>
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>
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>
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"] },
]);