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
Way to pair serialize_with and deserialize_with into one attribute #763
Comments
So the |
I haven't thought about how it would work yet. I think the way you are suggesting is you give the attribute a path to a wrapper type: struct Url(url::Url);
impl Serialize for Url { ... }
impl Deserialize for Url { ... } A different approach that would be more similar to serialize_with and deserialize_with would be to give the attribute a path to a module containing ser and de functions: mod url {
fn serialize<S>(...) { ... }
fn deserialize<D>(...) { ... }
} Right now I am leaning toward the module approach because it means that simple wrapper libraries like url_serde can be used just with |
Oh, your idea is much more general, since it also supports the case where the "wrapper type" is not a wrapper type at all, but e.g. some random type from another crate. |
@nox my #[derive(Serialize, Deserialize)]
struct MyStruct {
- #[serde(deserialize_with = "hyper_serde::deserialize",
- serialize_with = "hyper_serde::serialize")]
+ #[serde(with = "hyper_serde")]
headers: Headers,
} Any concerns or suggestions? |
I released this in 0.9.8. |
This gets tedious because you almost always want these paired. Can we deduplicate into one attribute?
#[serde(with = "url_serde")]
The text was updated successfully, but these errors were encountered: