Skip to main content

anvilkit_core/
lib.rs

1//! # AnvilKit Core
2//! 
3//! AnvilKit 游戏引擎的核心基础设施库。
4//! 
5//! 本 crate 提供了 AnvilKit 生态系统中使用的基础构建块:
6//! - **数学系统**: 变换、几何图形、插值和数学常量
7//! - **时间管理**: 帧时间跟踪、计时器和时间工具
8//! - **错误处理**: 统一的错误类型和结果处理
9//! 
10//! ## 快速开始
11//! 
12//! ```rust
13//! use anvilkit_core::prelude::*;
14//! 
15//! // 创建一个 3D 变换
16//! let transform = Transform::from_xyz(1.0, 2.0, 3.0)
17//!     .with_rotation(Quat::from_rotation_y(std::f32::consts::PI / 4.0))
18//!     .with_scale(Vec3::splat(2.0));
19//! 
20//! // 创建时间管理器
21//! let mut time = Time::new();
22//! time.update();
23//! 
24//! println!("Delta time: {:.3}s", time.delta_seconds());
25//! ```
26//! 
27//! ## 特性标志
28//! 
29//! - `serde`: 启用序列化支持
30//! - `debug`: 启用调试功能和额外的验证
31
32#![warn(missing_docs)]
33
34pub mod math;
35pub mod time;
36pub mod error;
37
38/// 预导入模块,包含最常用的类型和函数
39pub mod prelude {
40    // 数学类型
41    pub use crate::math::{Transform, GlobalTransform};
42    pub use crate::math::geometry::{Rect, Circle, Bounds2D, Bounds3D};
43    pub use crate::math::interpolation::{Lerp, Slerp, Interpolate};
44    
45    // 时间类型
46    pub use crate::time::{Time, Timer};
47    
48    // 错误类型
49    pub use crate::error::{AnvilKitError, Result};
50    
51    // 重新导出 glam 的常用类型
52    pub use glam::{
53        Vec2, Vec3, Vec4,
54        Mat3, Mat4,
55        Quat,
56        UVec2, UVec3, UVec4,
57        IVec2, IVec3, IVec4,
58    };
59
60    // 数学常量
61    pub use std::f32::consts as math_consts;
62}
63
64// 重新导出核心模块
65pub use math::*;
66pub use time::*;
67pub use error::*;
68
69// 重新导出常用的 glam 类型
70pub use glam::{
71    Vec2, Vec3, Vec4,
72    Mat3, Mat4,
73    Quat,
74    UVec2, UVec3, UVec4,
75    IVec2, IVec3, IVec4,
76};
77
78/// AnvilKit Core 的版本信息
79pub const VERSION: &str = env!("CARGO_PKG_VERSION");
80
81/// AnvilKit Core 的构建信息
82pub const BUILD_INFO: &str = concat!(
83    "AnvilKit Core v",
84    env!("CARGO_PKG_VERSION"),
85);
86
87#[cfg(test)]
88mod tests {
89    use super::*;
90
91    #[test]
92    fn test_version_info() {
93        assert!(!VERSION.is_empty());
94        assert!(BUILD_INFO.contains(VERSION));
95    }
96
97    #[test]
98    fn test_prelude_imports() {
99        use crate::prelude::*;
100        
101        // 测试可以使用预导入的类型
102        let _transform = Transform::IDENTITY;
103        let _time = Time::new();
104        let _rect = Rect::new(Vec2::ZERO, Vec2::ONE);
105    }
106}