Closed cuviper closed 1 year ago
neat idea. I'll look into this next weekend
It looks like we have:
impl<'a: 'de, 'de> de::Deserializer<'de> for Val<'a> {
type Error = Error;
fn deserialize_any<V>(
self,
visitor: V,
) -> Result<V::Value>
where
V: de::Visitor<'de>,
{
BorrowedStrDeserializer::new(self.1).deserialize_any(visitor)
}
in the current code of the crate, so this should work no?
Cool! It looks like that was #13, and my original example does compile now.
💡 Feature description
It would be nice to be able to capture referenced data, like a more general
Deserialize<'de>
rather than justDeserializeOwned
.I realize that
FromStr
can't borrow data, since there's no lifetime parameter to use in relation toSelf
, but maybe there could be atrait Recap<'s>
which does permit borrowing. I would thinkrecap::from_captures
could just use a'de
parameter forD: Deserialize<'de>
.💻 Basic example
I tried to write something like this for Advent of Code 2015 day 9:
It's not a big deal to use
String
instead in this case, since there aren't very many inputs overall, but it seems like a borrowed&str
should be possible.