jugar_core/
lib.rs

1//! # jugar-core
2//!
3//! Core ECS (Entity-Component-System), Game Loop, and State Management for Jugar.
4//!
5//! This crate provides the foundational data structures and systems for the Jugar
6//! game engine. It follows Toyota Way principles:
7//!
8//! - **Poka-Yoke**: Type-safe entity/component relationships prevent invalid states
9//! - **Heijunka**: Fixed timestep game loop ensures physics consistency
10//! - **Mieruka**: Debug-friendly types with comprehensive Display/Debug impls
11
12#![forbid(unsafe_code)]
13#![warn(missing_docs)]
14#![warn(clippy::pedantic)]
15#![allow(clippy::module_name_repetitions)]
16
17use thiserror::Error;
18
19pub mod components;
20pub mod ecs;
21pub mod game_loop;
22
23pub use components::*;
24pub use ecs::*;
25pub use game_loop::*;
26
27/// Errors that can occur in jugar-core
28#[derive(Error, Debug, Clone, PartialEq, Eq)]
29pub enum CoreError {
30    /// Entity not found in the world
31    #[error("Entity {0:?} not found")]
32    EntityNotFound(Entity),
33
34    /// Component not found on entity
35    #[error("Component not found on entity {0:?}")]
36    ComponentNotFound(Entity),
37
38    /// Invalid game state transition
39    #[error("Invalid state transition from {from} to {to}")]
40    InvalidStateTransition {
41        /// Current state
42        from: String,
43        /// Attempted target state
44        to: String,
45    },
46}
47
48/// Result type for jugar-core operations
49pub type Result<T> = core::result::Result<T, CoreError>;
50
51#[cfg(test)]
52#[allow(clippy::unwrap_used, clippy::expect_used)]
53mod tests {
54    use super::*;
55
56    #[test]
57    fn test_error_display() {
58        let err = CoreError::EntityNotFound(Entity(42));
59        assert!(err.to_string().contains("42"));
60    }
61}