Skip to content

Commit 4ea34a2

Browse files
authored
Merge pull request #1072 from dtolnay/rawvalue
Support deserializing from &RawValue
2 parents 2c22077 + fe30766 commit 4ea34a2

File tree

1 file changed

+240
-0
lines changed

1 file changed

+240
-0
lines changed

src/raw.rs

+240
Original file line numberDiff line numberDiff line change
@@ -527,3 +527,243 @@ impl<'de> MapAccess<'de> for BorrowedRawDeserializer<'de> {
527527
seed.deserialize(BorrowedStrDeserializer::new(self.raw_value.take().unwrap()))
528528
}
529529
}
530+
531+
impl<'de> Deserializer<'de> for &'de RawValue {
532+
type Error = Error;
533+
534+
fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Error>
535+
where
536+
V: Visitor<'de>,
537+
{
538+
crate::Deserializer::from_str(&self.json).deserialize_any(visitor)
539+
}
540+
541+
fn deserialize_bool<V>(self, visitor: V) -> Result<V::Value, Error>
542+
where
543+
V: Visitor<'de>,
544+
{
545+
crate::Deserializer::from_str(&self.json).deserialize_bool(visitor)
546+
}
547+
548+
fn deserialize_i8<V>(self, visitor: V) -> Result<V::Value, Error>
549+
where
550+
V: Visitor<'de>,
551+
{
552+
crate::Deserializer::from_str(&self.json).deserialize_i8(visitor)
553+
}
554+
555+
fn deserialize_i16<V>(self, visitor: V) -> Result<V::Value, Error>
556+
where
557+
V: Visitor<'de>,
558+
{
559+
crate::Deserializer::from_str(&self.json).deserialize_i16(visitor)
560+
}
561+
562+
fn deserialize_i32<V>(self, visitor: V) -> Result<V::Value, Error>
563+
where
564+
V: Visitor<'de>,
565+
{
566+
crate::Deserializer::from_str(&self.json).deserialize_i32(visitor)
567+
}
568+
569+
fn deserialize_i64<V>(self, visitor: V) -> Result<V::Value, Error>
570+
where
571+
V: Visitor<'de>,
572+
{
573+
crate::Deserializer::from_str(&self.json).deserialize_i64(visitor)
574+
}
575+
576+
fn deserialize_i128<V>(self, visitor: V) -> Result<V::Value, Error>
577+
where
578+
V: Visitor<'de>,
579+
{
580+
crate::Deserializer::from_str(&self.json).deserialize_i128(visitor)
581+
}
582+
583+
fn deserialize_u8<V>(self, visitor: V) -> Result<V::Value, Error>
584+
where
585+
V: Visitor<'de>,
586+
{
587+
crate::Deserializer::from_str(&self.json).deserialize_u8(visitor)
588+
}
589+
590+
fn deserialize_u16<V>(self, visitor: V) -> Result<V::Value, Error>
591+
where
592+
V: Visitor<'de>,
593+
{
594+
crate::Deserializer::from_str(&self.json).deserialize_u16(visitor)
595+
}
596+
597+
fn deserialize_u32<V>(self, visitor: V) -> Result<V::Value, Error>
598+
where
599+
V: Visitor<'de>,
600+
{
601+
crate::Deserializer::from_str(&self.json).deserialize_u32(visitor)
602+
}
603+
604+
fn deserialize_u64<V>(self, visitor: V) -> Result<V::Value, Error>
605+
where
606+
V: Visitor<'de>,
607+
{
608+
crate::Deserializer::from_str(&self.json).deserialize_u64(visitor)
609+
}
610+
611+
fn deserialize_u128<V>(self, visitor: V) -> Result<V::Value, Error>
612+
where
613+
V: Visitor<'de>,
614+
{
615+
crate::Deserializer::from_str(&self.json).deserialize_u128(visitor)
616+
}
617+
618+
fn deserialize_f32<V>(self, visitor: V) -> Result<V::Value, Error>
619+
where
620+
V: Visitor<'de>,
621+
{
622+
crate::Deserializer::from_str(&self.json).deserialize_f32(visitor)
623+
}
624+
625+
fn deserialize_f64<V>(self, visitor: V) -> Result<V::Value, Error>
626+
where
627+
V: Visitor<'de>,
628+
{
629+
crate::Deserializer::from_str(&self.json).deserialize_f64(visitor)
630+
}
631+
632+
fn deserialize_char<V>(self, visitor: V) -> Result<V::Value, Error>
633+
where
634+
V: Visitor<'de>,
635+
{
636+
crate::Deserializer::from_str(&self.json).deserialize_char(visitor)
637+
}
638+
639+
fn deserialize_str<V>(self, visitor: V) -> Result<V::Value, Error>
640+
where
641+
V: Visitor<'de>,
642+
{
643+
crate::Deserializer::from_str(&self.json).deserialize_str(visitor)
644+
}
645+
646+
fn deserialize_string<V>(self, visitor: V) -> Result<V::Value, Error>
647+
where
648+
V: Visitor<'de>,
649+
{
650+
crate::Deserializer::from_str(&self.json).deserialize_string(visitor)
651+
}
652+
653+
fn deserialize_bytes<V>(self, visitor: V) -> Result<V::Value, Error>
654+
where
655+
V: Visitor<'de>,
656+
{
657+
crate::Deserializer::from_str(&self.json).deserialize_bytes(visitor)
658+
}
659+
660+
fn deserialize_byte_buf<V>(self, visitor: V) -> Result<V::Value, Error>
661+
where
662+
V: Visitor<'de>,
663+
{
664+
crate::Deserializer::from_str(&self.json).deserialize_byte_buf(visitor)
665+
}
666+
667+
fn deserialize_option<V>(self, visitor: V) -> Result<V::Value, Error>
668+
where
669+
V: Visitor<'de>,
670+
{
671+
crate::Deserializer::from_str(&self.json).deserialize_option(visitor)
672+
}
673+
674+
fn deserialize_unit<V>(self, visitor: V) -> Result<V::Value, Error>
675+
where
676+
V: Visitor<'de>,
677+
{
678+
crate::Deserializer::from_str(&self.json).deserialize_unit(visitor)
679+
}
680+
681+
fn deserialize_unit_struct<V>(self, name: &'static str, visitor: V) -> Result<V::Value, Error>
682+
where
683+
V: Visitor<'de>,
684+
{
685+
crate::Deserializer::from_str(&self.json).deserialize_unit_struct(name, visitor)
686+
}
687+
688+
fn deserialize_newtype_struct<V>(
689+
self,
690+
name: &'static str,
691+
visitor: V,
692+
) -> Result<V::Value, Error>
693+
where
694+
V: Visitor<'de>,
695+
{
696+
crate::Deserializer::from_str(&self.json).deserialize_newtype_struct(name, visitor)
697+
}
698+
699+
fn deserialize_seq<V>(self, visitor: V) -> Result<V::Value, Error>
700+
where
701+
V: Visitor<'de>,
702+
{
703+
crate::Deserializer::from_str(&self.json).deserialize_seq(visitor)
704+
}
705+
706+
fn deserialize_tuple<V>(self, len: usize, visitor: V) -> Result<V::Value, Error>
707+
where
708+
V: Visitor<'de>,
709+
{
710+
crate::Deserializer::from_str(&self.json).deserialize_tuple(len, visitor)
711+
}
712+
713+
fn deserialize_tuple_struct<V>(
714+
self,
715+
name: &'static str,
716+
len: usize,
717+
visitor: V,
718+
) -> Result<V::Value, Error>
719+
where
720+
V: Visitor<'de>,
721+
{
722+
crate::Deserializer::from_str(&self.json).deserialize_tuple_struct(name, len, visitor)
723+
}
724+
725+
fn deserialize_map<V>(self, visitor: V) -> Result<V::Value, Error>
726+
where
727+
V: Visitor<'de>,
728+
{
729+
crate::Deserializer::from_str(&self.json).deserialize_map(visitor)
730+
}
731+
732+
fn deserialize_struct<V>(
733+
self,
734+
name: &'static str,
735+
fields: &'static [&'static str],
736+
visitor: V,
737+
) -> Result<V::Value, Error>
738+
where
739+
V: Visitor<'de>,
740+
{
741+
crate::Deserializer::from_str(&self.json).deserialize_struct(name, fields, visitor)
742+
}
743+
744+
fn deserialize_enum<V>(
745+
self,
746+
name: &'static str,
747+
variants: &'static [&'static str],
748+
visitor: V,
749+
) -> Result<V::Value, Error>
750+
where
751+
V: Visitor<'de>,
752+
{
753+
crate::Deserializer::from_str(&self.json).deserialize_enum(name, variants, visitor)
754+
}
755+
756+
fn deserialize_identifier<V>(self, visitor: V) -> Result<V::Value, Error>
757+
where
758+
V: Visitor<'de>,
759+
{
760+
crate::Deserializer::from_str(&self.json).deserialize_identifier(visitor)
761+
}
762+
763+
fn deserialize_ignored_any<V>(self, visitor: V) -> Result<V::Value, Error>
764+
where
765+
V: Visitor<'de>,
766+
{
767+
crate::Deserializer::from_str(&self.json).deserialize_ignored_any(visitor)
768+
}
769+
}

0 commit comments

Comments
 (0)