@@ -9,7 +9,8 @@ A lib help you patch Rust instance, and easy to partial update configures.
99This crate provides the ` Patch ` , ` Filler ` traits and accompanying derive macro.
1010If the any field in ` Patch ` is some then it will overwrite the field of instance when apply.
1111If the any field in the instance is none then it will try to fill the field with the ` Filler ` .
12- Currently, ` Filler ` only support ` Option ` field, and the ` Vec ` and other field will implement later.
12+ Currently, ` Filler ` only support ` Option ` field and the ` Vec ` .
13+ The other fields and operator for Filler will implement later.
1314The detail discussion is in [ issue #81 ] ( https://github.com/yanganto/struct-patch/issues/81 )
1415
1516## Quick Example
@@ -73,21 +74,29 @@ use struct_patch::Filler;
7374struct Item {
7475 field_int : usize ,
7576 maybe_field_int : Option <usize >,
77+ list : Vec <uszie >,
7678}
7779let mut item = Item {
7880 field_int : 0 ,
7981 maybe_field_int : None ,
82+ list : Vec :: new (),
8083};
8184
82- let filler_1 = ItemFiller { maybe_field_int : Some (7 ), };
85+ let filler_1 = ItemFiller { maybe_field_int : Some (7 ), list : Vec :: new () };
8386item . apply (filler_1 );
8487assert_eq! (item . maybe_field_int, Some (7 ));
8588
86- let filler_2 = ItemFiller { maybe_field_int : Some (100 ), };
89+ let filler_2 = ItemFiller { maybe_field_int : Some (100 ), list : Vec :: new () };
8790
8891// The field is not empty, so the filler has not effect.
8992item . apply (filler_2 );
9093assert_eq! (item . maybe_field_int, Some (7 ));
94+
95+ let filler_3 = ItemFiller { maybe_field_int : Some (100 ), list : vec! [7 ] };
96+
97+ item . apply (filler_3 );
98+ assert_eq! (item . maybe_field_int, Some (7 ));
99+ assert_eq! (item . list, vec! [7 ]);
91100```
92101
93102## Documentation and Examples
0 commit comments