EmbarkStudios / mirror-mirror

🪞 Powerful reflection library for Rust
Apache License 2.0
79 stars 2 forks source link

What are the semantics of `patch()`? #79

Open bnjbvr opened 1 year ago

bnjbvr commented 1 year ago

It seems that patch won't augment existing objects: e.g. if I patch a list with a larger list, the patchee won't get any push for the missing entries. Ditto for structs, and there it makes sense imo: while we could add new fields to the reflected value, this wouldn't have any effect when converting back to the actual struct type. At the same time, one could use Value as a very generic way to manipulate values in general, and then it might make sense to add new fields etc (e.g. a serialization framework could use that to run "migrations").

I'm not advocating for one way or another, I'm just curious about the why behind this choice, and I think it'd make sense documenting that choice in a doc-comment on patch() :)

davidpdrsn commented 1 year ago

Honestly most of the choice are just what I felt was appropriate at the time. Would be good to write down the semantics and align on what exactly they should be.

There are also lots of edge cases to test so its possible I've missed some. That would be good look into as well when documenting/cleaning things.