Debian Codegraph @

debian/missing-sources/serde_json/src/raw.rs

raw
1 use crate::error::Error;
2 use alloc::borrow::ToOwned;
3 use alloc::boxed::Box;
4 use alloc::string::String;
5 use core::fmt::{self, Debug, Display};
6 use core::mem;
7 use serde::de::value::BorrowedStrDeserializer;
8 use serde::de::{
9 self, Deserialize, DeserializeSeed, Deserializer, IntoDeserializer, MapAccess, Unexpected,
10 Visitor,
11 };
12 use serde::forward_to_deserialize_any;
13 use serde::ser::{Serialize, SerializeStruct, Serializer};
14
15 /// Reference to a range of bytes encompassing a single valid JSON value in the
16 /// input data.
17 ///
18 /// A `RawValue` can be used to defer parsing parts of a payload until later,
19 /// or to avoid parsing it at all in the case that part of the payload just
20 /// needs to be transferred verbatim into a different output object.
21 ///
22 /// When serializing, a value of this type will retain its original formatting
23 /// and will not be minified or pretty-printed.
24 ///
25 /// # Note
26 ///
27 /// `RawValue` is only available if serde\_json is built with the `"raw_value"`
28 /// feature.
29 ///
30 /// ```toml
31 /// [dependencies]
32 /// serde_json = { version = "1.0", features = ["raw_value"] }
33 /// ```
34 ///
35 /// # Example
36 ///
37 /// ```
38 /// use serde::{Deserialize, Serialize};
39 /// use serde_json::{Result, value::RawValue};
40 ///
41 /// #[derive(Deserialize)]
42 /// struct Input<'a> {
43 /// code: u32,
44 /// #[serde(borrow)]
45 /// payload: &'a RawValue,
46 /// }
47 ///
48 /// #[derive(Serialize)]
49 /// struct Output<'a> {
50 /// info: (u32, &'a RawValue),
51 /// }
52 ///
53 /// // Efficiently rearrange JSON input containing separate "code" and "payload"
54 /// // keys into a single "info" key holding an array of code and payload.
55 /// //
56 /// // This could be done equivalently using serde_json::Value as the type for
57 /// // payload, but &RawValue will perform better because it does not require
58 /// // memory allocation. The correct range of bytes is borrowed from the input
59 /// // data and pasted verbatim into the output.
60 /// fn rearrange(input: &str) -> Result<String> {
61 /// let input: Input = serde_json::from_str(input)?;
62 ///
63 /// let output = Output {
64 /// info: (input.code, input.payload),
65 /// };
66 ///
67 /// serde_json::to_string(&output)
68 /// }
69 ///
70 /// fn main() -> Result<()> {
71 /// let out = rearrange(r#" {"code": 200, "payload": {}} "#)?;
72 ///
73 /// assert_eq!(out, r#"{"info":[200,{}]}"#);
74 ///
75 /// Ok(())
76 /// }
77 /// ```
78 ///
79 /// # Ownership
80 ///
81 /// The typical usage of `RawValue` will be in the borrowed form:
82 ///
83 /// ```
84 /// # use serde::Deserialize;
85 /// # use serde_json::value::RawValue;
86 /// #
87 /// #[derive(Deserialize)]
88 /// struct SomeStruct<'a> {
89 /// #[serde(borrow)]
90 /// raw_value: &'a RawValue,
91 /// }
92 /// ```
93 ///
94 /// The borrowed form is suitable when deserializing through
95 /// [`serde_json::from_str`] and [`serde_json::from_slice`] which support
96 /// borrowing from the input data without memory allocation.
97 ///
98 /// When deserializing through [`serde_json::from_reader`] you will need to use
99 /// the boxed form of `RawValue` instead. This is almost as efficient but
100 /// involves buffering the raw value from the I/O stream into memory.
101 ///
102 /// [`serde_json::from_str`]: crate::from_str
103 /// [`serde_json::from_slice`]: crate::from_slice
104 /// [`serde_json::from_reader`]: crate::from_reader
105 ///
106 /// ```
107 /// # use serde::Deserialize;
108 /// # use serde_json::value::RawValue;
109 /// #
110 /// #[derive(Deserialize)]
111 /// struct SomeStruct {
112 /// raw_value: Box<RawValue>,
113 /// }
114 /// ```
115 #[cfg_attr(docsrs, doc(cfg(feature = "raw_value")))]
116 #[repr(transparent)]
117 pub struct RawValue {
118 json: str,
119 }
120
121 impl RawValue {
122 const fn from_borrowed(json: &str) -> &Self {
123 unsafe { mem::transmute::<&str, &RawValue>(json) }
124 }
125
126 fn from_owned(json: Box<str>) -> Box<Self> {
127 unsafe { mem::transmute::<Box<str>, Box<RawValue>>(json) }
128 }
129
130 fn into_owned(raw_value: Box<Self>) -> Box<str> {
131 unsafe { mem::transmute::<Box<RawValue>, Box<str>>(raw_value) }
132 }
133 }
134
135 impl Clone for Box<RawValue> {
136 fn clone(&self) -> Self {
137 (**self).to_owned()
138 }
139 }
140
141 impl ToOwned for RawValue {
142 type Owned = Box<RawValue>;
143
144 fn to_owned(&self) -> Self::Owned {
145 RawValue::from_owned(self.json.to_owned().into_boxed_str())
146 }
147 }
148
149 impl Default for Box<RawValue> {
150 fn default() -> Self {
151 RawValue::NULL.to_owned()
152 }
153 }
154
155 impl Debug for RawValue {
156 fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
157 formatter
158 .debug_tuple("RawValue")
159 .field(&format_args!("{}", &self.json))
160 .finish()
161 }
162 }
163
164 impl Display for RawValue {
165 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
166 f.write_str(&self.json)
167 }
168 }
169
170 impl RawValue {
171 /// A constant RawValue with the JSON value `null`.
172 pub const NULL: &'static RawValue = RawValue::from_borrowed("null");
173 /// A constant RawValue with the JSON value `true`.
174 pub const TRUE: &'static RawValue = RawValue::from_borrowed("true");
175 /// A constant RawValue with the JSON value `false`.
176 pub const FALSE: &'static RawValue = RawValue::from_borrowed("false");
177
178 /// Convert an owned `String` of JSON data to an owned `RawValue`.
179 ///
180 /// This function is equivalent to `serde_json::from_str::<Box<RawValue>>`
181 /// except that we avoid an allocation and memcpy if both of the following
182 /// are true:
183 ///
184 /// - the input has no leading or trailing whitespace, and
185 /// - the input has capacity equal to its length.
186 pub fn from_string(json: String) -> Result<Box<Self>, Error> {
187 let borrowed = tri!(crate::from_str::<&Self>(&json));
188 if borrowed.json.len() < json.len() {
189 return Ok(borrowed.to_owned());
190 }
191 Ok(Self::from_owned(json.into_boxed_str()))
192 }
193
194 /// Access the JSON text underlying a raw value.
195 ///
196 /// # Example
197 ///
198 /// ```
199 /// use serde::Deserialize;
200 /// use serde_json::{Result, value::RawValue};
201 ///
202 /// #[derive(Deserialize)]
203 /// struct Response<'a> {
204 /// code: u32,
205 /// #[serde(borrow)]
206 /// payload: &'a RawValue,
207 /// }
208 ///
209 /// fn process(input: &str) -> Result<()> {
210 /// let response: Response = serde_json::from_str(input)?;
211 ///
212 /// let payload = response.payload.get();
213 /// if payload.starts_with('{') {
214 /// // handle a payload which is a JSON map
215 /// } else {
216 /// // handle any other type
217 /// }
218 ///
219 /// Ok(())
220 /// }
221 ///
222 /// fn main() -> Result<()> {
223 /// process(r#" {"code": 200, "payload": {}} "#)?;
224 /// Ok(())
225 /// }
226 /// ```
227 pub fn get(&self) -> &str {
228 &self.json
229 }
230 }
231
232 impl From<Box<RawValue>> for Box<str> {
233 fn from(raw_value: Box<RawValue>) -> Self {
234 RawValue::into_owned(raw_value)
235 }
236 }
237
238 /// Convert a `T` into a boxed `RawValue`.
239 ///
240 /// # Example
241 ///
242 /// ```
243 /// // Upstream crate
244 /// # #[derive(Serialize)]
245 /// pub struct Thing {
246 /// foo: String,
247 /// bar: Option<String>,
248 /// extra_data: Box<RawValue>,
249 /// }
250 ///
251 /// // Local crate
252 /// use serde::Serialize;
253 /// use serde_json::value::{to_raw_value, RawValue};
254 ///
255 /// #[derive(Serialize)]
256 /// struct MyExtraData {
257 /// a: u32,
258 /// b: u32,
259 /// }
260 ///
261 /// let my_thing = Thing {
262 /// foo: "FooVal".into(),
263 /// bar: None,
264 /// extra_data: to_raw_value(&MyExtraData { a: 1, b: 2 }).unwrap(),
265 /// };
266 /// # assert_eq!(
267 /// # serde_json::to_value(my_thing).unwrap(),
268 /// # serde_json::json!({
269 /// # "foo": "FooVal",
270 /// # "bar": null,
271 /// # "extra_data": { "a": 1, "b": 2 }
272 /// # })
273 /// # );
274 /// ```
275 ///
276 /// # Errors
277 ///
278 /// This conversion can fail if `T`'s implementation of `Serialize` decides to
279 /// fail, or if `T` contains a map with non-string keys.
280 ///
281 /// ```
282 /// use std::collections::BTreeMap;
283 ///
284 /// // The keys in this map are vectors, not strings.
285 /// let mut map = BTreeMap::new();
286 /// map.insert(vec![32, 64], "x86");
287 ///
288 /// println!("{}", serde_json::value::to_raw_value(&map).unwrap_err());
289 /// ```
290 #[cfg_attr(docsrs, doc(cfg(feature = "raw_value")))]
291 pub fn to_raw_value<T>(value: &T) -> Result<Box<RawValue>, Error>
292 where
293 T: ?Sized + Serialize,
294 {
295 let json_string = tri!(crate::to_string(value));
296 Ok(RawValue::from_owned(json_string.into_boxed_str()))
297 }
298
299 pub const TOKEN: &str = "$serde_json::private::RawValue";
300
301 impl Serialize for RawValue {
302 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
303 where
304 S: Serializer,
305 {
306 let mut s = tri!(serializer.serialize_struct(TOKEN, 1));
307 tri!(s.serialize_field(TOKEN, &self.json));
308 s.end()
309 }
310 }
311
312 impl<'de: 'a, 'a> Deserialize<'de> for &'a RawValue {
313 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
314 where
315 D: Deserializer<'de>,
316 {
317 struct ReferenceVisitor;
318
319 impl<'de> Visitor<'de> for ReferenceVisitor {
320 type Value = &'de RawValue;
321
322 fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
323 write!(formatter, "any valid JSON value")
324 }
325
326 fn visit_map<V>(self, mut visitor: V) -> Result<Self::Value, V::Error>
327 where
328 V: MapAccess<'de>,
329 {
330 let value = tri!(visitor.next_key::<RawKey>());
331 if value.is_none() {
332 return Err(de::Error::invalid_type(Unexpected::Map, &self));
333 }
334 visitor.next_value_seed(ReferenceFromString)
335 }
336 }
337
338 deserializer.deserialize_newtype_struct(TOKEN, ReferenceVisitor)
339 }
340 }
341
342 impl<'de> Deserialize<'de> for Box<RawValue> {
343 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
344 where
345 D: Deserializer<'de>,
346 {
347 struct BoxedVisitor;
348
349 impl<'de> Visitor<'de> for BoxedVisitor {
350 type Value = Box<RawValue>;
351
352 fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
353 write!(formatter, "any valid JSON value")
354 }
355
356 fn visit_map<V>(self, mut visitor: V) -> Result<Self::Value, V::Error>
357 where
358 V: MapAccess<'de>,
359 {
360 let value = tri!(visitor.next_key::<RawKey>());
361 if value.is_none() {
362 return Err(de::Error::invalid_type(Unexpected::Map, &self));
363 }
364 visitor.next_value_seed(BoxedFromString)
365 }
366 }
367
368 deserializer.deserialize_newtype_struct(TOKEN, BoxedVisitor)
369 }
370 }
371
372 struct RawKey;
373
374 impl<'de> Deserialize<'de> for RawKey {
375 fn deserialize<D>(deserializer: D) -> Result<RawKey, D::Error>
376 where
377 D: Deserializer<'de>,
378 {
379 struct FieldVisitor;
380
381 impl<'de> Visitor<'de> for FieldVisitor {
382 type Value = ();
383
384 fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
385 formatter.write_str("raw value")
386 }
387
388 fn visit_str<E>(self, s: &str) -> Result<(), E>
389 where
390 E: de::Error,
391 {
392 if s == TOKEN {
393 Ok(())
394 } else {
395 Err(de::Error::custom("unexpected raw value"))
396 }
397 }
398 }
399
400 tri!(deserializer.deserialize_identifier(FieldVisitor));
401 Ok(RawKey)
402 }
403 }
404
405 pub struct ReferenceFromString;
406
407 impl<'de> DeserializeSeed<'de> for ReferenceFromString {
408 type Value = &'de RawValue;
409
410 fn deserialize<D>(self, deserializer: D) -> Result<Self::Value, D::Error>
411 where
412 D: Deserializer<'de>,
413 {
414 deserializer.deserialize_str(self)
415 }
416 }
417
418 impl<'de> Visitor<'de> for ReferenceFromString {
419 type Value = &'de RawValue;
420
421 fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
422 formatter.write_str("raw value")
423 }
424
425 fn visit_borrowed_str<E>(self, s: &'de str) -> Result<Self::Value, E>
426 where
427 E: de::Error,
428 {
429 Ok(RawValue::from_borrowed(s))
430 }
431 }
432
433 pub struct BoxedFromString;
434
435 impl<'de> DeserializeSeed<'de> for BoxedFromString {
436 type Value = Box<RawValue>;
437
438 fn deserialize<D>(self, deserializer: D) -> Result<Self::Value, D::Error>
439 where
440 D: Deserializer<'de>,
441 {
442 deserializer.deserialize_str(self)
443 }
444 }
445
446 impl<'de> Visitor<'de> for BoxedFromString {
447 type Value = Box<RawValue>;
448
449 fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
450 formatter.write_str("raw value")
451 }
452
453 fn visit_str<E>(self, s: &str) -> Result<Self::Value, E>
454 where
455 E: de::Error,
456 {
457 Ok(RawValue::from_owned(s.to_owned().into_boxed_str()))
458 }
459
460 #[cfg(any(feature = "std", feature = "alloc"))]
461 fn visit_string<E>(self, s: String) -> Result<Self::Value, E>
462 where
463 E: de::Error,
464 {
465 Ok(RawValue::from_owned(s.into_boxed_str()))
466 }
467 }
468
469 struct RawKeyDeserializer;
470
471 impl<'de> Deserializer<'de> for RawKeyDeserializer {
472 type Error = Error;
473
474 fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Error>
475 where
476 V: de::Visitor<'de>,
477 {
478 visitor.visit_borrowed_str(TOKEN)
479 }
480
481 forward_to_deserialize_any! {
482 bool u8 u16 u32 u64 u128 i8 i16 i32 i64 i128 f32 f64 char str string seq
483 bytes byte_buf map struct option unit newtype_struct ignored_any
484 unit_struct tuple_struct tuple enum identifier
485 }
486 }
487
488 pub struct OwnedRawDeserializer {
489 pub raw_value: Option<String>,
490 }
491
492 impl<'de> MapAccess<'de> for OwnedRawDeserializer {
493 type Error = Error;
494
495 fn next_key_seed<K>(&mut self, seed: K) -> Result<Option<K::Value>, Error>
496 where
497 K: de::DeserializeSeed<'de>,
498 {
499 if self.raw_value.is_none() {
500 return Ok(None);
501 }
502 seed.deserialize(RawKeyDeserializer).map(Some)
503 }
504
505 fn next_value_seed<V>(&mut self, seed: V) -> Result<V::Value, Error>
506 where
507 V: de::DeserializeSeed<'de>,
508 {
509 seed.deserialize(self.raw_value.take().unwrap().into_deserializer())
510 }
511 }
512
513 pub struct BorrowedRawDeserializer<'de> {
514 pub raw_value: Option<&'de str>,
515 }
516
517 impl<'de> MapAccess<'de> for BorrowedRawDeserializer<'de> {
518 type Error = Error;
519
520 fn next_key_seed<K>(&mut self, seed: K) -> Result<Option<K::Value>, Error>
521 where
522 K: de::DeserializeSeed<'de>,
523 {
524 if self.raw_value.is_none() {
525 return Ok(None);
526 }
527 seed.deserialize(RawKeyDeserializer).map(Some)
528 }
529
530 fn next_value_seed<V>(&mut self, seed: V) -> Result<V::Value, Error>
531 where
532 V: de::DeserializeSeed<'de>,
533 {
534 seed.deserialize(BorrowedStrDeserializer::new(self.raw_value.take().unwrap()))
535 }
536 }
537
538 impl<'de> IntoDeserializer<'de, Error> for &'de RawValue {
539 type Deserializer = &'de RawValue;
540
541 fn into_deserializer(self) -> Self::Deserializer {
542 self
543 }
544 }
545
546 impl<'de> Deserializer<'de> for &'de RawValue {
547 type Error = Error;
548
549 fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Error>
550 where
551 V: Visitor<'de>,
552 {
553 crate::Deserializer::from_str(&self.json).deserialize_any(visitor)
554 }
555
556 fn deserialize_bool<V>(self, visitor: V) -> Result<V::Value, Error>
557 where
558 V: Visitor<'de>,
559 {
560 crate::Deserializer::from_str(&self.json).deserialize_bool(visitor)
561 }
562
563 fn deserialize_i8<V>(self, visitor: V) -> Result<V::Value, Error>
564 where
565 V: Visitor<'de>,
566 {
567 crate::Deserializer::from_str(&self.json).deserialize_i8(visitor)
568 }
569
570 fn deserialize_i16<V>(self, visitor: V) -> Result<V::Value, Error>
571 where
572 V: Visitor<'de>,
573 {
574 crate::Deserializer::from_str(&self.json).deserialize_i16(visitor)
575 }
576
577 fn deserialize_i32<V>(self, visitor: V) -> Result<V::Value, Error>
578 where
579 V: Visitor<'de>,
580 {
581 crate::Deserializer::from_str(&self.json).deserialize_i32(visitor)
582 }
583
584 fn deserialize_i64<V>(self, visitor: V) -> Result<V::Value, Error>
585 where
586 V: Visitor<'de>,
587 {
588 crate::Deserializer::from_str(&self.json).deserialize_i64(visitor)
589 }
590
591 fn deserialize_i128<V>(self, visitor: V) -> Result<V::Value, Error>
592 where
593 V: Visitor<'de>,
594 {
595 crate::Deserializer::from_str(&self.json).deserialize_i128(visitor)
596 }
597
598 fn deserialize_u8<V>(self, visitor: V) -> Result<V::Value, Error>
599 where
600 V: Visitor<'de>,
601 {
602 crate::Deserializer::from_str(&self.json).deserialize_u8(visitor)
603 }
604
605 fn deserialize_u16<V>(self, visitor: V) -> Result<V::Value, Error>
606 where
607 V: Visitor<'de>,
608 {
609 crate::Deserializer::from_str(&self.json).deserialize_u16(visitor)
610 }
611
612 fn deserialize_u32<V>(self, visitor: V) -> Result<V::Value, Error>
613 where
614 V: Visitor<'de>,
615 {
616 crate::Deserializer::from_str(&self.json).deserialize_u32(visitor)
617 }
618
619 fn deserialize_u64<V>(self, visitor: V) -> Result<V::Value, Error>
620 where
621 V: Visitor<'de>,
622 {
623 crate::Deserializer::from_str(&self.json).deserialize_u64(visitor)
624 }
625
626 fn deserialize_u128<V>(self, visitor: V) -> Result<V::Value, Error>
627 where
628 V: Visitor<'de>,
629 {
630 crate::Deserializer::from_str(&self.json).deserialize_u128(visitor)
631 }
632
633 fn deserialize_f32<V>(self, visitor: V) -> Result<V::Value, Error>
634 where
635 V: Visitor<'de>,
636 {
637 crate::Deserializer::from_str(&self.json).deserialize_f32(visitor)
638 }
639
640 fn deserialize_f64<V>(self, visitor: V) -> Result<V::Value, Error>
641 where
642 V: Visitor<'de>,
643 {
644 crate::Deserializer::from_str(&self.json).deserialize_f64(visitor)
645 }
646
647 fn deserialize_char<V>(self, visitor: V) -> Result<V::Value, Error>
648 where
649 V: Visitor<'de>,
650 {
651 crate::Deserializer::from_str(&self.json).deserialize_char(visitor)
652 }
653
654 fn deserialize_str<V>(self, visitor: V) -> Result<V::Value, Error>
655 where
656 V: Visitor<'de>,
657 {
658 crate::Deserializer::from_str(&self.json).deserialize_str(visitor)
659 }
660
661 fn deserialize_string<V>(self, visitor: V) -> Result<V::Value, Error>
662 where
663 V: Visitor<'de>,
664 {
665 crate::Deserializer::from_str(&self.json).deserialize_string(visitor)
666 }
667
668 fn deserialize_bytes<V>(self, visitor: V) -> Result<V::Value, Error>
669 where
670 V: Visitor<'de>,
671 {
672 crate::Deserializer::from_str(&self.json).deserialize_bytes(visitor)
673 }
674
675 fn deserialize_byte_buf<V>(self, visitor: V) -> Result<V::Value, Error>
676 where
677 V: Visitor<'de>,
678 {
679 crate::Deserializer::from_str(&self.json).deserialize_byte_buf(visitor)
680 }
681
682 fn deserialize_option<V>(self, visitor: V) -> Result<V::Value, Error>
683 where
684 V: Visitor<'de>,
685 {
686 crate::Deserializer::from_str(&self.json).deserialize_option(visitor)
687 }
688
689 fn deserialize_unit<V>(self, visitor: V) -> Result<V::Value, Error>
690 where
691 V: Visitor<'de>,
692 {
693 crate::Deserializer::from_str(&self.json).deserialize_unit(visitor)
694 }
695
696 fn deserialize_unit_struct<V>(self, name: &'static str, visitor: V) -> Result<V::Value, Error>
697 where
698 V: Visitor<'de>,
699 {
700 crate::Deserializer::from_str(&self.json).deserialize_unit_struct(name, visitor)
701 }
702
703 fn deserialize_newtype_struct<V>(
704 self,
705 name: &'static str,
706 visitor: V,
707 ) -> Result<V::Value, Error>
708 where
709 V: Visitor<'de>,
710 {
711 crate::Deserializer::from_str(&self.json).deserialize_newtype_struct(name, visitor)
712 }
713
714 fn deserialize_seq<V>(self, visitor: V) -> Result<V::Value, Error>
715 where
716 V: Visitor<'de>,
717 {
718 crate::Deserializer::from_str(&self.json).deserialize_seq(visitor)
719 }
720
721 fn deserialize_tuple<V>(self, len: usize, visitor: V) -> Result<V::Value, Error>
722 where
723 V: Visitor<'de>,
724 {
725 crate::Deserializer::from_str(&self.json).deserialize_tuple(len, visitor)
726 }
727
728 fn deserialize_tuple_struct<V>(
729 self,
730 name: &'static str,
731 len: usize,
732 visitor: V,
733 ) -> Result<V::Value, Error>
734 where
735 V: Visitor<'de>,
736 {
737 crate::Deserializer::from_str(&self.json).deserialize_tuple_struct(name, len, visitor)
738 }
739
740 fn deserialize_map<V>(self, visitor: V) -> Result<V::Value, Error>
741 where
742 V: Visitor<'de>,
743 {
744 crate::Deserializer::from_str(&self.json).deserialize_map(visitor)
745 }
746
747 fn deserialize_struct<V>(
748 self,
749 name: &'static str,
750 fields: &'static [&'static str],
751 visitor: V,
752 ) -> Result<V::Value, Error>
753 where
754 V: Visitor<'de>,
755 {
756 crate::Deserializer::from_str(&self.json).deserialize_struct(name, fields, visitor)
757 }
758
759 fn deserialize_enum<V>(
760 self,
761 name: &'static str,
762 variants: &'static [&'static str],
763 visitor: V,
764 ) -> Result<V::Value, Error>
765 where
766 V: Visitor<'de>,
767 {
768 crate::Deserializer::from_str(&self.json).deserialize_enum(name, variants, visitor)
769 }
770
771 fn deserialize_identifier<V>(self, visitor: V) -> Result<V::Value, Error>
772 where
773 V: Visitor<'de>,
774 {
775 crate::Deserializer::from_str(&self.json).deserialize_identifier(visitor)
776 }
777
778 fn deserialize_ignored_any<V>(self, visitor: V) -> Result<V::Value, Error>
779 where
780 V: Visitor<'de>,
781 {
782 crate::Deserializer::from_str(&self.json).deserialize_ignored_any(visitor)
783 }
784 }