-
Notifications
You must be signed in to change notification settings - Fork 342
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
Add proof of concept serde support with PathBuf #512
base: main
Are you sure you want to change the base?
Conversation
@jamesmunns would it be possible to use |
@yoshuawuyts I think so! It's a habit of mine to just use |
Things that need to be decided now:
Once we decide and correct those, we can probably land this with just PathBuf supported, then start incrementally covering more data types. Or we can hit them all at once in this PR. |
Another thing we may want to consider is adding an entry to our "features" section in |
@yoshuawuyts ah, no, I think we need a
|
Should we put serde support behind a new feature flag, perhaps named See also: rust-lang/api-guidelines#180 |
Hmm, this needs a deeper look. My first approach won't work. use async_std;
use serde_json::to_string;
use serde::{self, Serialize, Deserialize};
#[derive(Serialize, Deserialize)]
struct Hmmm {
ex: async_std::path::PathBuf,
}
fn main() {
dbg!(to_string(&Hmmm {
ex: async_std::path::PathBuf::new(),
}).unwrap());
}
There's likely still a way, just probably a bit less elegant. Merits further investigation. |
But it does work for newtypes! c70f00e switches
I don't think this needs to be a breaking change? And for fields where a newtype doesn't work, we can always manually impl |
We've never provided guarantees about internals, so indeed don't think it's a breaking change. I think this PR looks great; but probably want to give @stjepang a chance to sign off on it too before we merge. |
@stjepang just let me know if you'd prefer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yoshuawuyts and I discussed this during triage.
I'm 👍 with the idea of making more and more async-std types implement Serialize
and Deserialize
.
I don't think those implementations should also go behind the unstable
flag, that would a bit too cautious to the point where stabilizations becomes an nuisance with little benefit.
Approving. Thanks for submitting the PR! :)
@dtolnay Do you think we should name the feature flag |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recommend sticking with "serde".
Two thoughts:
- I am skeptical of making this a default feature. What fraction of users need this enabled? Or is it default only because you already depend on something that depends on serde?
- I am skeptical of using serde_derive. A pair of Serialize/Deserialize impls for a wrapper type that forwards to the inner PathBuf's impls are ~15 lines to write. Is that a better tradeoff?
Agreed; this should only be available when the
Oh, yeah a manual impl def sounds better here. Thanks for suggesting! |
Status? Edit: That approach wont work in every case, as quick experiment with |
How is the state of this? ( personally need serde support exactly for PathBuf) |
This is a proof of concept for supporting types from
async_std
to be used with Serde. For now I have only implemented support for PathBuf, but if you like this, we can start rolling it out to all of the wrapped types.