-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add `Add` between instance and patch * update testcase * Move `Add` to `add` feature * Update struct-patch-derive/src/lib.rs Co-authored-by: Thomas DA ROCHA <thomas.darocha@lenra.io> * Add add example * Reuse instance test case with add feature * Fix Add with generics * feat: Implement Add<patch> for patch (#33) * feat: Implement Add<patch> for patch * Use `Shl` as default feature and remove `add` * Allow patch + patch if no conflict * Setup `op` feature * add more assertions on op example * fix type specific issue with std feature * refine panic message --------- Co-authored-by: Thomas DA ROCHA <thomas.darocha@lenra.io>
- Loading branch information
1 parent
db68b86
commit 0ee5705
Showing
8 changed files
with
284 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
use struct_patch::Patch; | ||
|
||
#[derive(Clone, Default, Patch)] | ||
#[patch(attribute(derive(Clone, Debug, Default)))] | ||
struct Item { | ||
field_complete: bool, | ||
field_int: usize, | ||
field_string: String, | ||
} | ||
|
||
#[cfg(feature = "op")] | ||
fn main() { | ||
let mut item = Item::default(); | ||
|
||
let mut patch: ItemPatch = Item::new_empty_patch(); | ||
|
||
patch.field_int = Some(7); | ||
|
||
assert_eq!( | ||
format!("{patch:?}"), | ||
"ItemPatch { field_complete: None, field_int: Some(7), field_string: None }" | ||
); | ||
|
||
item.apply(patch); | ||
|
||
assert_eq!(item.field_complete, false); | ||
assert_eq!(item.field_int, 7); | ||
assert_eq!(item.field_string, ""); | ||
|
||
let another_patch = ItemPatch { | ||
field_complete: None, | ||
field_int: None, | ||
field_string: Some("from another patch".into()), | ||
}; | ||
|
||
let _conflict_patch = ItemPatch { | ||
field_complete: None, | ||
field_int: Some(1), | ||
field_string: Some("from another patch".into()), | ||
}; | ||
|
||
let the_other_patch = ItemPatch { | ||
field_complete: Some(true), | ||
field_int: Some(2), | ||
field_string: None, | ||
}; | ||
|
||
// let final_item_from_merge = item.clone() << (_conflict_patch + the_other_patch.clone()); | ||
// Will get panic `There are conflict patches on ItemPatch.field_int` | ||
// | ||
// TODO | ||
// Will be handdled as the discussion | ||
// https://github.com/yanganto/struct-patch/pull/32#issuecomment-2283154990 | ||
|
||
let final_item_from_merge = item.clone() << (another_patch.clone() + the_other_patch.clone()); | ||
assert_eq!(final_item_from_merge.field_string, "from another patch"); | ||
assert_eq!(final_item_from_merge.field_complete, true); | ||
|
||
let final_item_series_patch = item << another_patch << the_other_patch; | ||
assert_eq!(final_item_series_patch.field_string, "from another patch"); | ||
assert_eq!(final_item_series_patch.field_complete, true); | ||
} | ||
|
||
#[cfg(not(feature = "op"))] | ||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters