|
@@ -21,6 +21,7 @@ pub struct OpMethods(pub Vec<OpMethod>);
|
|
|
|
|
|
|
|
#[derive(PartialEq, Eq, SerialEncodable, SerialDecodable, Serialize, Deserialize, Clone, Debug)]
|
|
#[derive(PartialEq, Eq, SerialEncodable, SerialDecodable, Serialize, Deserialize, Clone, Debug)]
|
|
|
pub struct Patch {
|
|
pub struct Patch {
|
|
|
|
|
+ title: String,
|
|
|
author: String,
|
|
author: String,
|
|
|
id: String,
|
|
id: String,
|
|
|
base: String,
|
|
base: String,
|
|
@@ -67,8 +68,9 @@ impl std::string::ToString for Patch {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
impl Patch {
|
|
impl Patch {
|
|
|
- pub fn new(id: &str, author: &str) -> Self {
|
|
|
|
|
|
|
+ pub fn new(title: &str, id: &str, author: &str) -> Self {
|
|
|
Self {
|
|
Self {
|
|
|
|
|
+ title: title.to_string(),
|
|
|
id: id.to_string(),
|
|
id: id.to_string(),
|
|
|
ops: OpMethods(vec![]),
|
|
ops: OpMethods(vec![]),
|
|
|
base: String::new(),
|
|
base: String::new(),
|
|
@@ -147,6 +149,10 @@ impl Patch {
|
|
|
self.id.clone()
|
|
self.id.clone()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ pub fn title(&self) -> String {
|
|
|
|
|
+ self.title.clone()
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
pub fn ops(&self) -> OpMethods {
|
|
pub fn ops(&self) -> OpMethods {
|
|
|
self.ops.clone()
|
|
self.ops.clone()
|
|
|
}
|
|
}
|
|
@@ -158,7 +164,7 @@ impl Patch {
|
|
|
//
|
|
//
|
|
|
// TODO need more work to get better performance with iterators
|
|
// TODO need more work to get better performance with iterators
|
|
|
pub fn transform(&self, other: &Self) -> Self {
|
|
pub fn transform(&self, other: &Self) -> Self {
|
|
|
- let mut new_patch = Self::new(&self.id, &self.author);
|
|
|
|
|
|
|
+ let mut new_patch = Self::new(&self.title, &self.id, &self.author);
|
|
|
new_patch.set_base(&self.base);
|
|
new_patch.set_base(&self.base);
|
|
|
|
|
|
|
|
let mut ops1 = self.ops.0.iter().cloned();
|
|
let mut ops1 = self.ops.0.iter().cloned();
|
|
@@ -260,7 +266,7 @@ impl Patch {
|
|
|
let mut ops1 = ops1.iter().cloned();
|
|
let mut ops1 = ops1.iter().cloned();
|
|
|
let mut ops2 = other.ops.0.iter().cloned();
|
|
let mut ops2 = other.ops.0.iter().cloned();
|
|
|
|
|
|
|
|
- let mut new_patch = Self::new(&self.id, &self.author);
|
|
|
|
|
|
|
+ let mut new_patch = Self::new(&self.title, &self.id, &self.author);
|
|
|
new_patch.set_base(&self.base);
|
|
new_patch.set_base(&self.base);
|
|
|
|
|
|
|
|
let mut op1 = ops1.next();
|
|
let mut op1 = ops1.next();
|
|
@@ -432,7 +438,7 @@ mod tests {
|
|
|
|
|
|
|
|
#[test]
|
|
#[test]
|
|
|
fn test_to_string() {
|
|
fn test_to_string() {
|
|
|
- let mut patch = Patch::new(&gen_id(30), "");
|
|
|
|
|
|
|
+ let mut patch = Patch::new("", &gen_id(30), "");
|
|
|
patch.set_base("text example\n hello");
|
|
patch.set_base("text example\n hello");
|
|
|
patch.retain(14);
|
|
patch.retain(14);
|
|
|
patch.delete(5);
|
|
patch.delete(5);
|
|
@@ -443,7 +449,7 @@ mod tests {
|
|
|
|
|
|
|
|
#[test]
|
|
#[test]
|
|
|
fn test_merge() {
|
|
fn test_merge() {
|
|
|
- let mut patch_init = Patch::new(&gen_id(30), "");
|
|
|
|
|
|
|
+ let mut patch_init = Patch::new("", &gen_id(30), "");
|
|
|
let base = "text example\n hello";
|
|
let base = "text example\n hello";
|
|
|
patch_init.set_base(base);
|
|
patch_init.set_base(base);
|
|
|
|
|
|
|
@@ -481,7 +487,7 @@ mod tests {
|
|
|
|
|
|
|
|
#[test]
|
|
#[test]
|
|
|
fn test_transform() {
|
|
fn test_transform() {
|
|
|
- let mut patch_init = Patch::new(&gen_id(30), "");
|
|
|
|
|
|
|
+ let mut patch_init = Patch::new("", &gen_id(30), "");
|
|
|
let base = "text example\n hello";
|
|
let base = "text example\n hello";
|
|
|
patch_init.set_base(base);
|
|
patch_init.set_base(base);
|
|
|
|
|
|
|
@@ -528,7 +534,7 @@ mod tests {
|
|
|
assert_eq!(op_method, op_method_deser);
|
|
assert_eq!(op_method, op_method_deser);
|
|
|
|
|
|
|
|
// serialize & deserialize Patch
|
|
// serialize & deserialize Patch
|
|
|
- let mut patch = Patch::new(&gen_id(30), "");
|
|
|
|
|
|
|
+ let mut patch = Patch::new("", &gen_id(30), "");
|
|
|
patch.insert("hello");
|
|
patch.insert("hello");
|
|
|
patch.delete(2);
|
|
patch.delete(2);
|
|
|
|
|
|