Skip to main content

zvariant/dbus/
de.rs

1use serde::de::{self, DeserializeSeed, EnumAccess, MapAccess, SeqAccess, Visitor};
2
3use std::{marker::PhantomData, str};
4
5#[cfg(unix)]
6use std::os::fd::AsFd;
7
8use crate::{
9    Basic, Error, ObjectPath, Result, Signature,
10    de::{DeserializerCommon, ValueParseStage},
11    serialized::{Context, Format},
12    utils::*,
13};
14
15/// Our D-Bus deserialization implementation.
16#[derive(Debug)]
17pub(crate) struct Deserializer<'de, 'sig, 'f, F>(pub(crate) DeserializerCommon<'de, 'sig, 'f, F>);
18
19#[allow(clippy::needless_lifetimes)]
20impl<'de, 'sig, 'f, F> Deserializer<'de, 'sig, 'f, F> {
21    /// Create a Deserializer struct instance.
22    ///
23    /// On Windows, there is no `fds` argument.
24    pub fn new<'r: 'de>(
25        bytes: &'r [u8],
26        #[cfg(unix)] fds: Option<&'f [F]>,
27        signature: &'sig Signature,
28        ctxt: Context,
29    ) -> Result<Self> {
30        assert_eq!(ctxt.format(), Format::DBus);
31        super::reject_maybe(signature)?;
32
33        Ok(Self(DeserializerCommon {
34            ctxt,
35            signature,
36            bytes,
37            #[cfg(unix)]
38            fds,
39            #[cfg(not(unix))]
40            fds: PhantomData,
41            pos: 0,
42            container_depths: Default::default(),
43        }))
44    }
45}
46
47macro_rules! deserialize_basic {
48    ($method:ident $read_method:ident $visitor_method:ident($type:ty)) => {
49        fn $method<V>(self, visitor: V) -> Result<V::Value>
50        where
51            V: Visitor<'de>,
52        {
53            let v = self
54                .0
55                .ctxt
56                .endian()
57                .$read_method(self.0.next_const_size_slice::<$type>()?);
58
59            visitor.$visitor_method(v)
60        }
61    };
62}
63
64macro_rules! deserialize_as {
65    ($method:ident => $as:ident) => {
66        deserialize_as!($method() => $as());
67    };
68    ($method:ident($($in_arg:ident: $type:ty),*) => $as:ident($($as_arg:expr),*)) => {
69        #[inline]
70        fn $method<V>(self, $($in_arg: $type,)* visitor: V) -> Result<V::Value>
71        where
72            V: Visitor<'de>,
73        {
74            self.$as($($as_arg,)* visitor)
75        }
76    }
77}
78
79impl<'de, #[cfg(unix)] F: AsFd, #[cfg(not(unix))] F> de::Deserializer<'de>
80    for &mut Deserializer<'de, '_, '_, F>
81{
82    type Error = Error;
83
84    fn deserialize_any<V>(self, visitor: V) -> Result<V::Value>
85    where
86        V: Visitor<'de>,
87    {
88        crate::de::deserialize_any::<Self, V>(self, self.0.signature, visitor)
89    }
90
91    fn deserialize_bool<V>(self, visitor: V) -> Result<V::Value>
92    where
93        V: Visitor<'de>,
94    {
95        let v = self
96            .0
97            .ctxt
98            .endian()
99            .read_u32(self.0.next_const_size_slice::<bool>()?);
100        let b = match v {
101            1 => true,
102            0 => false,
103            // As per D-Bus spec, only 0 and 1 values are allowed
104            _ => {
105                return Err(de::Error::invalid_value(
106                    de::Unexpected::Unsigned(v as u64),
107                    &"0 or 1",
108                ));
109            }
110        };
111
112        visitor.visit_bool(b)
113    }
114
115    fn deserialize_i8<V>(self, visitor: V) -> Result<V::Value>
116    where
117        V: Visitor<'de>,
118    {
119        self.deserialize_i16(visitor)
120    }
121
122    deserialize_basic!(deserialize_i16 read_i16 visit_i16(i16));
123    deserialize_basic!(deserialize_i64 read_i64 visit_i64(i64));
124    deserialize_basic!(deserialize_u16 read_u16 visit_u16(u16));
125    deserialize_basic!(deserialize_u32 read_u32 visit_u32(u32));
126    deserialize_basic!(deserialize_u64 read_u64 visit_u64(u64));
127    deserialize_basic!(deserialize_f64 read_f64 visit_f64(f64));
128
129    fn deserialize_byte_buf<V>(self, visitor: V) -> Result<V::Value>
130    where
131        V: Visitor<'de>,
132    {
133        let bytes = deserialize_ay(self)?;
134        visitor.visit_byte_buf(bytes.into())
135    }
136
137    fn deserialize_bytes<V>(self, visitor: V) -> Result<V::Value>
138    where
139        V: Visitor<'de>,
140    {
141        let bytes = deserialize_ay(self)?;
142        visitor.visit_borrowed_bytes(bytes)
143    }
144
145    deserialize_as!(deserialize_char => deserialize_str);
146    deserialize_as!(deserialize_string => deserialize_str);
147    deserialize_as!(deserialize_tuple(_l: usize) => deserialize_struct("", &[]));
148    deserialize_as!(deserialize_tuple_struct(n: &'static str, _l: usize) => deserialize_struct(n, &[]));
149    deserialize_as!(deserialize_struct(_n: &'static str, _f: &'static [&'static str]) => deserialize_seq());
150    deserialize_as!(deserialize_map => deserialize_seq);
151    deserialize_as!(deserialize_ignored_any => deserialize_any);
152
153    fn deserialize_i32<V>(self, visitor: V) -> Result<V::Value>
154    where
155        V: Visitor<'de>,
156    {
157        let v = match &self.0.signature {
158            #[cfg(unix)]
159            Signature::Fd => {
160                let alignment = u32::alignment(Format::DBus);
161                self.0.parse_padding(alignment)?;
162                let idx = self.0.ctxt.endian().read_u32(self.0.next_slice(alignment)?);
163                self.0.get_fd(idx)?
164            }
165            _ => self
166                .0
167                .ctxt
168                .endian()
169                .read_i32(self.0.next_const_size_slice::<i32>()?),
170        };
171
172        visitor.visit_i32(v)
173    }
174
175    fn deserialize_u8<V>(self, visitor: V) -> Result<V::Value>
176    where
177        V: Visitor<'de>,
178    {
179        // Endianness is irrelevant for single bytes.
180        visitor.visit_u8(self.0.next_const_size_slice::<u8>().map(|bytes| bytes[0])?)
181    }
182
183    fn deserialize_f32<V>(self, visitor: V) -> Result<V::Value>
184    where
185        V: Visitor<'de>,
186    {
187        let v = self
188            .0
189            .ctxt
190            .endian()
191            .read_f64(self.0.next_const_size_slice::<f64>()?);
192
193        if v.is_finite() && v > (f32::MAX as f64) {
194            return Err(de::Error::invalid_value(
195                de::Unexpected::Float(v),
196                &"Too large for f32",
197            ));
198        }
199        visitor.visit_f32(v as f32)
200    }
201
202    fn deserialize_str<V>(self, visitor: V) -> Result<V::Value>
203    where
204        V: Visitor<'de>,
205    {
206        let len = match self.0.signature {
207            Signature::Signature | Signature::Variant => {
208                let len_slice = self.0.next_slice(1)?;
209
210                len_slice[0] as usize
211            }
212            Signature::Str | Signature::ObjectPath => {
213                let alignment = u32::alignment(Format::DBus);
214                self.0.parse_padding(alignment)?;
215                let len_slice = self.0.next_slice(alignment)?;
216
217                self.0.ctxt.endian().read_u32(len_slice) as usize
218            }
219            _ => {
220                let expected = format!(
221                    "`{}`, `{}`, `{}` or `{}`",
222                    <&str>::SIGNATURE_STR,
223                    Signature::SIGNATURE_STR,
224                    ObjectPath::SIGNATURE_STR,
225                    VARIANT_SIGNATURE_CHAR,
226                );
227                return Err(Error::SignatureMismatch(self.0.signature.clone(), expected));
228            }
229        };
230        let slice = self.0.next_slice(len)?;
231        if slice.contains(&0) {
232            return Err(serde::de::Error::invalid_value(
233                serde::de::Unexpected::Char('\0'),
234                &"D-Bus string type must not contain interior null bytes",
235            ));
236        }
237        self.0.pos += 1; // skip trailing null byte
238        let s = str::from_utf8(slice).map_err(Error::Utf8)?;
239
240        // A `g` or `v` value carries a signature; a maybe type in it is not valid D-Bus.
241        if matches!(self.0.signature, Signature::Signature | Signature::Variant) {
242            super::reject_maybe_in_signature_str(slice)?;
243        }
244
245        visitor.visit_borrowed_str(s)
246    }
247
248    fn deserialize_option<V>(self, #[allow(unused)] visitor: V) -> Result<V::Value>
249    where
250        V: Visitor<'de>,
251    {
252        #[cfg(feature = "option-as-array")]
253        {
254            // This takes care of parsing all the padding and getting the byte length.
255            let ad = ArrayDeserializer::new(self)?;
256            let len = ad.len;
257            let array_signature = ad.array_signature;
258
259            let v = if len == 0 {
260                visitor.visit_none()
261            } else {
262                visitor.visit_some(&mut *self)
263            };
264            self.0.container_depths = self.0.container_depths.dec_array();
265            self.0.signature = array_signature;
266
267            v
268        }
269
270        #[cfg(not(feature = "option-as-array"))]
271        Err(de::Error::custom(
272            "Can only decode Option<T> from D-Bus format if `option-as-array` feature is enabled",
273        ))
274    }
275
276    fn deserialize_unit<V>(self, visitor: V) -> Result<V::Value>
277    where
278        V: Visitor<'de>,
279    {
280        visitor.visit_unit()
281    }
282
283    fn deserialize_unit_struct<V>(self, _name: &'static str, visitor: V) -> Result<V::Value>
284    where
285        V: Visitor<'de>,
286    {
287        visitor.visit_unit()
288    }
289
290    fn deserialize_newtype_struct<V>(self, _name: &'static str, visitor: V) -> Result<V::Value>
291    where
292        V: Visitor<'de>,
293    {
294        visitor.visit_newtype_struct(self)
295    }
296
297    fn deserialize_seq<V>(self, visitor: V) -> Result<V::Value>
298    where
299        V: Visitor<'de>,
300    {
301        let alignment = self.0.signature.alignment(Format::DBus);
302        self.0.parse_padding(alignment)?;
303
304        match self.0.signature {
305            Signature::Variant => {
306                let value_de = ValueDeserializer::new(self);
307
308                visitor.visit_seq(value_de)
309            }
310            Signature::Array(_) => {
311                let array_de = ArrayDeserializer::new(self)?;
312                visitor.visit_seq(ArraySeqDeserializer(array_de))
313            }
314            Signature::Dict { .. } => visitor.visit_map(ArrayMapDeserializer::new(self)?),
315            Signature::Structure(_) => visitor.visit_seq(StructureDeserializer::new(self)?),
316            Signature::U8 => {
317                // Empty struct: encoded as a `0u8`.
318                let _: u8 = serde::Deserialize::deserialize(&mut *self)?;
319
320                visitor.visit_seq(StructureDeserializer {
321                    de: self,
322                    field_idx: 0,
323                    num_fields: 0,
324                })
325            }
326            _ => Err(Error::SignatureMismatch(
327                self.0.signature.clone(),
328                "a variant, array, dict, structure or u8".to_string(),
329            )),
330        }
331    }
332
333    fn deserialize_enum<V>(
334        self,
335        name: &'static str,
336        _variants: &'static [&'static str],
337        visitor: V,
338    ) -> Result<V::Value>
339    where
340        V: Visitor<'de>,
341    {
342        let alignment = self.0.signature.alignment(self.0.ctxt.format());
343        self.0.parse_padding(alignment)?;
344
345        visitor.visit_enum(crate::de::Enum {
346            de: self,
347            name,
348            _phantom: PhantomData,
349        })
350    }
351
352    fn deserialize_identifier<V>(self, visitor: V) -> Result<V::Value>
353    where
354        V: Visitor<'de>,
355    {
356        match self.0.signature {
357            Signature::Str | Signature::ObjectPath | Signature::Signature => {
358                self.deserialize_str(visitor)
359            }
360            Signature::U32 => self.deserialize_u32(visitor),
361            Signature::Structure(fields) => {
362                let mut fields = fields.iter();
363                let index_signature = fields.next().ok_or_else(|| {
364                    Error::SignatureMismatch(
365                        self.0.signature.clone(),
366                        "a structure with 2 fields and u32 as its first field".to_string(),
367                    )
368                })?;
369                self.0.signature = index_signature;
370                let v = self.deserialize_u32(visitor);
371
372                self.0.signature = fields.next().ok_or_else(|| {
373                    Error::SignatureMismatch(
374                        self.0.signature.clone(),
375                        "a structure with 2 fields and u32 as its first field".to_string(),
376                    )
377                })?;
378
379                v
380            }
381            _ => Err(Error::SignatureMismatch(
382                self.0.signature.clone(),
383                "a string, object path or signature".to_string(),
384            )),
385        }
386    }
387
388    fn is_human_readable(&self) -> bool {
389        false
390    }
391}
392
393struct ArrayDeserializer<'d, 'de, 'sig, 'f, F> {
394    de: &'d mut Deserializer<'de, 'sig, 'f, F>,
395    len: usize,
396    start: usize,
397    // alignment of element
398    element_alignment: usize,
399    array_signature: &'sig Signature,
400}
401
402impl<'d, 'de, 'sig, 'f, #[cfg(unix)] F: AsFd, #[cfg(not(unix))] F>
403    ArrayDeserializer<'d, 'de, 'sig, 'f, F>
404{
405    fn new(de: &'d mut Deserializer<'de, 'sig, 'f, F>) -> Result<Self> {
406        de.0.parse_padding(ARRAY_ALIGNMENT_DBUS)?;
407        de.0.container_depths = de.0.container_depths.inc_array()?;
408
409        let len = de.0.ctxt.endian().read_u32(de.0.next_slice(4)?) as usize;
410
411        // D-Bus expects us to add padding for the first element even when there is no first
412        // element (i-e empty array) so we parse padding already.
413        let (element_alignment, child_signature) = match de.0.signature {
414            Signature::Array(child) => (child.alignment(de.0.ctxt.format()), child.signature()),
415            Signature::Dict { key, .. } => (DICT_ENTRY_ALIGNMENT_DBUS, key.signature()),
416            _ => {
417                return Err(Error::SignatureMismatch(
418                    de.0.signature.clone(),
419                    "an array or dict".to_string(),
420                ));
421            }
422        };
423        de.0.parse_padding(element_alignment)?;
424
425        // In case of an array, we'll only be serializing the array's child elements from now on and
426        // in case of a dict, we'll swap key and value signatures during serlization of each entry,
427        // so let's assume the element signature for array and key signature for dict, from now on.
428        // We restore the original signature at the end of deserialization.
429        let array_signature = de.0.signature;
430        de.0.signature = child_signature;
431        let start = de.0.pos;
432
433        Ok(Self {
434            de,
435            len,
436            start,
437            element_alignment,
438            array_signature,
439        })
440    }
441
442    fn next<T>(&mut self, seed: T) -> Result<T::Value>
443    where
444        T: DeserializeSeed<'de>,
445    {
446        let v = seed.deserialize(&mut *self.de);
447
448        if self.de.0.pos > self.start + self.len {
449            return Err(serde::de::Error::invalid_length(
450                self.len,
451                &format!(">= {}", self.de.0.pos - self.start).as_str(),
452            ));
453        }
454
455        v
456    }
457
458    fn next_element<T>(&mut self, seed: T) -> Result<Option<T::Value>>
459    where
460        T: DeserializeSeed<'de>,
461    {
462        if self.done() {
463            self.end();
464
465            return Ok(None);
466        }
467        // Redundant for normal arrays but dict requires each entry to be padded by 8 bytes.
468        self.de.0.parse_padding(self.element_alignment)?;
469
470        self.next(seed).map(Some)
471    }
472
473    fn done(&self) -> bool {
474        self.de.0.pos == self.start + self.len
475    }
476
477    fn end(&mut self) {
478        self.de.0.container_depths = self.de.0.container_depths.dec_array();
479        self.de.0.signature = self.array_signature;
480    }
481}
482
483fn deserialize_ay<'de, #[cfg(unix)] F: AsFd, #[cfg(not(unix))] F>(
484    de: &mut Deserializer<'de, '_, '_, F>,
485) -> Result<&'de [u8]> {
486    if !matches!(de.0.signature, Signature::Array(child) if child.signature() == &Signature::U8) {
487        return Err(de::Error::invalid_type(de::Unexpected::Seq, &"ay"));
488    }
489
490    let mut ad = ArrayDeserializer::new(de)?;
491    let len = ad.len;
492    ad.end();
493
494    de.0.next_slice(len)
495}
496
497struct ArraySeqDeserializer<'d, 'de, 'sig, 'f, F>(ArrayDeserializer<'d, 'de, 'sig, 'f, F>);
498
499impl<'de, #[cfg(unix)] F: AsFd, #[cfg(not(unix))] F> SeqAccess<'de>
500    for ArraySeqDeserializer<'_, 'de, '_, '_, F>
501{
502    type Error = Error;
503
504    fn next_element_seed<T>(&mut self, seed: T) -> Result<Option<T::Value>>
505    where
506        T: DeserializeSeed<'de>,
507    {
508        self.0.next_element(seed)
509    }
510}
511
512struct ArrayMapDeserializer<'d, 'de, 'sig, 'f, F> {
513    ad: ArrayDeserializer<'d, 'de, 'sig, 'f, F>,
514    key_signature: &'sig Signature,
515    value_signature: &'sig Signature,
516}
517impl<'d, 'de, 'sig, 'f, #[cfg(unix)] F: AsFd, #[cfg(not(unix))] F>
518    ArrayMapDeserializer<'d, 'de, 'sig, 'f, F>
519{
520    fn new(de: &'d mut Deserializer<'de, 'sig, 'f, F>) -> Result<Self> {
521        let (key_signature, value_signature) = match de.0.signature {
522            Signature::Dict { key, value } => (key.signature(), value.signature()),
523            _ => {
524                return Err(Error::SignatureMismatch(
525                    de.0.signature.clone(),
526                    "a dict".to_string(),
527                ));
528            }
529        };
530        let ad = ArrayDeserializer::new(de)?;
531
532        Ok(Self {
533            ad,
534            key_signature,
535            value_signature,
536        })
537    }
538}
539
540impl<'de, #[cfg(unix)] F: AsFd, #[cfg(not(unix))] F> MapAccess<'de>
541    for ArrayMapDeserializer<'_, 'de, '_, '_, F>
542{
543    type Error = Error;
544
545    fn next_key_seed<K>(&mut self, seed: K) -> Result<Option<K::Value>>
546    where
547        K: DeserializeSeed<'de>,
548    {
549        self.ad.next_element(seed)
550    }
551
552    fn next_value_seed<V>(&mut self, seed: V) -> Result<V::Value>
553    where
554        V: DeserializeSeed<'de>,
555    {
556        self.ad.de.0.signature = self.value_signature;
557        let v = self.ad.next(seed);
558        self.ad.de.0.signature = self.key_signature;
559
560        v
561    }
562}
563
564#[derive(Debug)]
565struct StructureDeserializer<'d, 'de, 'sig, 'f, F> {
566    de: &'d mut Deserializer<'de, 'sig, 'f, F>,
567    /// Index of the next field to serialize.
568    field_idx: usize,
569    /// The number of fields in the structure.
570    num_fields: usize,
571}
572
573impl<'d, 'de, 'sig, 'f, #[cfg(unix)] F: AsFd, #[cfg(not(unix))] F>
574    StructureDeserializer<'d, 'de, 'sig, 'f, F>
575{
576    fn new(de: &'d mut Deserializer<'de, 'sig, 'f, F>) -> Result<Self> {
577        let num_fields = match de.0.signature {
578            Signature::Structure(fields) => fields.iter().count(),
579            _ => unreachable!("Incorrect signature for struct"),
580        };
581        de.0.parse_padding(STRUCT_ALIGNMENT_DBUS)?;
582        de.0.container_depths = de.0.container_depths.inc_structure()?;
583
584        Ok(Self {
585            de,
586            field_idx: 0,
587            num_fields,
588        })
589    }
590}
591
592impl<'de, #[cfg(unix)] F: AsFd, #[cfg(not(unix))] F> SeqAccess<'de>
593    for StructureDeserializer<'_, 'de, '_, '_, F>
594{
595    type Error = Error;
596
597    fn next_element_seed<T>(&mut self, seed: T) -> Result<Option<T::Value>>
598    where
599        T: DeserializeSeed<'de>,
600    {
601        if self.field_idx == self.num_fields {
602            return Ok(None);
603        }
604
605        let signature = self.de.0.signature;
606        let field_signature = match signature {
607            Signature::Structure(fields) => {
608                let signature = fields.get(self.field_idx).ok_or_else(|| {
609                    Error::SignatureMismatch(signature.clone(), "a struct".to_string())
610                })?;
611                self.field_idx += 1;
612
613                signature
614            }
615            _ => unreachable!("Incorrect signature for struct"),
616        };
617
618        let mut de = Deserializer::<F>(DeserializerCommon {
619            ctxt: self.de.0.ctxt,
620            signature: field_signature,
621            fds: self.de.0.fds,
622            bytes: self.de.0.bytes,
623            pos: self.de.0.pos,
624            container_depths: self.de.0.container_depths,
625        });
626        let v = seed.deserialize(&mut de)?;
627        self.de.0.pos = de.0.pos;
628
629        if self.field_idx == self.num_fields {
630            // All fields have been deserialized.
631            self.de.0.container_depths = self.de.0.container_depths.dec_structure();
632        }
633
634        Ok(Some(v))
635    }
636}
637
638#[derive(Debug)]
639struct ValueDeserializer<'d, 'de, 'sig, 'f, F> {
640    de: &'d mut Deserializer<'de, 'sig, 'f, F>,
641    stage: ValueParseStage,
642    sig_start: usize,
643}
644
645impl<'d, 'de, 'sig, 'f, #[cfg(unix)] F: AsFd, #[cfg(not(unix))] F>
646    ValueDeserializer<'d, 'de, 'sig, 'f, F>
647{
648    fn new(de: &'d mut Deserializer<'de, 'sig, 'f, F>) -> Self {
649        let sig_start = de.0.pos;
650        ValueDeserializer::<F> {
651            de,
652            stage: ValueParseStage::Signature,
653            sig_start,
654        }
655    }
656}
657
658impl<'de, #[cfg(unix)] F: AsFd, #[cfg(not(unix))] F> SeqAccess<'de>
659    for ValueDeserializer<'_, 'de, '_, '_, F>
660{
661    type Error = Error;
662
663    fn next_element_seed<T>(&mut self, seed: T) -> Result<Option<T::Value>>
664    where
665        T: DeserializeSeed<'de>,
666    {
667        match self.stage {
668            ValueParseStage::Signature => {
669                self.stage = ValueParseStage::Value;
670
671                let signature = self.de.0.signature;
672                self.de.0.signature = &Signature::Signature;
673                let ret = seed.deserialize(&mut *self.de).map(Some);
674                self.de.0.signature = signature;
675
676                ret
677            }
678            ValueParseStage::Value => {
679                self.stage = ValueParseStage::Done;
680
681                let sig_len = self.de.0.bytes[self.sig_start] as usize;
682                // skip length byte
683                let sig_start = self.sig_start + 1;
684                let sig_end = sig_start + sig_len;
685                // Skip trailing nul byte
686                let value_start = sig_end + 1;
687
688                let slice = subslice(self.de.0.bytes, sig_start..sig_end)?;
689                let signature = Signature::from_bytes(slice)?;
690                super::reject_maybe(&signature)?;
691
692                let ctxt = Context::new(
693                    Format::DBus,
694                    self.de.0.ctxt.endian(),
695                    self.de.0.ctxt.position() + value_start,
696                );
697                let mut de = Deserializer::<F>(DeserializerCommon {
698                    ctxt,
699                    signature: &signature,
700                    bytes: subslice(self.de.0.bytes, value_start..)?,
701                    fds: self.de.0.fds,
702                    pos: 0,
703                    container_depths: self.de.0.container_depths.inc_variant()?,
704                });
705
706                let v = seed.deserialize(&mut de).map(Some);
707                self.de.0.pos += de.0.pos;
708
709                v
710            }
711            ValueParseStage::Done => Ok(None),
712        }
713    }
714}
715
716impl<'de, #[cfg(unix)] F: AsFd, #[cfg(not(unix))] F> EnumAccess<'de>
717    for crate::de::Enum<&mut Deserializer<'de, '_, '_, F>, F>
718{
719    type Error = Error;
720    type Variant = Self;
721
722    fn variant_seed<V>(self, seed: V) -> Result<(V::Value, Self::Variant)>
723    where
724        V: DeserializeSeed<'de>,
725    {
726        seed.deserialize(&mut *self.de).map(|v| (v, self))
727    }
728}