@@ -27,12 +27,14 @@ notion of a type for which two members can be simultaneously compared.
27
27
use daft :: {Diffable , Leaf };
28
28
29
29
// Annotate your struct with `#[derive(Diffable)]`:
30
+ #[derive(Diffable )]
30
31
struct MyStruct {
31
32
a : i32 ,
32
33
b : String ,
33
34
}
34
35
35
36
// This generates a type called MyStructDiff, which looks like:
37
+ #[automatically_derived]
36
38
struct MyStructDiff <'daft > {
37
39
a : Leaf <& 'daft i32 >,
38
40
b : Leaf <& 'daft str >,
@@ -95,6 +97,7 @@ assert_eq!(diff.before, Some(&1));
95
97
assert_eq! (diff . after, Some (& 2 ));
96
98
97
99
// Automatically derived enums also use Leaf:
100
+ #[derive(Debug , PartialEq , Eq , Diffable )]
98
101
enum MyEnum {
99
102
A (i32 ),
100
103
B (String ),
@@ -261,6 +264,7 @@ Tuple-like structs produce tuple-like diff structs:
261
264
use daft :: Diffable ;
262
265
use std :: collections :: BTreeMap ;
263
266
267
+ #[derive(Diffable )]
264
268
struct MyTuple (BTreeMap <i32 , & 'static str >, i32 );
265
269
266
270
let before = MyTuple (BTreeMap :: new (), 1 );
@@ -278,6 +282,8 @@ An example with `#[daft(leaf)]` on **structs**:
278
282
```` rust
279
283
use daft :: {Diffable , Leaf };
280
284
285
+ #[derive(Diffable )]
286
+ #[daft(leaf)]
281
287
struct MyStruct {
282
288
a : i32 ,
283
289
}
@@ -296,13 +302,16 @@ An example with `#[daft(leaf)]` on **struct fields**:
296
302
use daft :: {Diffable , Leaf };
297
303
298
304
// A simple struct that implements Diffable.
305
+ #[derive(Debug , PartialEq , Eq , Diffable )]
299
306
struct InnerStruct {
300
307
text : & 'static str ,
301
308
}
302
309
303
310
// A struct that does not implement Diffable.
311
+ #[derive(Debug , PartialEq , Eq )]
304
312
struct PlainStruct (usize );
305
313
314
+ #[derive(Diffable )]
306
315
struct OuterStruct {
307
316
// Ordinarily, InnerStruct would be diffed recursively, but
308
317
// with #[daft(leaf)], it is treated as a leaf node.
@@ -383,13 +392,15 @@ outlive it.
383
392
```` rust
384
393
use daft :: Diffable ;
385
394
395
+ #[derive(Diffable )]
386
396
struct BorrowedData <'a , 'b , T : Diffable + ? Sized > {
387
397
a : & 'a str ,
388
398
b : & 'b T ,
389
399
// TODO: example with daft(leaf)
390
400
}
391
401
392
402
// This generates a struct that looks like:
403
+ #[automatically_derived]
393
404
struct BorrowedDataDiff <'daft , 'a : 'daft , 'b : 'daft , T : ? Sized + 'daft > {
394
405
a : Leaf <'daft , & 'a str >,
395
406
b : T :: Diff <'daft >,
0 commit comments