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

Adds Serialize with AsRef or ToString and Deserialize with FromStr #2626

Closed
wants to merge 2 commits into from
Closed

Adds Serialize with AsRef or ToString and Deserialize with FromStr #2626

wants to merge 2 commits into from

Conversation

wyatt-herkamp
Copy link

Adds

  • Serialize #[serde(as_ref = "Type") Calls AsRef and serializes the value
  • Serialize #[serde(to_string) Calls ToString and serializes the String
  • Deserialize #[serde(from_str) Calls FromStr for deserialize.

Copy link
Member

@dtolnay dtolnay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!

The from_str and to_string part of this are a duplicate of #2017. I would prefer not to build that into this crate but they are available in serde_with. The implementation there is more powerful than the one in this PR because deserialization works for data formats that do not expose borrowed data, such as deserializing from a std::io::Read.

For as_ref, I would similarly prefer not to build that into this crate. Like to_string, this is substituting for a pretty trivial Serialize impl that one can go ahead and handwrite without needing macro support; I don't see the use case occurring commonly enough to warrant dedicating an attribute (and compile time) to.

@dtolnay dtolnay closed this Oct 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants