Expand description

Edict

Edict is a fast and powerful ECS crate that expands traditional ECS feature set. Written in Rust by your fellow 🦀

Features

  • General purpose archetype based ECS with fast iteration.

  • Relations can be added to pair of entities, binding them together. When either of the two entities is despawned, relation is dropped. Relation type may further configure behavior of the bonds.

  • Change tracking. Each component instance is equipped with epoch counter that tracks last potential mutation of the component. Special query type uses epoch counter to skip entities where component wasn’t changed since specified epoch. Last epoch can be obtained with World::epoch.

  • Built-in type-map for singleton values called “resources”. Resources can be inserted into/fetched from World. Resources live separately from entities and their components.

  • Runtime checks for query validity and mutable aliasing avoidance. This requires atomic operations at the beginning iteration on next archetype.

  • Support for !Send and !Sync components. !Send components cannot be fetched mutably from outside “main” thread. !Sync components cannot be fetched immutably from outside “main” thread. World has to be !Send but implements Sync.

  • ActionEncoder allows recording actions and later run them on World. Actions get mutable access to World.

  • Component replace/drop hooks. Components can define hooks that will be executed on value drop and replace. Hooks can read old and new values, EntityId and can record actions into ActionEncoder.

  • Component type may define a set of types that can be borrowed from it. Borrowed type may be not sized, allowing slices, dyn traits and any other !Sized types. There’s macro to define dyn trait borrows. Special kind of queries look into possible borrows to fetch.

  • WorldBuilder can be used to manually register component types and override default behavior.

  • Optional Component trait to allow implicit component type registration by insertion methods. Implicit registration uses behavior defined by Component implementation as-is. Separate insertions methods with Component trait bound lifted can be used where trait is not implemented or implementation is not visible for generic type. Those methods require pre-registration of the component type. If type was not registered - method panics. Both explicit registration with WorldBuilder and implicit registration via insertion method with Component type bound is enough.

  • System trait and IntoSystem implemented for functions if argument types implement FnArg. This way practically any system can be defined as a function.

  • Scheduler that can run Systems in parallel using provided executor.

Re-exports

pub use atomicell;
pub use crate::action::ActionEncoder;
pub use crate::action::ActionEncoderSliceExt;
pub use crate::bundle::Bundle;
pub use crate::bundle::ComponentBundle;
pub use crate::bundle::DynamicBundle;
pub use crate::bundle::DynamicComponentBundle;
pub use crate::bundle::EntityBuilder;
pub use crate::component::Component;
pub use crate::component::Component;
pub use crate::entity::EntityId;
pub use crate::query::Alt;
pub use crate::query::Entities;
pub use crate::query::Modified;
pub use crate::query::PhantomQuery;
pub use crate::query::Query;
pub use crate::query::QueryIter;
pub use crate::relation::ChildOf;
pub use crate::relation::Related;
pub use crate::relation::Relates;
pub use crate::relation::RelatesExclusive;
pub use crate::relation::RelatesTo;
pub use crate::relation::Relation;
pub use crate::relation::Relation;
pub use crate::scheduler::Scheduler;
pub use crate::system::IntoSystem;
pub use crate::system::Res;
pub use crate::system::ResMut;
pub use crate::system::ResMutNoSend;
pub use crate::system::ResNoSync;
pub use crate::system::State;
pub use crate::system::System;
pub use crate::world::EntityError;
pub use crate::world::MissingComponents;
pub use crate::world::NoSuchEntity;
pub use crate::world::QueryOneError;
pub use crate::world::QueryRef;
pub use crate::world::World;

Modules

This module contains definitions for action recording. Actions can be recorded into ActionEncoder and executed later onto the World. Two primary use cases for actions are:

This module contains Archetype type definition.

This module defines Component trait and related types.

Entity references.

This module contains EpochCounter and EpochId types used for change detection.

Provides API to define task executors.

A prelude module. Reexports types and traits, enough to start using edict

Queries and iterators.

Relation is a concept that is similar to Component. The main difference is that they are not components, but rather relations.

Built-in scheduling for systems.

Provides API to define systems compatible with built-in scheduler.

Self-contained ECS World.

Macros

Constructs ComponentBorrow to borrow dyn trait object.

Extends output with ComponentBorrow to borrow dyn trait object. dyn Trait + Send + Sync and all valid combinations are automatically added.