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

Consider implementing IntoDeserializer for serde's IntoDeserializer impls #2498

Closed
dtolnay opened this issue Jul 9, 2023 · 0 comments · Fixed by #2568
Closed

Consider implementing IntoDeserializer for serde's IntoDeserializer impls #2498

dtolnay opened this issue Jul 9, 2023 · 0 comments · Fixed by #2568

Comments

@dtolnay
Copy link
Member

dtolnay commented Jul 9, 2023

For example:

impl<'de, E> IntoDeserializer<'de, E> for BorrowedStrDeserializer<'de, E>
where
    E: de::Error,
{
    type Deserializer = Self;

    fn into_deserializer(self) -> Self {
        self
    }
}

This would be useful to #2467.

Instead of:

struct BorrowedStr<'de>(&'de str);
impl<'de, E: de::Error> IntoDeserializer<'de, E> for BorrowedStr<'de> {
    type Deserializer = BorrowedStrDeserializer<'de, E>;
    fn into_deserializer(self) -> Self::Deserializer {
        BorrowedStrDeserializer::new(self.0)
    }
}
let deserializer = MapDeserializer::new(
    my_map.into_iter().map(|(k, v)| {
        (BorrowedStr(k), BorrowedStr(v))
    }),
);

you'd have:

use serde::de::value::BorrowedStrDeserializer;

let deserializer = MapDeserializer::new(
    my_map.into_iter().map(|(k, v)| {
        (BorrowedStrDeserializer::new(k), BorrowedStrDeserializer::new(v))
    }),
);

Note that MapDeserializer requires an input of type impl Iterator<Item = (impl IntoDeserializer<'de, E>, impl IntoDeserializer<'de, E>)>.

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

Successfully merging a pull request may close this issue.

1 participant