toml-rs / toml

Rust TOML Parser
https://docs.rs/toml
Apache License 2.0
654 stars 98 forks source link

Emitting `serde_spanned` from other crates (formats) #634

Open Kixunil opened 8 months ago

Kixunil commented 8 months ago

I'd like to be able to emit Spanned in rfc822-like. I think an API like this could work:

impl<''de> Deserializer<'de> for MyDeserializer {
    // ...
    fn deserialize_struct<V: Visitor<'de>>(name: &'static str, fields: &'static [&'static str], visitor: V) -> Result<V::Value, Self::Error> {
        if serde_spanned::is_spanned(name, fields) {
            serde_spanned::emit_spanned(self, self.span)
        } else {
            // normal deserialization here
        }
    }
}
epage commented 8 months ago

Could you try patching in #635 and seeing if it works for you?

Kixunil commented 8 months ago

Thanks for quick response! I don't expect to be able to do it very soon but will try not to lag too much.