9个版本 (重大更改)
0.7.0 | 2022年12月28日 |
---|---|
0.6.0 | 2022年1月12日 |
0.5.0 | 2019年2月13日 |
0.4.2 | 2017年9月7日 |
0.4.1 | 2016年11月25日 |
#736 在 解析器实现
7,366 每月下载量
用于 12 个crate(10个直接使用)
36KB
697 行
补丁
Rust crate,用于解析和生成统一格式的补丁文件。
解析器试图足够宽容以兼容由git等程序生成的diff。它通过忽略这些程序在diff中提供的附加代码上下文和信息来实现这一点。
请参阅 文档 获取更多信息及示例。
lib.rs
:
解析和生成统一格式的补丁文件(diff)。
格式尚未完全定义,但Guido van Rossum等人已经完成了这项工作来找出细节。
解析器试图足够宽容以兼容由git等程序生成的diff。它通过忽略这些程序在diff中提供的附加代码上下文和信息来实现这一点。
示例
// Make sure you add the `patch` crate to the `[dependencies]` key of your Cargo.toml file.
use patch::Patch;
let sample = "\
--- before.py
+++ path/to/after.py
@@ -1,4 +1,4 @@
-bacon
-eggs
-ham
+python
+eggy
+hamster
guido\n";
let patch = Patch::from_single(sample)?;
assert_eq!(&patch.old.path, "before.py");
assert_eq!(&patch.new.path, "path/to/after.py");
// Print out the parsed patch file in its Rust representation
println!("{:#?}", patch);
// Print out the parsed patch file in the Unified Format. For input that was originally in the
// Unified Format, this will produce output identical to that original input.
println!("{}", patch); // use format!("{}\n", patch) to get this as a String
依赖关系
~2.5MB
~40K SLoC