You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+7-2Lines changed: 7 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -48,18 +48,23 @@ assert_ne!(diffed, second);
48
48
For more examples take a look at [integration tests](/tests)
49
49
50
50
## Derive macro attributes
51
-
-`#[difference(skip)]`- Do not consider this field when creating a diff
52
-
-`#[difference(recurse)]`- Generate a StructDiff for this field when creating a diff
51
+
-`#[difference(skip)]` - Do not consider this field when creating a diff
52
+
-`#[difference(recurse)]` - Generate a StructDiff for this field when creating a diff
53
53
-`#[difference(collection_strategy = {})]`
54
54
-`"unordered_array_like"` - Generates a changeset for array-like collections of items which implement `Hash + Eq`, rather than cloning the entire list. (currently works for `Vec`, `BTreeSet`, `LinkedList`, and `HashSet`)
55
55
-`"unordered_map_like"` - Generates a changeset for map-like collections for which the key implements `Hash + Eq`, rather than cloning the entire map. (currently works for `HashMap` and `BTreeMap`)
56
56
-`#[difference(map_equality = {})]` - Used with `unordered_map_like`, specifies whether the equality check should consider keys only, or both keys and values
57
57
-`"key_only"` - only replace a key-value pair for which the key has changed
58
58
-`"key_and_value"` - replace a key-value pair if either the key or value has changed
59
+
-`#[difference(setters)]` - Generate setters for all fields in the struct (used on struct)
60
+
- Example: for the `field1` of the `Example` struct used above, a function with the signature `set_field1_with_diff(&mut self, value: Option<usize>) -> Option<<Self as StructDiff>::Diff>` will be generated. Useful when a single field will be changed in a struct with many fields, as it saves the comparison of all other fields.
61
+
-`#[difference(setter)]` - Generate setters for this struct field (used on field)
62
+
-`#[difference(setter_name = {})]` - Use this name instead of the default value when generating a setter for this field (used on field)
59
63
60
64
## Optional features
61
65
-[`nanoserde`, `serde`] - Serialization of `Difference` derived associated types. Allows diffs to easily be sent over network.
62
66
-`debug_diffs` - Derive `Debug` on the generated diff type
67
+
-`generated_setters` - Enable generation of setters for struct fields. These setters automatically return a diff if a field's value is changed by the assignment.
63
68
64
69
### Development status
65
70
This is being used actively for my own projects, although it's mostly working now. PRs will be accepted for either more tests or functionality.
0 commit comments