Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature request: Better tolerance for missing fields in derived hydrate for forward-compatibility #52

Open
aran opened this issue Jun 13, 2024 · 2 comments

Comments

@aran
Copy link
Contributor

aran commented Jun 13, 2024

If I have a struct TOld and add a field to my code to make TNew, I may want to hydrate a TOld into a TNew.

As a concrete example, if I add a new Option<X> field, (perhaps configurably) it should treat missing field as a None.
If I add a field that has implements Default I could also see it treating a missing field as that ::default().

Currently the Hydrate implementation for Option throws an Unexpected when a field is missing.

Quick notes:

  • There's lots of decisions needed in how the API could look for this
  • I think in general this kind of forward-compatibility should be doable if semantically TOld is a subtype of TNew (Liskov substitutable)
  • Thinking about forward-compatibility obviously raises the idea of push-safety / backward compatibility, which would suggest explicitly doing the opposite of Autosurgeon reconcile not clearing all old data #46 so old code could still read new documents. I believe changes are backward compatible if TNew is a subtype of TOld.
@alexjg
Copy link
Collaborator

alexjg commented Jun 13, 2024

Does the missing= attribute address the migration problem?

@aran
Copy link
Contributor Author

aran commented Jun 13, 2024

...I just came back here to mea culpa after seeing it.

I'm going to say "kind of", because it's a subjective API decision, but I'll note that my naive expectation was that Option<X> would behave that way out of the box. Not sure of the right call.

Looks like the following little utilities work fine with missing= (?), which would ease the burden a little.

fn none<T>() -> Option<T> {
    None
}

fn default<T: Default>() -> T {
    T::default()
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants