fix(patch): 占位函数返回未实现错误而非空结果

apply_patch / apply_json_patch 原返回 Ok(空 Vec/空 String),调用方会把未实现
的占位误当成一次成功的补丁应用。改为返回 PatchError::ApplyFailed,让占位状态
显式可见。新增单测确认返回错误。

对应 issue #18 维护清单 2-4。

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-16 08:00:31 -07:00
co-authored by Claude Fable 5
parent 962261ba12
commit 02d5bc537e
2 changed files with 36 additions and 4 deletions
+18 -2
View File
@@ -1,6 +1,22 @@
//! Binary Patch 模块占位
/// Binary Patch 应用(实现)
/// Binary Patch 应用(尚未实现)
///
/// 返回 [`crate::PatchError::ApplyFailed`] 而非空结果,避免调用方把未实现的
/// 占位当成一次成功的补丁应用。
pub fn apply_patch(_old: &[u8], _patch: &[u8]) -> crate::Result<Vec<u8>> {
Ok(Vec::new())
Err(crate::PatchError::ApplyFailed(
"binary patch 尚未实现".to_string(),
))
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn apply_patch_reports_not_implemented() {
let error = apply_patch(b"old", b"patch").unwrap_err();
assert!(matches!(error, crate::PatchError::ApplyFailed(_)));
}
}
+18 -2
View File
@@ -1,6 +1,22 @@
//! JSON Patch 模块占位
/// JSON Patch 应用(实现)
/// JSON Patch 应用(尚未实现)
///
/// 返回 [`crate::PatchError::ApplyFailed`] 而非空字符串,避免调用方把未实现的
/// 占位当成一次成功的补丁应用。
pub fn apply_json_patch(_doc: &str, _patch: &str) -> crate::Result<String> {
Ok(String::new())
Err(crate::PatchError::ApplyFailed(
"json patch 尚未实现".to_string(),
))
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn apply_json_patch_reports_not_implemented() {
let error = apply_json_patch("{}", "[]").unwrap_err();
assert!(matches!(error, crate::PatchError::ApplyFailed(_)));
}
}