evorule_tcb/lib.rs
1// SPDX-License-Identifier: AGPL-3.0-or-later
2// Copyright (C) 2026 EvoRule Project
3// This file is part of EvoRule, licensed under GNU Affero General Public License v3 or later.
4//! `EvoRule` TCB Core - 纯计算内核
5//!
6//! # 设计原则
7//! - 零依赖(`#![no_std]` 兼容)
8//! - 纯函数(所有函数无副作用)
9//! - 确定性强(`BTreeMap` + 确定性迭代)
10//! - 永不 panic(路径解析返回 `Option`)
11//!
12//! # 公开接口
13//! - `execute_transition()`:执行一步状态转换
14//! - `JsonValue`:JSON 数据模型
15//! - `TcbError`:错误类型
16//!
17//! # 快速入门
18//!
19//! ```
20//! extern crate alloc;
21//! use evorule_tcb::JsonValue;
22//! use alloc::collections::BTreeMap;
23//!
24//! // 构造一个 JsonValue 对象
25//! let mut map = BTreeMap::new();
26//! map.insert("name".to_string(), JsonValue::string("Alice"));
27//! map.insert("age".to_string(), JsonValue::Integer(30));
28//! let value = JsonValue::object(map);
29//!
30//! // 类型检查与取值
31//! assert!(value.is_object());
32//! let age = value.get("age").and_then(|v| v.as_i64());
33//! assert_eq!(age, Some(30));
34//! ```
35
36#![no_std]
37#![forbid(unsafe_code)]
38#![deny(missing_docs)]
39// 永不 panic 保障:禁止以下 panic-prone 模式
40#![deny(clippy::unwrap_used)]
41#![deny(clippy::expect_used)]
42#![deny(clippy::indexing_slicing)]
43#![deny(clippy::panic)]
44
45extern crate alloc;
46
47// 模块声明(按依赖顺序:基础类型在前)
48pub mod discipline;
49pub mod domain;
50pub mod error;
51pub mod executor;
52pub mod path;
53pub mod transition;
54pub mod value;
55
56// 核心类型重导出(仅公开稳定的 API)
57pub use error::TcbError;
58pub use executor::META_INSTRUCTION_TYPES;
59pub use transition::{execute_transition, RuleHit, TransitionResult, MAX_TRANSFORM_RULES};
60pub use value::{JsonValue, ObjectMap};