docs: 添加 Rustdoc 注释

This commit is contained in:
2026-08-05 21:46:47 +08:00
parent 7c8f19f61a
commit 263fd255b6
158 changed files with 1440 additions and 15 deletions
+24
View File
@@ -1,16 +1,35 @@
//! 子系统标识与日志级别解析。
//!
//! 引擎日志按子系统划分(VM / IC / Kernel / Builtins),各子系统可独立设置
//! 级别。`parse_level` 把字符串解析为 [`Level`];`apply_env_levels` 读取
//! `OXIDE_LOG` 环境变量并按 `oxide=<level>` 形式的指令批量覆盖级别。
use crate::level::Level;
/// 引擎子系统标识。
///
/// `repr(usize)` 的值同时用作 [`SubsystemFilter`](crate::SubsystemFilter)
/// 内部原子级别数组的下标,故枚举顺序不可随意调整。
#[repr(usize)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SubsystemId {
/// 虚拟机执行循环(字节码解释器)。
Vm = 0,
/// 内联缓存(inline cache)相关路径。
Ic = 1,
/// 内核:对象模型、GC、运行时服务。
Kernel = 2,
/// 内置对象与内置函数实现。
Builtins = 3,
}
/// 子系统总数,即 [`SubsystemId`] 变体个数,也是 `SubsystemFilter` 级别数组长度。
pub const SUBSYSTEM_COUNT: usize = 4;
/// 把级别字符串解析为 [`Level`],大小写不敏感。
///
/// 接受 `off` / `error` / `warn` / `info` / `debug` / `trace`,未知字符串返回
/// `None`。
pub fn parse_level(s: &str) -> Option<Level> {
if s.eq_ignore_ascii_case("off") {
Some(Level::Off)
@@ -29,6 +48,11 @@ pub fn parse_level(s: &str) -> Option<Level> {
}
}
/// 从环境变量 `OXIDE_LOG` 应用启动时级别覆盖。
///
/// 指令格式为逗号分隔的 `target=level` 列表,如 `oxide::vm=debug,oxide::ic=info`;
/// `oxide=<level>` 为所有子系统的快捷写法。无效指令被静默跳过,
/// 若环境变量缺失则直接返回。
pub fn apply_env_levels() {
let Ok(spec) = std::env::var("OXIDE_LOG") else {
return;