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:
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -2300,6 +2300,7 @@ dependencies = [
|
||||
"directories",
|
||||
"insta",
|
||||
"memchr",
|
||||
"memmap2",
|
||||
"notify",
|
||||
"parking_lot",
|
||||
"regex",
|
||||
|
||||
@@ -12,6 +12,7 @@ crossbeam-channel = "0.5"
|
||||
notify = "8"
|
||||
regex = "1"
|
||||
memchr = "2"
|
||||
memmap2 = "0.9"
|
||||
toml = "0.8"
|
||||
directories = "6"
|
||||
insta = "1"
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user