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

Allow deserializing from disk #1

Closed
yoshuawuyts opened this issue Oct 16, 2018 · 3 comments
Closed

Allow deserializing from disk #1

yoshuawuyts opened this issue Oct 16, 2018 · 3 comments
Labels
help wanted Extra attention is needed

Comments

@yoshuawuyts
Copy link
Contributor

Feature Request

Summary

Enable the Deserialize trait.

Motivation

This allows files to be read from disk and parsed using this crate.

Guide-level explanation

Explain the proposal as if it was already included in the project and you
were teaching it to another programmer. That generally means:

  • Introducing new named concepts.
  • Explaining the feature largely in terms of examples.
  • If applicable, provide sample error messages, deprecation warnings, or
    migration guidance.

Drawbacks

None

Rationale and alternatives

This makes this crate useful for both serializing and deserializing.

Unresolved Questions

Right now there's some lifetime problems that need to be figured out when implementing this.

@yoshuawuyts yoshuawuyts added the help wanted Extra attention is needed label Oct 16, 2018
@maxdeviant
Copy link
Collaborator

I started taking a look at this, and it seems like the pain has to do with using Vecs of references on the Manifest struct.

// This fails to compile.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Manifest<'s, 'i, 'r> {
  // ... elided
  #[serde(borrow)]
  icons: Vec<&'i Icon<'i>>,
  #[serde(borrow)]
  related_applications: Vec<&'r Related<'r>>,
}
// This compiles fine.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Manifest<'s, 'i, 'r> {
  // ... elided
  #[serde(borrow)]
  icons: Vec<Icon<'i>>,
  #[serde(borrow)]
  related_applications: Vec<Related<'r>>,
}

So far I have yet to find anything in the Serde docs about deserializing references

@maxdeviant
Copy link
Collaborator

According to this comment:

Oh working with collections + attributes is currently obnoxious because we don't yet have a way to apply attributes to the content of a collection. This is tracked in #723.

It is possible to make it work but unless you really need it, I would recommend sticking to owned types in collections (just like you would have in any previous version of Serde).

It does list a (rather ugly) workaround that we could try.

Thoughts @yoshuawuyts?

@yoshuawuyts
Copy link
Contributor Author

@maxdeviant ugh, yeah, it probably needs to be owned then. Shame :(

maxdeviant added a commit to deviant-forks/webmanifest that referenced this issue Oct 20, 2018
maxdeviant added a commit to deviant-forks/webmanifest that referenced this issue Oct 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants