From 02d7323a8b9140bbbe930d9da26c9cc5200e2f4c Mon Sep 17 00:00:00 2001 From: dailz Date: Sun, 12 Apr 2026 20:49:27 +0800 Subject: [PATCH] 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 --- Cargo.lock | 1 + Cargo.toml | 1 + crates/core/Cargo.toml | 1 + crates/core/src/error.rs | 18 ++++++++++++++++++ 4 files changed, 21 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 08d7e2e..209df0e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2300,6 +2300,7 @@ dependencies = [ "directories", "insta", "memchr", + "memmap2", "notify", "parking_lot", "regex", diff --git a/Cargo.toml b/Cargo.toml index 418a26f..082d4ca 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,6 +12,7 @@ crossbeam-channel = "0.5" notify = "8" regex = "1" memchr = "2" +memmap2 = "0.9" toml = "0.8" directories = "6" insta = "1" diff --git a/crates/core/Cargo.toml b/crates/core/Cargo.toml index 0dbb891..0dcf99c 100644 --- a/crates/core/Cargo.toml +++ b/crates/core/Cargo.toml @@ -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] diff --git a/crates/core/src/error.rs b/crates/core/src/error.rs index 249901a..151d714 100644 --- a/crates/core/src/error.rs +++ b/crates/core/src/error.rs @@ -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() {