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.
Relationtype 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
!Sendand!Synccomponents.!Sendcomponents cannot be fetched mutably from outside “main” thread.!Synccomponents cannot be fetched immutably from outside “main” thread.Worldhas to be!Sendbut implementsSync. -
ActionEncoderallows recording actions and later run them onWorld. Actions get mutable access toWorld. -
Component replace/drop hooks. Components can define hooks that will be executed on value drop and replace. Hooks can read old and new values,
EntityIdand can record actions intoActionEncoder. -
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
!Sizedtypes. There’s macro to define dyn trait borrows. Special kind of queries look into possible borrows to fetch. -
WorldBuildercan be used to manually register component types and override default behavior. -
Optional
Componenttrait to allow implicit component type registration by insertion methods. Implicit registration uses behavior defined byComponentimplementation as-is. Separate insertions methods withComponenttrait 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 withWorldBuilderand implicit registration via insertion method withComponenttype bound is enough. -
Systemtrait andIntoSystemimplemented for functions if argument types implementFnArg. This way practically any system can be defined as a function. -
Schedulerthat can runSystems in parallel using provided executor.
Re-exports§
pub use crate::action::ActionBuffer;pub use crate::action::ActionBufferSliceExt;pub use crate::action::ActionEncoder;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::Entity;pub use crate::entity::EntityBound;pub use crate::entity::EntityId;pub use crate::entity::EntityLoc;pub use crate::entity::EntityRef;pub use crate::query::Alt;pub use crate::query::Entities;pub use crate::query::Modified;pub use crate::query::Query;pub use crate::query::With;pub use crate::query::Without;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::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::view::View;pub use crate::view::ViewCell;pub use crate::view::ViewIter;pub use crate::view::ViewOne;pub use crate::world::World;pub use crate::world::WorldBuilder;pub use crate::EntityError;pub use crate::NoSuchEntity;pub use crate::scheduler::Scheduler;pub use atomicell;
Modules§
- action
- This module contains definitions for action recording.
Actions can be recorded into
ActionEncoderand executed later onto theWorld. Two primary use cases for actions are: - archetype
- This module contains
Archetypetype definition. - bundle
- This module defines
Bundle,ComponentBundle,DynamicBundleandDynamicComponentBundletraits. - component
- This module defines
Componenttrait and related types. - dump
- Provides world serialization integration with serialization crates.
- entity
- Entity references.
- epoch
- This module contains
EpochCounterandEpochIdtypes used for change detection. - executor
- Provides API to define task executors.
- flow
- Flow module provides API to create high-level async workflows on top of the Edict ECS.
- prelude
- A prelude module. Reexports types and traits, enough to start using
edict - query
- Queries are used to fetch data from the
World. - relation
Relationis a concept that is similar toComponent. The main difference is that they are not components, but rather relations.- scheduler
- Built-in scheduling for systems.
- system
- Provides API to define systems compatible with built-in scheduler.
- tls
- Provides a thread-local storage for the current world pointer.
- view
- A view over
Worldthat may be used to access specific components. - world
- Self-contained ECS
World.
Macros§
- flow_
closure - Converts closure syntax to flow fn.
- flow_
closure_ for - Converts closure syntax to flow fn.
- spawn_
block - Spawns code block as a flow.
- trait_
borrow - Extends output with
ComponentBorrowto borrow dyn trait object.dyn Trait + Send + Syncand all valid combinations are automatically added. - type_
borrow - Extends output with
ComponentBorrowto borrow borrowed type. Mutably if possible. - yield_
now
Structs§
- Mismatch
- Error that may be returned when an entity does not have required components.
- NoSuch
Entity - Error that may be returned when an entity is not found in the world.
Enums§
- Access
- Specifies kind of access query performs for particular component.
- Entity
Error - Error that may be returned when fetching query from entity that may be despawned.
Attribute Macros§
- system
- This attribute adds checks for system functions. Only applicable to function items.