hyperclock/common.rs
1//! Contains common, primitive types and a prelude for easy importing.
2//!
3//! This module defines the basic ID types used to uniquely identify phases, listeners,
4//! tasks, and other components within the Hyperclock engine. Using distinct types
5//! improves type safety and code clarity.
6
7use serde::Deserialize;
8use slotmap::new_key_type;
9
10/// A prelude module for convenient importing of the most common Hyperclock types.
11///
12/// # Example
13/// ```
14/// use hyperclock::prelude::*;
15/// ```
16pub mod prelude {
17 pub use super::{ListenerId, PhaseId, TaskId};
18 pub use crate::config::HyperclockConfig;
19 pub use crate::engine::HyperclockEngine;
20}
21
22new_key_type! {
23 /// Uniquely and safely identifies a registered listener within the engine.
24 ///
25 /// This key is returned when a new listener (e.g., for an interval or a gong)
26 /// is added to the engine. It is guaranteed to be unique and will not be reused,
27 /// preventing stale ID bugs.
28 pub struct ListenerId;
29
30 /// Uniquely and safely identifies a stateful, complex task like a `LifecycleLoop`.
31 pub struct TaskId;
32}
33
34/// Uniquely identifies a phase within the engine's cycle.
35///
36/// A `PhaseId` is a lightweight identifier, typically a small integer, that
37/// corresponds to a step in the configured phase sequence.
38#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Deserialize)]
39#[serde(transparent)]
40pub struct PhaseId(pub u8);