Skip to content

Commit

Permalink
Support deserializing from &RawValue
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Sep 13, 2023
1 parent 2c22077 commit fe30766
Showing 1 changed file with 240 additions and 0 deletions.
240 changes: 240 additions & 0 deletions src/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -527,3 +527,243 @@ impl<'de> MapAccess<'de> for BorrowedRawDeserializer<'de> {
seed.deserialize(BorrowedStrDeserializer::new(self.raw_value.take().unwrap()))
}
}

impl<'de> Deserializer<'de> for &'de RawValue {
type Error = Error;

fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Error>
where
V: Visitor<'de>,
{
crate::Deserializer::from_str(&self.json).deserialize_any(visitor)
}

fn deserialize_bool<V>(self, visitor: V) -> Result<V::Value, Error>
where
V: Visitor<'de>,
{
crate::Deserializer::from_str(&self.json).deserialize_bool(visitor)
}

fn deserialize_i8<V>(self, visitor: V) -> Result<V::Value, Error>
where
V: Visitor<'de>,
{
crate::Deserializer::from_str(&self.json).deserialize_i8(visitor)
}

fn deserialize_i16<V>(self, visitor: V) -> Result<V::Value, Error>
where
V: Visitor<'de>,
{
crate::Deserializer::from_str(&self.json).deserialize_i16(visitor)
}

fn deserialize_i32<V>(self, visitor: V) -> Result<V::Value, Error>
where
V: Visitor<'de>,
{
crate::Deserializer::from_str(&self.json).deserialize_i32(visitor)
}

fn deserialize_i64<V>(self, visitor: V) -> Result<V::Value, Error>
where
V: Visitor<'de>,
{
crate::Deserializer::from_str(&self.json).deserialize_i64(visitor)
}

fn deserialize_i128<V>(self, visitor: V) -> Result<V::Value, Error>
where
V: Visitor<'de>,
{
crate::Deserializer::from_str(&self.json).deserialize_i128(visitor)
}

fn deserialize_u8<V>(self, visitor: V) -> Result<V::Value, Error>
where
V: Visitor<'de>,
{
crate::Deserializer::from_str(&self.json).deserialize_u8(visitor)
}

fn deserialize_u16<V>(self, visitor: V) -> Result<V::Value, Error>
where
V: Visitor<'de>,
{
crate::Deserializer::from_str(&self.json).deserialize_u16(visitor)
}

fn deserialize_u32<V>(self, visitor: V) -> Result<V::Value, Error>
where
V: Visitor<'de>,
{
crate::Deserializer::from_str(&self.json).deserialize_u32(visitor)
}

fn deserialize_u64<V>(self, visitor: V) -> Result<V::Value, Error>
where
V: Visitor<'de>,
{
crate::Deserializer::from_str(&self.json).deserialize_u64(visitor)
}

fn deserialize_u128<V>(self, visitor: V) -> Result<V::Value, Error>
where
V: Visitor<'de>,
{
crate::Deserializer::from_str(&self.json).deserialize_u128(visitor)
}

fn deserialize_f32<V>(self, visitor: V) -> Result<V::Value, Error>
where
V: Visitor<'de>,
{
crate::Deserializer::from_str(&self.json).deserialize_f32(visitor)
}

fn deserialize_f64<V>(self, visitor: V) -> Result<V::Value, Error>
where
V: Visitor<'de>,
{
crate::Deserializer::from_str(&self.json).deserialize_f64(visitor)
}

fn deserialize_char<V>(self, visitor: V) -> Result<V::Value, Error>
where
V: Visitor<'de>,
{
crate::Deserializer::from_str(&self.json).deserialize_char(visitor)
}

fn deserialize_str<V>(self, visitor: V) -> Result<V::Value, Error>
where
V: Visitor<'de>,
{
crate::Deserializer::from_str(&self.json).deserialize_str(visitor)
}

fn deserialize_string<V>(self, visitor: V) -> Result<V::Value, Error>
where
V: Visitor<'de>,
{
crate::Deserializer::from_str(&self.json).deserialize_string(visitor)
}

fn deserialize_bytes<V>(self, visitor: V) -> Result<V::Value, Error>
where
V: Visitor<'de>,
{
crate::Deserializer::from_str(&self.json).deserialize_bytes(visitor)
}

fn deserialize_byte_buf<V>(self, visitor: V) -> Result<V::Value, Error>
where
V: Visitor<'de>,
{
crate::Deserializer::from_str(&self.json).deserialize_byte_buf(visitor)
}

fn deserialize_option<V>(self, visitor: V) -> Result<V::Value, Error>
where
V: Visitor<'de>,
{
crate::Deserializer::from_str(&self.json).deserialize_option(visitor)
}

fn deserialize_unit<V>(self, visitor: V) -> Result<V::Value, Error>
where
V: Visitor<'de>,
{
crate::Deserializer::from_str(&self.json).deserialize_unit(visitor)
}

fn deserialize_unit_struct<V>(self, name: &'static str, visitor: V) -> Result<V::Value, Error>
where
V: Visitor<'de>,
{
crate::Deserializer::from_str(&self.json).deserialize_unit_struct(name, visitor)
}

fn deserialize_newtype_struct<V>(
self,
name: &'static str,
visitor: V,
) -> Result<V::Value, Error>
where
V: Visitor<'de>,
{
crate::Deserializer::from_str(&self.json).deserialize_newtype_struct(name, visitor)
}

fn deserialize_seq<V>(self, visitor: V) -> Result<V::Value, Error>
where
V: Visitor<'de>,
{
crate::Deserializer::from_str(&self.json).deserialize_seq(visitor)
}

fn deserialize_tuple<V>(self, len: usize, visitor: V) -> Result<V::Value, Error>
where
V: Visitor<'de>,
{
crate::Deserializer::from_str(&self.json).deserialize_tuple(len, visitor)
}

fn deserialize_tuple_struct<V>(
self,
name: &'static str,
len: usize,
visitor: V,
) -> Result<V::Value, Error>
where
V: Visitor<'de>,
{
crate::Deserializer::from_str(&self.json).deserialize_tuple_struct(name, len, visitor)
}

fn deserialize_map<V>(self, visitor: V) -> Result<V::Value, Error>
where
V: Visitor<'de>,
{
crate::Deserializer::from_str(&self.json).deserialize_map(visitor)
}

fn deserialize_struct<V>(
self,
name: &'static str,
fields: &'static [&'static str],
visitor: V,
) -> Result<V::Value, Error>
where
V: Visitor<'de>,
{
crate::Deserializer::from_str(&self.json).deserialize_struct(name, fields, visitor)
}

fn deserialize_enum<V>(
self,
name: &'static str,
variants: &'static [&'static str],
visitor: V,
) -> Result<V::Value, Error>
where
V: Visitor<'de>,
{
crate::Deserializer::from_str(&self.json).deserialize_enum(name, variants, visitor)
}

fn deserialize_identifier<V>(self, visitor: V) -> Result<V::Value, Error>
where
V: Visitor<'de>,
{
crate::Deserializer::from_str(&self.json).deserialize_identifier(visitor)
}

fn deserialize_ignored_any<V>(self, visitor: V) -> Result<V::Value, Error>
where
V: Visitor<'de>,
{
crate::Deserializer::from_str(&self.json).deserialize_ignored_any(visitor)
}
}

0 comments on commit fe30766

Please sign in to comment.