feat(core): add Mmap error variant and memmap2 dependency

Add CoreError::Mmap(String) error variant for mmap operations and memmap2 = "0.9" as workspace dependency.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
dailz
2026-04-12 20:49:27 +08:00
parent 2ac3eb99c7
commit 02d7323a8b
4 changed files with 21 additions and 0 deletions

1
Cargo.lock generated
View File

@@ -2300,6 +2300,7 @@ dependencies = [
"directories",
"insta",
"memchr",
"memmap2",
"notify",
"parking_lot",
"regex",

View File

@@ -12,6 +12,7 @@ crossbeam-channel = "0.5"
notify = "8"
regex = "1"
memchr = "2"
memmap2 = "0.9"
toml = "0.8"
directories = "6"
insta = "1"

View File

@@ -13,6 +13,7 @@ parking_lot.workspace = true
crossbeam-channel.workspace = true
regex.workspace = true
memchr.workspace = true
memmap2.workspace = true
directories.workspace = true
[dev-dependencies]

View File

@@ -119,6 +119,10 @@ pub enum CoreError {
// 这里 0 指的是 String 类型的值本身(因为这是"元组变体"风格,不是结构体风格)。
Watch(String),
// ─── Mmap 变体内存映射错误mmap 操作失败等)──────────────────────────────
#[error("mmap error: {0}")]
Mmap(String),
// ─── FileNotFound 变体:文件未找到 ──────────────────────────────────────
#[error("file not found: {path:?}")]
// {path:?} 使用 Debug 格式化输出路径,会保留引号,如 "file not found: "/path/to/file""
@@ -319,6 +323,20 @@ mod tests {
}
}
#[test]
fn test_mmap_error_display() {
let err = CoreError::Mmap("test mmap error".into());
let msg = err.to_string();
assert!(
msg.contains("mmap error"),
"display should contain 'mmap error'"
);
assert!(
msg.contains("test mmap error"),
"display should contain error message"
);
}
#[test]
// 测试Result 类型别名能正确使用 Ok 和 Err。
fn test_result_type_alias() {