Skip to main content

Crate moirai

Crate moirai 

Source
Expand description

Moirai is a single-threaded, no_std + alloc entity-component-system library.

The public surface is a set of concept-level namespaces, curated root re-exports, and a smaller system-authoring prelude. Implementation modules such as allocators, registries, storage engines, command queues, and schedule runners stay private.

§Crate root and prelude admission

Common application, world, schedule, query, bundle, state, and time vocabulary is available at the crate root. prelude contains the subset normally needed to author systems. Advanced construction helpers such as world::BundleWriter stay in their semantic namespace.

§Learn by example

examples is the canonical ordered learning path. Its stable, runnable doctests progress from a first app through scheduling, queries, and deterministic replay.

§Privacy boundary

Internal modules are not reachable from downstream crates:

use moirai::entity::allocator;
use moirai::storage;
use moirai::component::registry;

Re-exports§

pub use component::ComponentId;
pub use component::ComponentOptions;
pub use component::StorageKind;
pub use event::ComponentAdded;
pub use event::ComponentRemoved;
pub use event::EventId;
pub use event::EventOptions;
pub use event::EventReader;
pub use event::EventReaderStart;
pub use event::EventRegistrationError;
pub use event::EventRetention;
pub use math::Q16;
pub use query::ExactIdPolicy;
pub use query::PreparedQuery1;
pub use query::PreparedQuery2;
pub use query::Query1;
pub use query::Query2;
pub use query::QueryCommands;
pub use query::QueryCursor;
pub use query::QueryEffects;
pub use query::QueryError;
pub use query::QueryPolicy;
pub use query::QuerySpec;
pub use query::QueryWindow;
pub use schedule::stage;
pub use schedule::Condition;
pub use schedule::ConditionError;
pub use schedule::FlushMode;
pub use schedule::Schedule;
pub use schedule::ScheduleBuilder;
pub use schedule::ScheduleError;
pub use schedule::StageId;
pub use schedule::System;
pub use schedule::SystemId;
pub use schedule::SystemInitContext;
pub use schedule::SystemSet;
pub use schedule::UpdatePlan;
pub use state::apply;
pub use state::on_enter;
pub use state::on_exit;
pub use state::on_transition;
pub use state::State;
pub use state::StateError;
pub use world::Bundle;
pub use world::Commands;
pub use world::DenseEntityScratch;
pub use world::DynamicBundle;
pub use world::EntityScratchError;
pub use world::World;
pub use world::WorldBuilder;
pub use world::WorldError;

Modules§

component
Component registration, storage policy, and dense registry-local handles.
diagnostics
Platform-neutral diagnostic observer contracts for crate::App execution.
event
Typed event registration, retention policy, and independent readers.
examples
Progressive, runnable lessons for learning Moirai through its public API.
math
Deterministic fixed-point helpers for host-side simulation math.
prelude
System-authoring essentials for Moirai hosts.
query
Query selection, traversal, caching, and safe mutation.
schedule
Deterministic ECS schedule: stages, systems, conditions, and deferred flush policy.
state
Explicit host state machine backed by a crate::world::World resource.
testkit
Deterministic replay, step records, drivers, and report comparison for host tests.
world
ECS World: entities, components, resources, events, and deferred Commands.

Structs§

App
Runnable ECS host pairing one World with one compiled Schedule.
AppBuilder
Checked application construction: world seeding, schedule authoring, observer wiring.
AppFault
Terminal execution record retained after the first fault.
ChangeTick
Monotonic world change counter for component/resource mutation metadata.
EntityId
Opaque entity handle relative to one crate::world::World.
FixedConfig
Host-provided fixed timestep: interval, substep cap, and debt policy.
FixedDebtCoalesced
Whole fixed intervals represented by one coalesced FixedUpdate run. Whole fixed intervals combined into one coalesced FixedUpdate run.
FixedDebtDropped
Whole fixed intervals discarded when debt exceeds the substep cap.
FixedStep
Fixed simulation substep identity while FixedUpdate runs.
Revision
A checked monotonic revision counter.
RevisionExhausted
Returned when a Revision cannot advance without overflowing.
RevisionKey
A fixed-width collection of revisions suitable for cache keys.
WorldTick
Monotonic frame counter advanced once per successful Update pass.

Enums§

AppError
Recoverable preflight failures and terminal execution faults for App.
BuildError
Schedule construction failure before first execution.
FixedDebtPolicy
Policy used when a frame contains more whole fixed intervals than FixedConfig::max_substeps.
StageOperation
Which crate::App operation owns a stage, frame channel, or structural command surface.