Coverage Report

Created: 2026-04-09 06:45

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/rust/registry/src/index.crates.io-1949cf8c6b5b557f/serde_json-1.0.96/src/de.rs
Line
Count
Source
1
//! Deserialize JSON data to a Rust data structure.
2
3
use crate::error::{Error, ErrorCode, Result};
4
#[cfg(feature = "float_roundtrip")]
5
use crate::lexical;
6
use crate::number::Number;
7
use crate::read::{self, Fused, Reference};
8
use alloc::string::String;
9
use alloc::vec::Vec;
10
#[cfg(feature = "float_roundtrip")]
11
use core::iter;
12
use core::iter::FusedIterator;
13
use core::marker::PhantomData;
14
use core::result;
15
use core::str::FromStr;
16
use serde::de::{self, Expected, Unexpected};
17
use serde::forward_to_deserialize_any;
18
19
#[cfg(feature = "arbitrary_precision")]
20
use crate::number::NumberDeserializer;
21
22
pub use crate::read::{Read, SliceRead, StrRead};
23
24
#[cfg(feature = "std")]
25
pub use crate::read::IoRead;
26
27
//////////////////////////////////////////////////////////////////////////////
28
29
/// A structure that deserializes JSON into Rust values.
30
pub struct Deserializer<R> {
31
    read: R,
32
    scratch: Vec<u8>,
33
    remaining_depth: u8,
34
    #[cfg(feature = "float_roundtrip")]
35
    single_precision: bool,
36
    #[cfg(feature = "unbounded_depth")]
37
    disable_recursion_limit: bool,
38
}
39
40
impl<'de, R> Deserializer<R>
41
where
42
    R: read::Read<'de>,
43
{
44
    /// Create a JSON deserializer from one of the possible serde_json input
45
    /// sources.
46
    ///
47
    /// Typically it is more convenient to use one of these methods instead:
48
    ///
49
    ///   - Deserializer::from_str
50
    ///   - Deserializer::from_slice
51
    ///   - Deserializer::from_reader
52
0
    pub fn new(read: R) -> Self {
53
0
        Deserializer {
54
0
            read,
55
0
            scratch: Vec::new(),
56
0
            remaining_depth: 128,
57
0
            #[cfg(feature = "float_roundtrip")]
58
0
            single_precision: false,
59
0
            #[cfg(feature = "unbounded_depth")]
60
0
            disable_recursion_limit: false,
61
0
        }
62
0
    }
Unexecuted instantiation: <serde_json::de::Deserializer<serde_json::read::SliceRead>>::new
Unexecuted instantiation: <serde_json::de::Deserializer<serde_json::read::StrRead>>::new
63
}
64
65
#[cfg(feature = "std")]
66
impl<R> Deserializer<read::IoRead<R>>
67
where
68
    R: crate::io::Read,
69
{
70
    /// Creates a JSON deserializer from an `io::Read`.
71
    ///
72
    /// Reader-based deserializers do not support deserializing borrowed types
73
    /// like `&str`, since the `std::io::Read` trait has no non-copying methods
74
    /// -- everything it does involves copying bytes out of the data source.
75
0
    pub fn from_reader(reader: R) -> Self {
76
0
        Deserializer::new(read::IoRead::new(reader))
77
0
    }
78
}
79
80
impl<'a> Deserializer<read::SliceRead<'a>> {
81
    /// Creates a JSON deserializer from a `&[u8]`.
82
0
    pub fn from_slice(bytes: &'a [u8]) -> Self {
83
0
        Deserializer::new(read::SliceRead::new(bytes))
84
0
    }
85
}
86
87
impl<'a> Deserializer<read::StrRead<'a>> {
88
    /// Creates a JSON deserializer from a `&str`.
89
0
    pub fn from_str(s: &'a str) -> Self {
90
0
        Deserializer::new(read::StrRead::new(s))
91
0
    }
92
}
93
94
macro_rules! overflow {
95
    ($a:ident * 10 + $b:ident, $c:expr) => {
96
        match $c {
97
            c => $a >= c / 10 && ($a > c / 10 || $b > c % 10),
98
        }
99
    };
100
}
101
102
pub(crate) enum ParserNumber {
103
    F64(f64),
104
    U64(u64),
105
    I64(i64),
106
    #[cfg(feature = "arbitrary_precision")]
107
    String(String),
108
}
109
110
impl ParserNumber {
111
0
    fn visit<'de, V>(self, visitor: V) -> Result<V::Value>
112
0
    where
113
0
        V: de::Visitor<'de>,
114
    {
115
0
        match self {
116
0
            ParserNumber::F64(x) => visitor.visit_f64(x),
117
0
            ParserNumber::U64(x) => visitor.visit_u64(x),
118
0
            ParserNumber::I64(x) => visitor.visit_i64(x),
119
            #[cfg(feature = "arbitrary_precision")]
120
            ParserNumber::String(x) => visitor.visit_map(NumberDeserializer { number: x.into() }),
121
        }
122
0
    }
Unexecuted instantiation: <serde_json::de::ParserNumber>::visit::<<usize as serde::de::Deserialize>::deserialize::PrimitiveVisitor>
Unexecuted instantiation: <serde_json::de::ParserNumber>::visit::<<serde_json::value::Value as serde::de::Deserialize>::deserialize::ValueVisitor>
123
124
0
    fn invalid_type(self, exp: &dyn Expected) -> Error {
125
0
        match self {
126
0
            ParserNumber::F64(x) => de::Error::invalid_type(Unexpected::Float(x), exp),
127
0
            ParserNumber::U64(x) => de::Error::invalid_type(Unexpected::Unsigned(x), exp),
128
0
            ParserNumber::I64(x) => de::Error::invalid_type(Unexpected::Signed(x), exp),
129
            #[cfg(feature = "arbitrary_precision")]
130
            ParserNumber::String(_) => de::Error::invalid_type(Unexpected::Other("number"), exp),
131
        }
132
0
    }
133
}
134
135
impl<'de, R: Read<'de>> Deserializer<R> {
136
    /// The `Deserializer::end` method should be called after a value has been fully deserialized.
137
    /// This allows the `Deserializer` to validate that the input stream is at the end or that it
138
    /// only has trailing whitespace.
139
0
    pub fn end(&mut self) -> Result<()> {
140
0
        match tri!(self.parse_whitespace()) {
141
0
            Some(_) => Err(self.peek_error(ErrorCode::TrailingCharacters)),
142
0
            None => Ok(()),
143
        }
144
0
    }
Unexecuted instantiation: <serde_json::de::Deserializer<serde_json::read::SliceRead>>::end
Unexecuted instantiation: <serde_json::de::Deserializer<serde_json::read::StrRead>>::end
145
146
    /// Turn a JSON deserializer into an iterator over values of type T.
147
0
    pub fn into_iter<T>(self) -> StreamDeserializer<'de, R, T>
148
0
    where
149
0
        T: de::Deserialize<'de>,
150
    {
151
        // This cannot be an implementation of std::iter::IntoIterator because
152
        // we need the caller to choose what T is.
153
0
        let offset = self.read.byte_offset();
154
0
        StreamDeserializer {
155
0
            de: self,
156
0
            offset,
157
0
            failed: false,
158
0
            output: PhantomData,
159
0
            lifetime: PhantomData,
160
0
        }
161
0
    }
162
163
    /// Parse arbitrarily deep JSON structures without any consideration for
164
    /// overflowing the stack.
165
    ///
166
    /// You will want to provide some other way to protect against stack
167
    /// overflows, such as by wrapping your Deserializer in the dynamically
168
    /// growing stack adapter provided by the serde_stacker crate. Additionally
169
    /// you will need to be careful around other recursive operations on the
170
    /// parsed result which may overflow the stack after deserialization has
171
    /// completed, including, but not limited to, Display and Debug and Drop
172
    /// impls.
173
    ///
174
    /// *This method is only available if serde_json is built with the
175
    /// `"unbounded_depth"` feature.*
176
    ///
177
    /// # Examples
178
    ///
179
    /// ```
180
    /// use serde::Deserialize;
181
    /// use serde_json::Value;
182
    ///
183
    /// fn main() {
184
    ///     let mut json = String::new();
185
    ///     for _ in 0..10000 {
186
    ///         json = format!("[{}]", json);
187
    ///     }
188
    ///
189
    ///     let mut deserializer = serde_json::Deserializer::from_str(&json);
190
    ///     deserializer.disable_recursion_limit();
191
    ///     let deserializer = serde_stacker::Deserializer::new(&mut deserializer);
192
    ///     let value = Value::deserialize(deserializer).unwrap();
193
    ///
194
    ///     carefully_drop_nested_arrays(value);
195
    /// }
196
    ///
197
    /// fn carefully_drop_nested_arrays(value: Value) {
198
    ///     let mut stack = vec![value];
199
    ///     while let Some(value) = stack.pop() {
200
    ///         if let Value::Array(array) = value {
201
    ///             stack.extend(array);
202
    ///         }
203
    ///     }
204
    /// }
205
    /// ```
206
    #[cfg(feature = "unbounded_depth")]
207
    #[cfg_attr(docsrs, doc(cfg(feature = "unbounded_depth")))]
208
    pub fn disable_recursion_limit(&mut self) {
209
        self.disable_recursion_limit = true;
210
    }
211
212
0
    fn peek(&mut self) -> Result<Option<u8>> {
213
0
        self.read.peek()
214
0
    }
Unexecuted instantiation: <serde_json::de::Deserializer<serde_json::read::SliceRead>>::peek
Unexecuted instantiation: <serde_json::de::Deserializer<serde_json::read::StrRead>>::peek
215
216
0
    fn peek_or_null(&mut self) -> Result<u8> {
217
0
        Ok(tri!(self.peek()).unwrap_or(b'\x00'))
218
0
    }
Unexecuted instantiation: <serde_json::de::Deserializer<serde_json::read::SliceRead>>::peek_or_null
Unexecuted instantiation: <serde_json::de::Deserializer<serde_json::read::StrRead>>::peek_or_null
219
220
0
    fn eat_char(&mut self) {
221
0
        self.read.discard();
222
0
    }
Unexecuted instantiation: <serde_json::de::Deserializer<serde_json::read::SliceRead>>::eat_char
Unexecuted instantiation: <serde_json::de::Deserializer<serde_json::read::StrRead>>::eat_char
223
224
0
    fn next_char(&mut self) -> Result<Option<u8>> {
225
0
        self.read.next()
226
0
    }
Unexecuted instantiation: <serde_json::de::Deserializer<serde_json::read::SliceRead>>::next_char
Unexecuted instantiation: <serde_json::de::Deserializer<serde_json::read::StrRead>>::next_char
227
228
0
    fn next_char_or_null(&mut self) -> Result<u8> {
229
0
        Ok(tri!(self.next_char()).unwrap_or(b'\x00'))
230
0
    }
Unexecuted instantiation: <serde_json::de::Deserializer<serde_json::read::SliceRead>>::next_char_or_null
Unexecuted instantiation: <serde_json::de::Deserializer<_>>::next_char_or_null
231
232
    /// Error caused by a byte from next_char().
233
    #[cold]
234
0
    fn error(&self, reason: ErrorCode) -> Error {
235
0
        let position = self.read.position();
236
0
        Error::syntax(reason, position.line, position.column)
237
0
    }
Unexecuted instantiation: <serde_json::de::Deserializer<serde_json::read::SliceRead>>::error
Unexecuted instantiation: <serde_json::de::Deserializer<serde_json::read::StrRead>>::error
238
239
    /// Error caused by a byte from peek().
240
    #[cold]
241
0
    fn peek_error(&self, reason: ErrorCode) -> Error {
242
0
        let position = self.read.peek_position();
243
0
        Error::syntax(reason, position.line, position.column)
244
0
    }
Unexecuted instantiation: <serde_json::de::Deserializer<serde_json::read::SliceRead>>::peek_error
Unexecuted instantiation: <serde_json::de::Deserializer<serde_json::read::StrRead>>::peek_error
245
246
    /// Returns the first non-whitespace byte without consuming it, or `None` if
247
    /// EOF is encountered.
248
0
    fn parse_whitespace(&mut self) -> Result<Option<u8>> {
249
        loop {
250
0
            match tri!(self.peek()) {
251
0
                Some(b' ') | Some(b'\n') | Some(b'\t') | Some(b'\r') => {
252
0
                    self.eat_char();
253
0
                }
254
0
                other => {
255
0
                    return Ok(other);
256
                }
257
            }
258
        }
259
0
    }
Unexecuted instantiation: <serde_json::de::Deserializer<serde_json::read::SliceRead>>::parse_whitespace
Unexecuted instantiation: <serde_json::de::Deserializer<serde_json::read::StrRead>>::parse_whitespace
260
261
    #[cold]
262
0
    fn peek_invalid_type(&mut self, exp: &dyn Expected) -> Error {
263
0
        let err = match self.peek_or_null().unwrap_or(b'\x00') {
264
            b'n' => {
265
0
                self.eat_char();
266
0
                if let Err(err) = self.parse_ident(b"ull") {
267
0
                    return err;
268
0
                }
269
0
                de::Error::invalid_type(Unexpected::Unit, exp)
270
            }
271
            b't' => {
272
0
                self.eat_char();
273
0
                if let Err(err) = self.parse_ident(b"rue") {
274
0
                    return err;
275
0
                }
276
0
                de::Error::invalid_type(Unexpected::Bool(true), exp)
277
            }
278
            b'f' => {
279
0
                self.eat_char();
280
0
                if let Err(err) = self.parse_ident(b"alse") {
281
0
                    return err;
282
0
                }
283
0
                de::Error::invalid_type(Unexpected::Bool(false), exp)
284
            }
285
            b'-' => {
286
0
                self.eat_char();
287
0
                match self.parse_any_number(false) {
288
0
                    Ok(n) => n.invalid_type(exp),
289
0
                    Err(err) => return err,
290
                }
291
            }
292
0
            b'0'..=b'9' => match self.parse_any_number(true) {
293
0
                Ok(n) => n.invalid_type(exp),
294
0
                Err(err) => return err,
295
            },
296
            b'"' => {
297
0
                self.eat_char();
298
0
                self.scratch.clear();
299
0
                match self.read.parse_str(&mut self.scratch) {
300
0
                    Ok(s) => de::Error::invalid_type(Unexpected::Str(&s), exp),
301
0
                    Err(err) => return err,
302
                }
303
            }
304
0
            b'[' => de::Error::invalid_type(Unexpected::Seq, exp),
305
0
            b'{' => de::Error::invalid_type(Unexpected::Map, exp),
306
0
            _ => self.peek_error(ErrorCode::ExpectedSomeValue),
307
        };
308
309
0
        self.fix_position(err)
310
0
    }
Unexecuted instantiation: <serde_json::de::Deserializer<serde_json::read::SliceRead>>::peek_invalid_type
Unexecuted instantiation: <serde_json::de::Deserializer<_>>::peek_invalid_type
311
312
0
    fn deserialize_number<V>(&mut self, visitor: V) -> Result<V::Value>
313
0
    where
314
0
        V: de::Visitor<'de>,
315
    {
316
0
        let peek = match tri!(self.parse_whitespace()) {
317
0
            Some(b) => b,
318
            None => {
319
0
                return Err(self.peek_error(ErrorCode::EofWhileParsingValue));
320
            }
321
        };
322
323
0
        let value = match peek {
324
            b'-' => {
325
0
                self.eat_char();
326
0
                tri!(self.parse_integer(false)).visit(visitor)
327
            }
328
0
            b'0'..=b'9' => tri!(self.parse_integer(true)).visit(visitor),
329
0
            _ => Err(self.peek_invalid_type(&visitor)),
330
        };
331
332
0
        match value {
333
0
            Ok(value) => Ok(value),
334
0
            Err(err) => Err(self.fix_position(err)),
335
        }
336
0
    }
Unexecuted instantiation: <serde_json::de::Deserializer<serde_json::read::SliceRead>>::deserialize_number::<<usize as serde::de::Deserialize>::deserialize::PrimitiveVisitor>
Unexecuted instantiation: <serde_json::de::Deserializer<_>>::deserialize_number::<_>
337
338
0
    fn scan_integer128(&mut self, buf: &mut String) -> Result<()> {
339
0
        match tri!(self.next_char_or_null()) {
340
            b'0' => {
341
0
                buf.push('0');
342
                // There can be only one leading '0'.
343
0
                match tri!(self.peek_or_null()) {
344
0
                    b'0'..=b'9' => Err(self.peek_error(ErrorCode::InvalidNumber)),
345
0
                    _ => Ok(()),
346
                }
347
            }
348
0
            c @ b'1'..=b'9' => {
349
0
                buf.push(c as char);
350
0
                while let c @ b'0'..=b'9' = tri!(self.peek_or_null()) {
351
0
                    self.eat_char();
352
0
                    buf.push(c as char);
353
0
                }
354
0
                Ok(())
355
            }
356
0
            _ => Err(self.error(ErrorCode::InvalidNumber)),
357
        }
358
0
    }
359
360
    #[cold]
361
0
    fn fix_position(&self, err: Error) -> Error {
362
0
        err.fix_position(move |code| self.error(code))
Unexecuted instantiation: <serde_json::de::Deserializer<serde_json::read::SliceRead>>::fix_position::{closure#0}
Unexecuted instantiation: <serde_json::de::Deserializer<serde_json::read::StrRead>>::fix_position::{closure#0}
363
0
    }
Unexecuted instantiation: <serde_json::de::Deserializer<serde_json::read::SliceRead>>::fix_position
Unexecuted instantiation: <serde_json::de::Deserializer<serde_json::read::StrRead>>::fix_position
364
365
0
    fn parse_ident(&mut self, ident: &[u8]) -> Result<()> {
366
0
        for expected in ident {
367
0
            match tri!(self.next_char()) {
368
                None => {
369
0
                    return Err(self.error(ErrorCode::EofWhileParsingValue));
370
                }
371
0
                Some(next) => {
372
0
                    if next != *expected {
373
0
                        return Err(self.error(ErrorCode::ExpectedSomeIdent));
374
0
                    }
375
                }
376
            }
377
        }
378
379
0
        Ok(())
380
0
    }
Unexecuted instantiation: <serde_json::de::Deserializer<serde_json::read::SliceRead>>::parse_ident
Unexecuted instantiation: <serde_json::de::Deserializer<serde_json::read::StrRead>>::parse_ident
381
382
0
    fn parse_integer(&mut self, positive: bool) -> Result<ParserNumber> {
383
0
        let next = match tri!(self.next_char()) {
384
0
            Some(b) => b,
385
            None => {
386
0
                return Err(self.error(ErrorCode::EofWhileParsingValue));
387
            }
388
        };
389
390
0
        match next {
391
            b'0' => {
392
                // There can be only one leading '0'.
393
0
                match tri!(self.peek_or_null()) {
394
0
                    b'0'..=b'9' => Err(self.peek_error(ErrorCode::InvalidNumber)),
395
0
                    _ => self.parse_number(positive, 0),
396
                }
397
            }
398
0
            c @ b'1'..=b'9' => {
399
0
                let mut significand = (c - b'0') as u64;
400
401
                loop {
402
0
                    match tri!(self.peek_or_null()) {
403
0
                        c @ b'0'..=b'9' => {
404
0
                            let digit = (c - b'0') as u64;
405
406
                            // We need to be careful with overflow. If we can,
407
                            // try to keep the number as a `u64` until we grow
408
                            // too large. At that point, switch to parsing the
409
                            // value as a `f64`.
410
0
                            if overflow!(significand * 10 + digit, u64::max_value()) {
411
0
                                return Ok(ParserNumber::F64(tri!(
412
0
                                    self.parse_long_integer(positive, significand),
413
                                )));
414
0
                            }
415
416
0
                            self.eat_char();
417
0
                            significand = significand * 10 + digit;
418
                        }
419
                        _ => {
420
0
                            return self.parse_number(positive, significand);
421
                        }
422
                    }
423
                }
424
            }
425
0
            _ => Err(self.error(ErrorCode::InvalidNumber)),
426
        }
427
0
    }
Unexecuted instantiation: <serde_json::de::Deserializer<serde_json::read::SliceRead>>::parse_integer
Unexecuted instantiation: <serde_json::de::Deserializer<serde_json::read::StrRead>>::parse_integer
428
429
0
    fn parse_number(&mut self, positive: bool, significand: u64) -> Result<ParserNumber> {
430
0
        Ok(match tri!(self.peek_or_null()) {
431
0
            b'.' => ParserNumber::F64(tri!(self.parse_decimal(positive, significand, 0))),
432
0
            b'e' | b'E' => ParserNumber::F64(tri!(self.parse_exponent(positive, significand, 0))),
433
            _ => {
434
0
                if positive {
435
0
                    ParserNumber::U64(significand)
436
                } else {
437
0
                    let neg = (significand as i64).wrapping_neg();
438
439
                    // Convert into a float if we underflow, or on `-0`.
440
0
                    if neg >= 0 {
441
0
                        ParserNumber::F64(-(significand as f64))
442
                    } else {
443
0
                        ParserNumber::I64(neg)
444
                    }
445
                }
446
            }
447
        })
448
0
    }
Unexecuted instantiation: <serde_json::de::Deserializer<serde_json::read::SliceRead>>::parse_number
Unexecuted instantiation: <serde_json::de::Deserializer<serde_json::read::StrRead>>::parse_number
449
450
0
    fn parse_decimal(
451
0
        &mut self,
452
0
        positive: bool,
453
0
        mut significand: u64,
454
0
        exponent_before_decimal_point: i32,
455
0
    ) -> Result<f64> {
456
0
        self.eat_char();
457
458
0
        let mut exponent_after_decimal_point = 0;
459
0
        while let c @ b'0'..=b'9' = tri!(self.peek_or_null()) {
460
0
            let digit = (c - b'0') as u64;
461
462
0
            if overflow!(significand * 10 + digit, u64::max_value()) {
463
0
                let exponent = exponent_before_decimal_point + exponent_after_decimal_point;
464
0
                return self.parse_decimal_overflow(positive, significand, exponent);
465
0
            }
466
467
0
            self.eat_char();
468
0
            significand = significand * 10 + digit;
469
0
            exponent_after_decimal_point -= 1;
470
        }
471
472
        // Error if there is not at least one digit after the decimal point.
473
0
        if exponent_after_decimal_point == 0 {
474
0
            match tri!(self.peek()) {
475
0
                Some(_) => return Err(self.peek_error(ErrorCode::InvalidNumber)),
476
0
                None => return Err(self.peek_error(ErrorCode::EofWhileParsingValue)),
477
            }
478
0
        }
479
480
0
        let exponent = exponent_before_decimal_point + exponent_after_decimal_point;
481
0
        match tri!(self.peek_or_null()) {
482
0
            b'e' | b'E' => self.parse_exponent(positive, significand, exponent),
483
0
            _ => self.f64_from_parts(positive, significand, exponent),
484
        }
485
0
    }
Unexecuted instantiation: <serde_json::de::Deserializer<serde_json::read::SliceRead>>::parse_decimal
Unexecuted instantiation: <serde_json::de::Deserializer<serde_json::read::StrRead>>::parse_decimal
486
487
0
    fn parse_exponent(
488
0
        &mut self,
489
0
        positive: bool,
490
0
        significand: u64,
491
0
        starting_exp: i32,
492
0
    ) -> Result<f64> {
493
0
        self.eat_char();
494
495
0
        let positive_exp = match tri!(self.peek_or_null()) {
496
            b'+' => {
497
0
                self.eat_char();
498
0
                true
499
            }
500
            b'-' => {
501
0
                self.eat_char();
502
0
                false
503
            }
504
0
            _ => true,
505
        };
506
507
0
        let next = match tri!(self.next_char()) {
508
0
            Some(b) => b,
509
            None => {
510
0
                return Err(self.error(ErrorCode::EofWhileParsingValue));
511
            }
512
        };
513
514
        // Make sure a digit follows the exponent place.
515
0
        let mut exp = match next {
516
0
            c @ b'0'..=b'9' => (c - b'0') as i32,
517
            _ => {
518
0
                return Err(self.error(ErrorCode::InvalidNumber));
519
            }
520
        };
521
522
0
        while let c @ b'0'..=b'9' = tri!(self.peek_or_null()) {
523
0
            self.eat_char();
524
0
            let digit = (c - b'0') as i32;
525
526
0
            if overflow!(exp * 10 + digit, i32::max_value()) {
527
0
                let zero_significand = significand == 0;
528
0
                return self.parse_exponent_overflow(positive, zero_significand, positive_exp);
529
0
            }
530
531
0
            exp = exp * 10 + digit;
532
        }
533
534
0
        let final_exp = if positive_exp {
535
0
            starting_exp.saturating_add(exp)
536
        } else {
537
0
            starting_exp.saturating_sub(exp)
538
        };
539
540
0
        self.f64_from_parts(positive, significand, final_exp)
541
0
    }
Unexecuted instantiation: <serde_json::de::Deserializer<serde_json::read::SliceRead>>::parse_exponent
Unexecuted instantiation: <serde_json::de::Deserializer<serde_json::read::StrRead>>::parse_exponent
542
543
    #[cfg(feature = "float_roundtrip")]
544
    fn f64_from_parts(&mut self, positive: bool, significand: u64, exponent: i32) -> Result<f64> {
545
        let f = if self.single_precision {
546
            lexical::parse_concise_float::<f32>(significand, exponent) as f64
547
        } else {
548
            lexical::parse_concise_float::<f64>(significand, exponent)
549
        };
550
551
        if f.is_infinite() {
552
            Err(self.error(ErrorCode::NumberOutOfRange))
553
        } else {
554
            Ok(if positive { f } else { -f })
555
        }
556
    }
557
558
    #[cfg(not(feature = "float_roundtrip"))]
559
0
    fn f64_from_parts(
560
0
        &mut self,
561
0
        positive: bool,
562
0
        significand: u64,
563
0
        mut exponent: i32,
564
0
    ) -> Result<f64> {
565
0
        let mut f = significand as f64;
566
        loop {
567
0
            match POW10.get(exponent.wrapping_abs() as usize) {
568
0
                Some(&pow) => {
569
0
                    if exponent >= 0 {
570
0
                        f *= pow;
571
0
                        if f.is_infinite() {
572
0
                            return Err(self.error(ErrorCode::NumberOutOfRange));
573
0
                        }
574
0
                    } else {
575
0
                        f /= pow;
576
0
                    }
577
0
                    break;
578
                }
579
                None => {
580
0
                    if f == 0.0 {
581
0
                        break;
582
0
                    }
583
0
                    if exponent >= 0 {
584
0
                        return Err(self.error(ErrorCode::NumberOutOfRange));
585
0
                    }
586
0
                    f /= 1e308;
587
0
                    exponent += 308;
588
                }
589
            }
590
        }
591
0
        Ok(if positive { f } else { -f })
592
0
    }
Unexecuted instantiation: <serde_json::de::Deserializer<serde_json::read::SliceRead>>::f64_from_parts
Unexecuted instantiation: <serde_json::de::Deserializer<serde_json::read::StrRead>>::f64_from_parts
593
594
    #[cfg(feature = "float_roundtrip")]
595
    #[cold]
596
    #[inline(never)]
597
    fn parse_long_integer(&mut self, positive: bool, partial_significand: u64) -> Result<f64> {
598
        // To deserialize floats we'll first push the integer and fraction
599
        // parts, both as byte strings, into the scratch buffer and then feed
600
        // both slices to lexical's parser. For example if the input is
601
        // `12.34e5` we'll push b"1234" into scratch and then pass b"12" and
602
        // b"34" to lexical. `integer_end` will be used to track where to split
603
        // the scratch buffer.
604
        //
605
        // Note that lexical expects the integer part to contain *no* leading
606
        // zeroes and the fraction part to contain *no* trailing zeroes. The
607
        // first requirement is already handled by the integer parsing logic.
608
        // The second requirement will be enforced just before passing the
609
        // slices to lexical in f64_long_from_parts.
610
        self.scratch.clear();
611
        self.scratch
612
            .extend_from_slice(itoa::Buffer::new().format(partial_significand).as_bytes());
613
614
        loop {
615
            match tri!(self.peek_or_null()) {
616
                c @ b'0'..=b'9' => {
617
                    self.scratch.push(c);
618
                    self.eat_char();
619
                }
620
                b'.' => {
621
                    self.eat_char();
622
                    return self.parse_long_decimal(positive, self.scratch.len());
623
                }
624
                b'e' | b'E' => {
625
                    return self.parse_long_exponent(positive, self.scratch.len());
626
                }
627
                _ => {
628
                    return self.f64_long_from_parts(positive, self.scratch.len(), 0);
629
                }
630
            }
631
        }
632
    }
633
634
    #[cfg(not(feature = "float_roundtrip"))]
635
    #[cold]
636
    #[inline(never)]
637
0
    fn parse_long_integer(&mut self, positive: bool, significand: u64) -> Result<f64> {
638
0
        let mut exponent = 0;
639
        loop {
640
0
            match tri!(self.peek_or_null()) {
641
0
                b'0'..=b'9' => {
642
0
                    self.eat_char();
643
0
                    // This could overflow... if your integer is gigabytes long.
644
0
                    // Ignore that possibility.
645
0
                    exponent += 1;
646
0
                }
647
                b'.' => {
648
0
                    return self.parse_decimal(positive, significand, exponent);
649
                }
650
                b'e' | b'E' => {
651
0
                    return self.parse_exponent(positive, significand, exponent);
652
                }
653
                _ => {
654
0
                    return self.f64_from_parts(positive, significand, exponent);
655
                }
656
            }
657
        }
658
0
    }
Unexecuted instantiation: <serde_json::de::Deserializer<serde_json::read::SliceRead>>::parse_long_integer
Unexecuted instantiation: <serde_json::de::Deserializer<serde_json::read::StrRead>>::parse_long_integer
659
660
    #[cfg(feature = "float_roundtrip")]
661
    #[cold]
662
    fn parse_long_decimal(&mut self, positive: bool, integer_end: usize) -> Result<f64> {
663
        let mut at_least_one_digit = integer_end < self.scratch.len();
664
        while let c @ b'0'..=b'9' = tri!(self.peek_or_null()) {
665
            self.scratch.push(c);
666
            self.eat_char();
667
            at_least_one_digit = true;
668
        }
669
670
        if !at_least_one_digit {
671
            match tri!(self.peek()) {
672
                Some(_) => return Err(self.peek_error(ErrorCode::InvalidNumber)),
673
                None => return Err(self.peek_error(ErrorCode::EofWhileParsingValue)),
674
            }
675
        }
676
677
        match tri!(self.peek_or_null()) {
678
            b'e' | b'E' => self.parse_long_exponent(positive, integer_end),
679
            _ => self.f64_long_from_parts(positive, integer_end, 0),
680
        }
681
    }
682
683
    #[cfg(feature = "float_roundtrip")]
684
    fn parse_long_exponent(&mut self, positive: bool, integer_end: usize) -> Result<f64> {
685
        self.eat_char();
686
687
        let positive_exp = match tri!(self.peek_or_null()) {
688
            b'+' => {
689
                self.eat_char();
690
                true
691
            }
692
            b'-' => {
693
                self.eat_char();
694
                false
695
            }
696
            _ => true,
697
        };
698
699
        let next = match tri!(self.next_char()) {
700
            Some(b) => b,
701
            None => {
702
                return Err(self.error(ErrorCode::EofWhileParsingValue));
703
            }
704
        };
705
706
        // Make sure a digit follows the exponent place.
707
        let mut exp = match next {
708
            c @ b'0'..=b'9' => (c - b'0') as i32,
709
            _ => {
710
                return Err(self.error(ErrorCode::InvalidNumber));
711
            }
712
        };
713
714
        while let c @ b'0'..=b'9' = tri!(self.peek_or_null()) {
715
            self.eat_char();
716
            let digit = (c - b'0') as i32;
717
718
            if overflow!(exp * 10 + digit, i32::max_value()) {
719
                let zero_significand = self.scratch.iter().all(|&digit| digit == b'0');
720
                return self.parse_exponent_overflow(positive, zero_significand, positive_exp);
721
            }
722
723
            exp = exp * 10 + digit;
724
        }
725
726
        let final_exp = if positive_exp { exp } else { -exp };
727
728
        self.f64_long_from_parts(positive, integer_end, final_exp)
729
    }
730
731
    // This cold code should not be inlined into the middle of the hot
732
    // decimal-parsing loop above.
733
    #[cfg(feature = "float_roundtrip")]
734
    #[cold]
735
    #[inline(never)]
736
    fn parse_decimal_overflow(
737
        &mut self,
738
        positive: bool,
739
        significand: u64,
740
        exponent: i32,
741
    ) -> Result<f64> {
742
        let mut buffer = itoa::Buffer::new();
743
        let significand = buffer.format(significand);
744
        let fraction_digits = -exponent as usize;
745
        self.scratch.clear();
746
        if let Some(zeros) = fraction_digits.checked_sub(significand.len() + 1) {
747
            self.scratch.extend(iter::repeat(b'0').take(zeros + 1));
748
        }
749
        self.scratch.extend_from_slice(significand.as_bytes());
750
        let integer_end = self.scratch.len() - fraction_digits;
751
        self.parse_long_decimal(positive, integer_end)
752
    }
753
754
    #[cfg(not(feature = "float_roundtrip"))]
755
    #[cold]
756
    #[inline(never)]
757
0
    fn parse_decimal_overflow(
758
0
        &mut self,
759
0
        positive: bool,
760
0
        significand: u64,
761
0
        exponent: i32,
762
0
    ) -> Result<f64> {
763
        // The next multiply/add would overflow, so just ignore all further
764
        // digits.
765
0
        while let b'0'..=b'9' = tri!(self.peek_or_null()) {
766
0
            self.eat_char();
767
0
        }
768
769
0
        match tri!(self.peek_or_null()) {
770
0
            b'e' | b'E' => self.parse_exponent(positive, significand, exponent),
771
0
            _ => self.f64_from_parts(positive, significand, exponent),
772
        }
773
0
    }
Unexecuted instantiation: <serde_json::de::Deserializer<serde_json::read::SliceRead>>::parse_decimal_overflow
Unexecuted instantiation: <serde_json::de::Deserializer<serde_json::read::StrRead>>::parse_decimal_overflow
774
775
    // This cold code should not be inlined into the middle of the hot
776
    // exponent-parsing loop above.
777
    #[cold]
778
    #[inline(never)]
779
0
    fn parse_exponent_overflow(
780
0
        &mut self,
781
0
        positive: bool,
782
0
        zero_significand: bool,
783
0
        positive_exp: bool,
784
0
    ) -> Result<f64> {
785
        // Error instead of +/- infinity.
786
0
        if !zero_significand && positive_exp {
787
0
            return Err(self.error(ErrorCode::NumberOutOfRange));
788
0
        }
789
790
0
        while let b'0'..=b'9' = tri!(self.peek_or_null()) {
791
0
            self.eat_char();
792
0
        }
793
0
        Ok(if positive { 0.0 } else { -0.0 })
794
0
    }
Unexecuted instantiation: <serde_json::de::Deserializer<serde_json::read::SliceRead>>::parse_exponent_overflow
Unexecuted instantiation: <serde_json::de::Deserializer<serde_json::read::StrRead>>::parse_exponent_overflow
795
796
    #[cfg(feature = "float_roundtrip")]
797
    fn f64_long_from_parts(
798
        &mut self,
799
        positive: bool,
800
        integer_end: usize,
801
        exponent: i32,
802
    ) -> Result<f64> {
803
        let integer = &self.scratch[..integer_end];
804
        let fraction = &self.scratch[integer_end..];
805
806
        let f = if self.single_precision {
807
            lexical::parse_truncated_float::<f32>(integer, fraction, exponent) as f64
808
        } else {
809
            lexical::parse_truncated_float::<f64>(integer, fraction, exponent)
810
        };
811
812
        if f.is_infinite() {
813
            Err(self.error(ErrorCode::NumberOutOfRange))
814
        } else {
815
            Ok(if positive { f } else { -f })
816
        }
817
    }
818
819
0
    fn parse_any_signed_number(&mut self) -> Result<ParserNumber> {
820
0
        let peek = match tri!(self.peek()) {
821
0
            Some(b) => b,
822
            None => {
823
0
                return Err(self.peek_error(ErrorCode::EofWhileParsingValue));
824
            }
825
        };
826
827
0
        let value = match peek {
828
            b'-' => {
829
0
                self.eat_char();
830
0
                self.parse_any_number(false)
831
            }
832
0
            b'0'..=b'9' => self.parse_any_number(true),
833
0
            _ => Err(self.peek_error(ErrorCode::InvalidNumber)),
834
        };
835
836
0
        let value = match tri!(self.peek()) {
837
0
            Some(_) => Err(self.peek_error(ErrorCode::InvalidNumber)),
838
0
            None => value,
839
        };
840
841
0
        match value {
842
0
            Ok(value) => Ok(value),
843
            // The de::Error impl creates errors with unknown line and column.
844
            // Fill in the position here by looking at the current index in the
845
            // input. There is no way to tell whether this should call `error`
846
            // or `peek_error` so pick the one that seems correct more often.
847
            // Worst case, the position is off by one character.
848
0
            Err(err) => Err(self.fix_position(err)),
849
        }
850
0
    }
851
852
    #[cfg(not(feature = "arbitrary_precision"))]
853
0
    fn parse_any_number(&mut self, positive: bool) -> Result<ParserNumber> {
854
0
        self.parse_integer(positive)
855
0
    }
Unexecuted instantiation: <serde_json::de::Deserializer<serde_json::read::SliceRead>>::parse_any_number
Unexecuted instantiation: <serde_json::de::Deserializer<serde_json::read::StrRead>>::parse_any_number
856
857
    #[cfg(feature = "arbitrary_precision")]
858
    fn parse_any_number(&mut self, positive: bool) -> Result<ParserNumber> {
859
        let mut buf = String::with_capacity(16);
860
        if !positive {
861
            buf.push('-');
862
        }
863
        self.scan_integer(&mut buf)?;
864
        if positive {
865
            if let Ok(unsigned) = buf.parse() {
866
                return Ok(ParserNumber::U64(unsigned));
867
            }
868
        } else {
869
            if let Ok(signed) = buf.parse() {
870
                return Ok(ParserNumber::I64(signed));
871
            }
872
        }
873
        Ok(ParserNumber::String(buf))
874
    }
875
876
    #[cfg(feature = "arbitrary_precision")]
877
    fn scan_or_eof(&mut self, buf: &mut String) -> Result<u8> {
878
        match tri!(self.next_char()) {
879
            Some(b) => {
880
                buf.push(b as char);
881
                Ok(b)
882
            }
883
            None => Err(self.error(ErrorCode::EofWhileParsingValue)),
884
        }
885
    }
886
887
    #[cfg(feature = "arbitrary_precision")]
888
    fn scan_integer(&mut self, buf: &mut String) -> Result<()> {
889
        match tri!(self.scan_or_eof(buf)) {
890
            b'0' => {
891
                // There can be only one leading '0'.
892
                match tri!(self.peek_or_null()) {
893
                    b'0'..=b'9' => Err(self.peek_error(ErrorCode::InvalidNumber)),
894
                    _ => self.scan_number(buf),
895
                }
896
            }
897
            b'1'..=b'9' => loop {
898
                match tri!(self.peek_or_null()) {
899
                    c @ b'0'..=b'9' => {
900
                        self.eat_char();
901
                        buf.push(c as char);
902
                    }
903
                    _ => {
904
                        return self.scan_number(buf);
905
                    }
906
                }
907
            },
908
            _ => Err(self.error(ErrorCode::InvalidNumber)),
909
        }
910
    }
911
912
    #[cfg(feature = "arbitrary_precision")]
913
    fn scan_number(&mut self, buf: &mut String) -> Result<()> {
914
        match tri!(self.peek_or_null()) {
915
            b'.' => self.scan_decimal(buf),
916
            e @ b'e' | e @ b'E' => self.scan_exponent(e as char, buf),
917
            _ => Ok(()),
918
        }
919
    }
920
921
    #[cfg(feature = "arbitrary_precision")]
922
    fn scan_decimal(&mut self, buf: &mut String) -> Result<()> {
923
        self.eat_char();
924
        buf.push('.');
925
926
        let mut at_least_one_digit = false;
927
        while let c @ b'0'..=b'9' = tri!(self.peek_or_null()) {
928
            self.eat_char();
929
            buf.push(c as char);
930
            at_least_one_digit = true;
931
        }
932
933
        if !at_least_one_digit {
934
            match tri!(self.peek()) {
935
                Some(_) => return Err(self.peek_error(ErrorCode::InvalidNumber)),
936
                None => return Err(self.peek_error(ErrorCode::EofWhileParsingValue)),
937
            }
938
        }
939
940
        match tri!(self.peek_or_null()) {
941
            e @ b'e' | e @ b'E' => self.scan_exponent(e as char, buf),
942
            _ => Ok(()),
943
        }
944
    }
945
946
    #[cfg(feature = "arbitrary_precision")]
947
    fn scan_exponent(&mut self, e: char, buf: &mut String) -> Result<()> {
948
        self.eat_char();
949
        buf.push(e);
950
951
        match tri!(self.peek_or_null()) {
952
            b'+' => {
953
                self.eat_char();
954
                buf.push('+');
955
            }
956
            b'-' => {
957
                self.eat_char();
958
                buf.push('-');
959
            }
960
            _ => {}
961
        }
962
963
        // Make sure a digit follows the exponent place.
964
        match tri!(self.scan_or_eof(buf)) {
965
            b'0'..=b'9' => {}
966
            _ => {
967
                return Err(self.error(ErrorCode::InvalidNumber));
968
            }
969
        }
970
971
        while let c @ b'0'..=b'9' = tri!(self.peek_or_null()) {
972
            self.eat_char();
973
            buf.push(c as char);
974
        }
975
976
        Ok(())
977
    }
978
979
0
    fn parse_object_colon(&mut self) -> Result<()> {
980
0
        match tri!(self.parse_whitespace()) {
981
            Some(b':') => {
982
0
                self.eat_char();
983
0
                Ok(())
984
            }
985
0
            Some(_) => Err(self.peek_error(ErrorCode::ExpectedColon)),
986
0
            None => Err(self.peek_error(ErrorCode::EofWhileParsingObject)),
987
        }
988
0
    }
Unexecuted instantiation: <serde_json::de::Deserializer<serde_json::read::SliceRead>>::parse_object_colon
Unexecuted instantiation: <serde_json::de::Deserializer<serde_json::read::StrRead>>::parse_object_colon
989
990
0
    fn end_seq(&mut self) -> Result<()> {
991
0
        match tri!(self.parse_whitespace()) {
992
            Some(b']') => {
993
0
                self.eat_char();
994
0
                Ok(())
995
            }
996
            Some(b',') => {
997
0
                self.eat_char();
998
0
                match self.parse_whitespace() {
999
0
                    Ok(Some(b']')) => Err(self.peek_error(ErrorCode::TrailingComma)),
1000
0
                    _ => Err(self.peek_error(ErrorCode::TrailingCharacters)),
1001
                }
1002
            }
1003
0
            Some(_) => Err(self.peek_error(ErrorCode::TrailingCharacters)),
1004
0
            None => Err(self.peek_error(ErrorCode::EofWhileParsingList)),
1005
        }
1006
0
    }
Unexecuted instantiation: <serde_json::de::Deserializer<serde_json::read::SliceRead>>::end_seq
Unexecuted instantiation: <serde_json::de::Deserializer<serde_json::read::StrRead>>::end_seq
1007
1008
0
    fn end_map(&mut self) -> Result<()> {
1009
0
        match tri!(self.parse_whitespace()) {
1010
            Some(b'}') => {
1011
0
                self.eat_char();
1012
0
                Ok(())
1013
            }
1014
0
            Some(b',') => Err(self.peek_error(ErrorCode::TrailingComma)),
1015
0
            Some(_) => Err(self.peek_error(ErrorCode::TrailingCharacters)),
1016
0
            None => Err(self.peek_error(ErrorCode::EofWhileParsingObject)),
1017
        }
1018
0
    }
Unexecuted instantiation: <serde_json::de::Deserializer<serde_json::read::SliceRead>>::end_map
Unexecuted instantiation: <serde_json::de::Deserializer<serde_json::read::StrRead>>::end_map
1019
1020
0
    fn ignore_value(&mut self) -> Result<()> {
1021
0
        self.scratch.clear();
1022
0
        let mut enclosing = None;
1023
1024
        loop {
1025
0
            let peek = match tri!(self.parse_whitespace()) {
1026
0
                Some(b) => b,
1027
                None => {
1028
0
                    return Err(self.peek_error(ErrorCode::EofWhileParsingValue));
1029
                }
1030
            };
1031
1032
0
            let frame = match peek {
1033
                b'n' => {
1034
0
                    self.eat_char();
1035
0
                    tri!(self.parse_ident(b"ull"));
1036
0
                    None
1037
                }
1038
                b't' => {
1039
0
                    self.eat_char();
1040
0
                    tri!(self.parse_ident(b"rue"));
1041
0
                    None
1042
                }
1043
                b'f' => {
1044
0
                    self.eat_char();
1045
0
                    tri!(self.parse_ident(b"alse"));
1046
0
                    None
1047
                }
1048
                b'-' => {
1049
0
                    self.eat_char();
1050
0
                    tri!(self.ignore_integer());
1051
0
                    None
1052
                }
1053
0
                b'0'..=b'9' => {
1054
0
                    tri!(self.ignore_integer());
1055
0
                    None
1056
                }
1057
                b'"' => {
1058
0
                    self.eat_char();
1059
0
                    tri!(self.read.ignore_str());
1060
0
                    None
1061
                }
1062
0
                frame @ b'[' | frame @ b'{' => {
1063
0
                    self.scratch.extend(enclosing.take());
1064
0
                    self.eat_char();
1065
0
                    Some(frame)
1066
                }
1067
0
                _ => return Err(self.peek_error(ErrorCode::ExpectedSomeValue)),
1068
            };
1069
1070
0
            let (mut accept_comma, mut frame) = match frame {
1071
0
                Some(frame) => (false, frame),
1072
0
                None => match enclosing.take() {
1073
0
                    Some(frame) => (true, frame),
1074
0
                    None => match self.scratch.pop() {
1075
0
                        Some(frame) => (true, frame),
1076
0
                        None => return Ok(()),
1077
                    },
1078
                },
1079
            };
1080
1081
            loop {
1082
0
                match tri!(self.parse_whitespace()) {
1083
0
                    Some(b',') if accept_comma => {
1084
0
                        self.eat_char();
1085
0
                        break;
1086
                    }
1087
0
                    Some(b']') if frame == b'[' => {}
1088
0
                    Some(b'}') if frame == b'{' => {}
1089
                    Some(_) => {
1090
0
                        if accept_comma {
1091
0
                            return Err(self.peek_error(match frame {
1092
0
                                b'[' => ErrorCode::ExpectedListCommaOrEnd,
1093
0
                                b'{' => ErrorCode::ExpectedObjectCommaOrEnd,
1094
0
                                _ => unreachable!(),
1095
                            }));
1096
                        } else {
1097
0
                            break;
1098
                        }
1099
                    }
1100
                    None => {
1101
0
                        return Err(self.peek_error(match frame {
1102
0
                            b'[' => ErrorCode::EofWhileParsingList,
1103
0
                            b'{' => ErrorCode::EofWhileParsingObject,
1104
0
                            _ => unreachable!(),
1105
                        }));
1106
                    }
1107
                }
1108
1109
0
                self.eat_char();
1110
0
                frame = match self.scratch.pop() {
1111
0
                    Some(frame) => frame,
1112
0
                    None => return Ok(()),
1113
                };
1114
0
                accept_comma = true;
1115
            }
1116
1117
0
            if frame == b'{' {
1118
0
                match tri!(self.parse_whitespace()) {
1119
0
                    Some(b'"') => self.eat_char(),
1120
0
                    Some(_) => return Err(self.peek_error(ErrorCode::KeyMustBeAString)),
1121
0
                    None => return Err(self.peek_error(ErrorCode::EofWhileParsingObject)),
1122
                }
1123
0
                tri!(self.read.ignore_str());
1124
0
                match tri!(self.parse_whitespace()) {
1125
0
                    Some(b':') => self.eat_char(),
1126
0
                    Some(_) => return Err(self.peek_error(ErrorCode::ExpectedColon)),
1127
0
                    None => return Err(self.peek_error(ErrorCode::EofWhileParsingObject)),
1128
                }
1129
0
            }
1130
1131
0
            enclosing = Some(frame);
1132
        }
1133
0
    }
Unexecuted instantiation: <serde_json::de::Deserializer<serde_json::read::SliceRead>>::ignore_value
Unexecuted instantiation: <serde_json::de::Deserializer<_>>::ignore_value
1134
1135
0
    fn ignore_integer(&mut self) -> Result<()> {
1136
0
        match tri!(self.next_char_or_null()) {
1137
            b'0' => {
1138
                // There can be only one leading '0'.
1139
0
                if let b'0'..=b'9' = tri!(self.peek_or_null()) {
1140
0
                    return Err(self.peek_error(ErrorCode::InvalidNumber));
1141
0
                }
1142
            }
1143
0
            b'1'..=b'9' => {
1144
0
                while let b'0'..=b'9' = tri!(self.peek_or_null()) {
1145
0
                    self.eat_char();
1146
0
                }
1147
            }
1148
            _ => {
1149
0
                return Err(self.error(ErrorCode::InvalidNumber));
1150
            }
1151
        }
1152
1153
0
        match tri!(self.peek_or_null()) {
1154
0
            b'.' => self.ignore_decimal(),
1155
0
            b'e' | b'E' => self.ignore_exponent(),
1156
0
            _ => Ok(()),
1157
        }
1158
0
    }
Unexecuted instantiation: <serde_json::de::Deserializer<serde_json::read::SliceRead>>::ignore_integer
Unexecuted instantiation: <serde_json::de::Deserializer<_>>::ignore_integer
1159
1160
0
    fn ignore_decimal(&mut self) -> Result<()> {
1161
0
        self.eat_char();
1162
1163
0
        let mut at_least_one_digit = false;
1164
0
        while let b'0'..=b'9' = tri!(self.peek_or_null()) {
1165
0
            self.eat_char();
1166
0
            at_least_one_digit = true;
1167
0
        }
1168
1169
0
        if !at_least_one_digit {
1170
0
            return Err(self.peek_error(ErrorCode::InvalidNumber));
1171
0
        }
1172
1173
0
        match tri!(self.peek_or_null()) {
1174
0
            b'e' | b'E' => self.ignore_exponent(),
1175
0
            _ => Ok(()),
1176
        }
1177
0
    }
Unexecuted instantiation: <serde_json::de::Deserializer<serde_json::read::SliceRead>>::ignore_decimal
Unexecuted instantiation: <serde_json::de::Deserializer<_>>::ignore_decimal
1178
1179
0
    fn ignore_exponent(&mut self) -> Result<()> {
1180
0
        self.eat_char();
1181
1182
0
        match tri!(self.peek_or_null()) {
1183
0
            b'+' | b'-' => self.eat_char(),
1184
0
            _ => {}
1185
        }
1186
1187
        // Make sure a digit follows the exponent place.
1188
0
        match tri!(self.next_char_or_null()) {
1189
0
            b'0'..=b'9' => {}
1190
            _ => {
1191
0
                return Err(self.error(ErrorCode::InvalidNumber));
1192
            }
1193
        }
1194
1195
0
        while let b'0'..=b'9' = tri!(self.peek_or_null()) {
1196
0
            self.eat_char();
1197
0
        }
1198
1199
0
        Ok(())
1200
0
    }
Unexecuted instantiation: <serde_json::de::Deserializer<serde_json::read::SliceRead>>::ignore_exponent
Unexecuted instantiation: <serde_json::de::Deserializer<_>>::ignore_exponent
1201
1202
    #[cfg(feature = "raw_value")]
1203
    fn deserialize_raw_value<V>(&mut self, visitor: V) -> Result<V::Value>
1204
    where
1205
        V: de::Visitor<'de>,
1206
    {
1207
        self.parse_whitespace()?;
1208
        self.read.begin_raw_buffering();
1209
        self.ignore_value()?;
1210
        self.read.end_raw_buffering(visitor)
1211
    }
1212
}
1213
1214
impl FromStr for Number {
1215
    type Err = Error;
1216
1217
0
    fn from_str(s: &str) -> result::Result<Self, Self::Err> {
1218
0
        Deserializer::from_str(s)
1219
0
            .parse_any_signed_number()
1220
0
            .map(Into::into)
1221
0
    }
1222
}
1223
1224
#[cfg(not(feature = "float_roundtrip"))]
1225
static POW10: [f64; 309] = [
1226
    1e000, 1e001, 1e002, 1e003, 1e004, 1e005, 1e006, 1e007, 1e008, 1e009, //
1227
    1e010, 1e011, 1e012, 1e013, 1e014, 1e015, 1e016, 1e017, 1e018, 1e019, //
1228
    1e020, 1e021, 1e022, 1e023, 1e024, 1e025, 1e026, 1e027, 1e028, 1e029, //
1229
    1e030, 1e031, 1e032, 1e033, 1e034, 1e035, 1e036, 1e037, 1e038, 1e039, //
1230
    1e040, 1e041, 1e042, 1e043, 1e044, 1e045, 1e046, 1e047, 1e048, 1e049, //
1231
    1e050, 1e051, 1e052, 1e053, 1e054, 1e055, 1e056, 1e057, 1e058, 1e059, //
1232
    1e060, 1e061, 1e062, 1e063, 1e064, 1e065, 1e066, 1e067, 1e068, 1e069, //
1233
    1e070, 1e071, 1e072, 1e073, 1e074, 1e075, 1e076, 1e077, 1e078, 1e079, //
1234
    1e080, 1e081, 1e082, 1e083, 1e084, 1e085, 1e086, 1e087, 1e088, 1e089, //
1235
    1e090, 1e091, 1e092, 1e093, 1e094, 1e095, 1e096, 1e097, 1e098, 1e099, //
1236
    1e100, 1e101, 1e102, 1e103, 1e104, 1e105, 1e106, 1e107, 1e108, 1e109, //
1237
    1e110, 1e111, 1e112, 1e113, 1e114, 1e115, 1e116, 1e117, 1e118, 1e119, //
1238
    1e120, 1e121, 1e122, 1e123, 1e124, 1e125, 1e126, 1e127, 1e128, 1e129, //
1239
    1e130, 1e131, 1e132, 1e133, 1e134, 1e135, 1e136, 1e137, 1e138, 1e139, //
1240
    1e140, 1e141, 1e142, 1e143, 1e144, 1e145, 1e146, 1e147, 1e148, 1e149, //
1241
    1e150, 1e151, 1e152, 1e153, 1e154, 1e155, 1e156, 1e157, 1e158, 1e159, //
1242
    1e160, 1e161, 1e162, 1e163, 1e164, 1e165, 1e166, 1e167, 1e168, 1e169, //
1243
    1e170, 1e171, 1e172, 1e173, 1e174, 1e175, 1e176, 1e177, 1e178, 1e179, //
1244
    1e180, 1e181, 1e182, 1e183, 1e184, 1e185, 1e186, 1e187, 1e188, 1e189, //
1245
    1e190, 1e191, 1e192, 1e193, 1e194, 1e195, 1e196, 1e197, 1e198, 1e199, //
1246
    1e200, 1e201, 1e202, 1e203, 1e204, 1e205, 1e206, 1e207, 1e208, 1e209, //
1247
    1e210, 1e211, 1e212, 1e213, 1e214, 1e215, 1e216, 1e217, 1e218, 1e219, //
1248
    1e220, 1e221, 1e222, 1e223, 1e224, 1e225, 1e226, 1e227, 1e228, 1e229, //
1249
    1e230, 1e231, 1e232, 1e233, 1e234, 1e235, 1e236, 1e237, 1e238, 1e239, //
1250
    1e240, 1e241, 1e242, 1e243, 1e244, 1e245, 1e246, 1e247, 1e248, 1e249, //
1251
    1e250, 1e251, 1e252, 1e253, 1e254, 1e255, 1e256, 1e257, 1e258, 1e259, //
1252
    1e260, 1e261, 1e262, 1e263, 1e264, 1e265, 1e266, 1e267, 1e268, 1e269, //
1253
    1e270, 1e271, 1e272, 1e273, 1e274, 1e275, 1e276, 1e277, 1e278, 1e279, //
1254
    1e280, 1e281, 1e282, 1e283, 1e284, 1e285, 1e286, 1e287, 1e288, 1e289, //
1255
    1e290, 1e291, 1e292, 1e293, 1e294, 1e295, 1e296, 1e297, 1e298, 1e299, //
1256
    1e300, 1e301, 1e302, 1e303, 1e304, 1e305, 1e306, 1e307, 1e308,
1257
];
1258
1259
macro_rules! deserialize_number {
1260
    ($method:ident) => {
1261
0
        fn $method<V>(self, visitor: V) -> Result<V::Value>
1262
0
        where
1263
0
            V: de::Visitor<'de>,
1264
        {
1265
0
            self.deserialize_number(visitor)
1266
0
        }
Unexecuted instantiation: <&mut serde_json::de::Deserializer<serde_json::read::SliceRead> as serde::de::Deserializer>::deserialize_u64::<<usize as serde::de::Deserialize>::deserialize::PrimitiveVisitor>
Unexecuted instantiation: <&mut serde_json::de::Deserializer<_> as serde::de::Deserializer>::deserialize_i8::<_>
Unexecuted instantiation: <&mut serde_json::de::Deserializer<_> as serde::de::Deserializer>::deserialize_u8::<_>
Unexecuted instantiation: <&mut serde_json::de::Deserializer<_> as serde::de::Deserializer>::deserialize_f32::<_>
Unexecuted instantiation: <&mut serde_json::de::Deserializer<_> as serde::de::Deserializer>::deserialize_f64::<_>
Unexecuted instantiation: <&mut serde_json::de::Deserializer<_> as serde::de::Deserializer>::deserialize_i16::<_>
Unexecuted instantiation: <&mut serde_json::de::Deserializer<_> as serde::de::Deserializer>::deserialize_i32::<_>
Unexecuted instantiation: <&mut serde_json::de::Deserializer<_> as serde::de::Deserializer>::deserialize_i64::<_>
Unexecuted instantiation: <&mut serde_json::de::Deserializer<_> as serde::de::Deserializer>::deserialize_u16::<_>
Unexecuted instantiation: <&mut serde_json::de::Deserializer<_> as serde::de::Deserializer>::deserialize_u32::<_>
Unexecuted instantiation: <&mut serde_json::de::Deserializer<_> as serde::de::Deserializer>::deserialize_u64::<_>
1267
    };
1268
}
1269
1270
#[cfg(not(feature = "unbounded_depth"))]
1271
macro_rules! if_checking_recursion_limit {
1272
    ($($body:tt)*) => {
1273
        $($body)*
1274
    };
1275
}
1276
1277
#[cfg(feature = "unbounded_depth")]
1278
macro_rules! if_checking_recursion_limit {
1279
    ($this:ident $($body:tt)*) => {
1280
        if !$this.disable_recursion_limit {
1281
            $this $($body)*
1282
        }
1283
    };
1284
}
1285
1286
macro_rules! check_recursion {
1287
    ($this:ident $($body:tt)*) => {
1288
        if_checking_recursion_limit! {
1289
            $this.remaining_depth -= 1;
1290
            if $this.remaining_depth == 0 {
1291
                return Err($this.peek_error(ErrorCode::RecursionLimitExceeded));
1292
            }
1293
        }
1294
1295
        $this $($body)*
1296
1297
        if_checking_recursion_limit! {
1298
            $this.remaining_depth += 1;
1299
        }
1300
    };
1301
}
1302
1303
impl<'de, 'a, R: Read<'de>> de::Deserializer<'de> for &'a mut Deserializer<R> {
1304
    type Error = Error;
1305
1306
    #[inline]
1307
0
    fn deserialize_any<V>(self, visitor: V) -> Result<V::Value>
1308
0
    where
1309
0
        V: de::Visitor<'de>,
1310
    {
1311
0
        let peek = match tri!(self.parse_whitespace()) {
1312
0
            Some(b) => b,
1313
            None => {
1314
0
                return Err(self.peek_error(ErrorCode::EofWhileParsingValue));
1315
            }
1316
        };
1317
1318
0
        let value = match peek {
1319
            b'n' => {
1320
0
                self.eat_char();
1321
0
                tri!(self.parse_ident(b"ull"));
1322
0
                visitor.visit_unit()
1323
            }
1324
            b't' => {
1325
0
                self.eat_char();
1326
0
                tri!(self.parse_ident(b"rue"));
1327
0
                visitor.visit_bool(true)
1328
            }
1329
            b'f' => {
1330
0
                self.eat_char();
1331
0
                tri!(self.parse_ident(b"alse"));
1332
0
                visitor.visit_bool(false)
1333
            }
1334
            b'-' => {
1335
0
                self.eat_char();
1336
0
                tri!(self.parse_any_number(false)).visit(visitor)
1337
            }
1338
0
            b'0'..=b'9' => tri!(self.parse_any_number(true)).visit(visitor),
1339
            b'"' => {
1340
0
                self.eat_char();
1341
0
                self.scratch.clear();
1342
0
                match tri!(self.read.parse_str(&mut self.scratch)) {
1343
0
                    Reference::Borrowed(s) => visitor.visit_borrowed_str(s),
1344
0
                    Reference::Copied(s) => visitor.visit_str(s),
1345
                }
1346
            }
1347
            b'[' => {
1348
0
                check_recursion! {
1349
                    self.eat_char();
1350
0
                    let ret = visitor.visit_seq(SeqAccess::new(self));
1351
                }
1352
1353
0
                match (ret, self.end_seq()) {
1354
0
                    (Ok(ret), Ok(())) => Ok(ret),
1355
0
                    (Err(err), _) | (_, Err(err)) => Err(err),
1356
                }
1357
            }
1358
            b'{' => {
1359
0
                check_recursion! {
1360
                    self.eat_char();
1361
0
                    let ret = visitor.visit_map(MapAccess::new(self));
1362
                }
1363
1364
0
                match (ret, self.end_map()) {
1365
0
                    (Ok(ret), Ok(())) => Ok(ret),
1366
0
                    (Err(err), _) | (_, Err(err)) => Err(err),
1367
                }
1368
            }
1369
0
            _ => Err(self.peek_error(ErrorCode::ExpectedSomeValue)),
1370
        };
1371
1372
0
        match value {
1373
0
            Ok(value) => Ok(value),
1374
            // The de::Error impl creates errors with unknown line and column.
1375
            // Fill in the position here by looking at the current index in the
1376
            // input. There is no way to tell whether this should call `error`
1377
            // or `peek_error` so pick the one that seems correct more often.
1378
            // Worst case, the position is off by one character.
1379
0
            Err(err) => Err(self.fix_position(err)),
1380
        }
1381
0
    }
1382
1383
0
    fn deserialize_bool<V>(self, visitor: V) -> Result<V::Value>
1384
0
    where
1385
0
        V: de::Visitor<'de>,
1386
    {
1387
0
        let peek = match tri!(self.parse_whitespace()) {
1388
0
            Some(b) => b,
1389
            None => {
1390
0
                return Err(self.peek_error(ErrorCode::EofWhileParsingValue));
1391
            }
1392
        };
1393
1394
0
        let value = match peek {
1395
            b't' => {
1396
0
                self.eat_char();
1397
0
                tri!(self.parse_ident(b"rue"));
1398
0
                visitor.visit_bool(true)
1399
            }
1400
            b'f' => {
1401
0
                self.eat_char();
1402
0
                tri!(self.parse_ident(b"alse"));
1403
0
                visitor.visit_bool(false)
1404
            }
1405
0
            _ => Err(self.peek_invalid_type(&visitor)),
1406
        };
1407
1408
0
        match value {
1409
0
            Ok(value) => Ok(value),
1410
0
            Err(err) => Err(self.fix_position(err)),
1411
        }
1412
0
    }
Unexecuted instantiation: <&mut serde_json::de::Deserializer<serde_json::read::SliceRead> as serde::de::Deserializer>::deserialize_bool::<serde::de::impls::BoolVisitor>
Unexecuted instantiation: <&mut serde_json::de::Deserializer<_> as serde::de::Deserializer>::deserialize_bool::<_>
1413
1414
    deserialize_number!(deserialize_i8);
1415
    deserialize_number!(deserialize_i16);
1416
    deserialize_number!(deserialize_i32);
1417
    deserialize_number!(deserialize_i64);
1418
    deserialize_number!(deserialize_u8);
1419
    deserialize_number!(deserialize_u16);
1420
    deserialize_number!(deserialize_u32);
1421
    deserialize_number!(deserialize_u64);
1422
    #[cfg(not(feature = "float_roundtrip"))]
1423
    deserialize_number!(deserialize_f32);
1424
    deserialize_number!(deserialize_f64);
1425
1426
    #[cfg(feature = "float_roundtrip")]
1427
    fn deserialize_f32<V>(self, visitor: V) -> Result<V::Value>
1428
    where
1429
        V: de::Visitor<'de>,
1430
    {
1431
        self.single_precision = true;
1432
        let val = self.deserialize_number(visitor);
1433
        self.single_precision = false;
1434
        val
1435
    }
1436
1437
0
    fn deserialize_i128<V>(self, visitor: V) -> Result<V::Value>
1438
0
    where
1439
0
        V: de::Visitor<'de>,
1440
    {
1441
0
        let mut buf = String::new();
1442
1443
0
        match tri!(self.parse_whitespace()) {
1444
0
            Some(b'-') => {
1445
0
                self.eat_char();
1446
0
                buf.push('-');
1447
0
            }
1448
0
            Some(_) => {}
1449
            None => {
1450
0
                return Err(self.peek_error(ErrorCode::EofWhileParsingValue));
1451
            }
1452
        };
1453
1454
0
        tri!(self.scan_integer128(&mut buf));
1455
1456
0
        let value = match buf.parse() {
1457
0
            Ok(int) => visitor.visit_i128(int),
1458
            Err(_) => {
1459
0
                return Err(self.error(ErrorCode::NumberOutOfRange));
1460
            }
1461
        };
1462
1463
0
        match value {
1464
0
            Ok(value) => Ok(value),
1465
0
            Err(err) => Err(self.fix_position(err)),
1466
        }
1467
0
    }
1468
1469
0
    fn deserialize_u128<V>(self, visitor: V) -> Result<V::Value>
1470
0
    where
1471
0
        V: de::Visitor<'de>,
1472
    {
1473
0
        match tri!(self.parse_whitespace()) {
1474
            Some(b'-') => {
1475
0
                return Err(self.peek_error(ErrorCode::NumberOutOfRange));
1476
            }
1477
0
            Some(_) => {}
1478
            None => {
1479
0
                return Err(self.peek_error(ErrorCode::EofWhileParsingValue));
1480
            }
1481
        }
1482
1483
0
        let mut buf = String::new();
1484
0
        tri!(self.scan_integer128(&mut buf));
1485
1486
0
        let value = match buf.parse() {
1487
0
            Ok(int) => visitor.visit_u128(int),
1488
            Err(_) => {
1489
0
                return Err(self.error(ErrorCode::NumberOutOfRange));
1490
            }
1491
        };
1492
1493
0
        match value {
1494
0
            Ok(value) => Ok(value),
1495
0
            Err(err) => Err(self.fix_position(err)),
1496
        }
1497
0
    }
1498
1499
0
    fn deserialize_char<V>(self, visitor: V) -> Result<V::Value>
1500
0
    where
1501
0
        V: de::Visitor<'de>,
1502
    {
1503
0
        self.deserialize_str(visitor)
1504
0
    }
1505
1506
0
    fn deserialize_str<V>(self, visitor: V) -> Result<V::Value>
1507
0
    where
1508
0
        V: de::Visitor<'de>,
1509
    {
1510
0
        let peek = match tri!(self.parse_whitespace()) {
1511
0
            Some(b) => b,
1512
            None => {
1513
0
                return Err(self.peek_error(ErrorCode::EofWhileParsingValue));
1514
            }
1515
        };
1516
1517
0
        let value = match peek {
1518
            b'"' => {
1519
0
                self.eat_char();
1520
0
                self.scratch.clear();
1521
0
                match tri!(self.read.parse_str(&mut self.scratch)) {
1522
0
                    Reference::Borrowed(s) => visitor.visit_borrowed_str(s),
1523
0
                    Reference::Copied(s) => visitor.visit_str(s),
1524
                }
1525
            }
1526
0
            _ => Err(self.peek_invalid_type(&visitor)),
1527
        };
1528
1529
0
        match value {
1530
0
            Ok(value) => Ok(value),
1531
0
            Err(err) => Err(self.fix_position(err)),
1532
        }
1533
0
    }
Unexecuted instantiation: <&mut serde_json::de::Deserializer<serde_json::read::SliceRead> as serde::de::Deserializer>::deserialize_str::<serde::de::impls::StringVisitor>
Unexecuted instantiation: <&mut serde_json::de::Deserializer<serde_json::read::SliceRead> as serde::de::Deserializer>::deserialize_str::<serde::de::impls::PathBufVisitor>
Unexecuted instantiation: <&mut serde_json::de::Deserializer<serde_json::read::SliceRead> as serde::de::Deserializer>::deserialize_str::<<audio_processor::config::Processor as serde::de::Deserialize>::deserialize::__FieldVisitor>
Unexecuted instantiation: <&mut serde_json::de::Deserializer<_> as serde::de::Deserializer>::deserialize_str::<_>
1534
1535
0
    fn deserialize_string<V>(self, visitor: V) -> Result<V::Value>
1536
0
    where
1537
0
        V: de::Visitor<'de>,
1538
    {
1539
0
        self.deserialize_str(visitor)
1540
0
    }
Unexecuted instantiation: <&mut serde_json::de::Deserializer<serde_json::read::SliceRead> as serde::de::Deserializer>::deserialize_string::<serde::de::impls::StringVisitor>
Unexecuted instantiation: <&mut serde_json::de::Deserializer<serde_json::read::SliceRead> as serde::de::Deserializer>::deserialize_string::<serde::de::impls::PathBufVisitor>
Unexecuted instantiation: <&mut serde_json::de::Deserializer<_> as serde::de::Deserializer>::deserialize_string::<_>
1541
1542
    /// Parses a JSON string as bytes. Note that this function does not check
1543
    /// whether the bytes represent a valid UTF-8 string.
1544
    ///
1545
    /// The relevant part of the JSON specification is Section 8.2 of [RFC
1546
    /// 7159]:
1547
    ///
1548
    /// > When all the strings represented in a JSON text are composed entirely
1549
    /// > of Unicode characters (however escaped), then that JSON text is
1550
    /// > interoperable in the sense that all software implementations that
1551
    /// > parse it will agree on the contents of names and of string values in
1552
    /// > objects and arrays.
1553
    /// >
1554
    /// > However, the ABNF in this specification allows member names and string
1555
    /// > values to contain bit sequences that cannot encode Unicode characters;
1556
    /// > for example, "\uDEAD" (a single unpaired UTF-16 surrogate). Instances
1557
    /// > of this have been observed, for example, when a library truncates a
1558
    /// > UTF-16 string without checking whether the truncation split a
1559
    /// > surrogate pair.  The behavior of software that receives JSON texts
1560
    /// > containing such values is unpredictable; for example, implementations
1561
    /// > might return different values for the length of a string value or even
1562
    /// > suffer fatal runtime exceptions.
1563
    ///
1564
    /// [RFC 7159]: https://tools.ietf.org/html/rfc7159
1565
    ///
1566
    /// The behavior of serde_json is specified to fail on non-UTF-8 strings
1567
    /// when deserializing into Rust UTF-8 string types such as String, and
1568
    /// succeed with non-UTF-8 bytes when deserializing using this method.
1569
    ///
1570
    /// Escape sequences are processed as usual, and for `\uXXXX` escapes it is
1571
    /// still checked if the hex number represents a valid Unicode code point.
1572
    ///
1573
    /// # Examples
1574
    ///
1575
    /// You can use this to parse JSON strings containing invalid UTF-8 bytes,
1576
    /// or unpaired surrogates.
1577
    ///
1578
    /// ```
1579
    /// use serde_bytes::ByteBuf;
1580
    ///
1581
    /// fn look_at_bytes() -> Result<(), serde_json::Error> {
1582
    ///     let json_data = b"\"some bytes: \xe5\x00\xe5\"";
1583
    ///     let bytes: ByteBuf = serde_json::from_slice(json_data)?;
1584
    ///
1585
    ///     assert_eq!(b'\xe5', bytes[12]);
1586
    ///     assert_eq!(b'\0', bytes[13]);
1587
    ///     assert_eq!(b'\xe5', bytes[14]);
1588
    ///
1589
    ///     Ok(())
1590
    /// }
1591
    /// #
1592
    /// # look_at_bytes().unwrap();
1593
    /// ```
1594
    ///
1595
    /// Backslash escape sequences like `\n` are still interpreted and required
1596
    /// to be valid. `\u` escape sequences are required to represent a valid
1597
    /// Unicode code point or lone surrogate.
1598
    ///
1599
    /// ```
1600
    /// use serde_bytes::ByteBuf;
1601
    ///
1602
    /// fn look_at_bytes() -> Result<(), serde_json::Error> {
1603
    ///     let json_data = b"\"lone surrogate: \\uD801\"";
1604
    ///     let bytes: ByteBuf = serde_json::from_slice(json_data)?;
1605
    ///     let expected = b"lone surrogate: \xED\xA0\x81";
1606
    ///     assert_eq!(expected, bytes.as_slice());
1607
    ///     Ok(())
1608
    /// }
1609
    /// #
1610
    /// # look_at_bytes();
1611
    /// ```
1612
0
    fn deserialize_bytes<V>(self, visitor: V) -> Result<V::Value>
1613
0
    where
1614
0
        V: de::Visitor<'de>,
1615
    {
1616
0
        let peek = match tri!(self.parse_whitespace()) {
1617
0
            Some(b) => b,
1618
            None => {
1619
0
                return Err(self.peek_error(ErrorCode::EofWhileParsingValue));
1620
            }
1621
        };
1622
1623
0
        let value = match peek {
1624
            b'"' => {
1625
0
                self.eat_char();
1626
0
                self.scratch.clear();
1627
0
                match tri!(self.read.parse_str_raw(&mut self.scratch)) {
1628
0
                    Reference::Borrowed(b) => visitor.visit_borrowed_bytes(b),
1629
0
                    Reference::Copied(b) => visitor.visit_bytes(b),
1630
                }
1631
            }
1632
0
            b'[' => self.deserialize_seq(visitor),
1633
0
            _ => Err(self.peek_invalid_type(&visitor)),
1634
        };
1635
1636
0
        match value {
1637
0
            Ok(value) => Ok(value),
1638
0
            Err(err) => Err(self.fix_position(err)),
1639
        }
1640
0
    }
1641
1642
    #[inline]
1643
0
    fn deserialize_byte_buf<V>(self, visitor: V) -> Result<V::Value>
1644
0
    where
1645
0
        V: de::Visitor<'de>,
1646
    {
1647
0
        self.deserialize_bytes(visitor)
1648
0
    }
1649
1650
    /// Parses a `null` as a None, and any other values as a `Some(...)`.
1651
    #[inline]
1652
0
    fn deserialize_option<V>(self, visitor: V) -> Result<V::Value>
1653
0
    where
1654
0
        V: de::Visitor<'de>,
1655
    {
1656
0
        match tri!(self.parse_whitespace()) {
1657
            Some(b'n') => {
1658
0
                self.eat_char();
1659
0
                tri!(self.parse_ident(b"ull"));
1660
0
                visitor.visit_none()
1661
            }
1662
0
            _ => visitor.visit_some(self),
1663
        }
1664
0
    }
Unexecuted instantiation: <&mut serde_json::de::Deserializer<serde_json::read::SliceRead> as serde::de::Deserializer>::deserialize_option::<serde::de::impls::OptionVisitor<usize>>
Unexecuted instantiation: <&mut serde_json::de::Deserializer<_> as serde::de::Deserializer>::deserialize_option::<_>
1665
1666
0
    fn deserialize_unit<V>(self, visitor: V) -> Result<V::Value>
1667
0
    where
1668
0
        V: de::Visitor<'de>,
1669
    {
1670
0
        let peek = match tri!(self.parse_whitespace()) {
1671
0
            Some(b) => b,
1672
            None => {
1673
0
                return Err(self.peek_error(ErrorCode::EofWhileParsingValue));
1674
            }
1675
        };
1676
1677
0
        let value = match peek {
1678
            b'n' => {
1679
0
                self.eat_char();
1680
0
                tri!(self.parse_ident(b"ull"));
1681
0
                visitor.visit_unit()
1682
            }
1683
0
            _ => Err(self.peek_invalid_type(&visitor)),
1684
        };
1685
1686
0
        match value {
1687
0
            Ok(value) => Ok(value),
1688
0
            Err(err) => Err(self.fix_position(err)),
1689
        }
1690
0
    }
Unexecuted instantiation: <&mut serde_json::de::Deserializer<serde_json::read::SliceRead> as serde::de::Deserializer>::deserialize_unit::<serde::de::impls::UnitVisitor>
Unexecuted instantiation: <&mut serde_json::de::Deserializer<_> as serde::de::Deserializer>::deserialize_unit::<_>
1691
1692
0
    fn deserialize_unit_struct<V>(self, _name: &'static str, visitor: V) -> Result<V::Value>
1693
0
    where
1694
0
        V: de::Visitor<'de>,
1695
    {
1696
0
        self.deserialize_unit(visitor)
1697
0
    }
1698
1699
    /// Parses a newtype struct as the underlying value.
1700
    #[inline]
1701
0
    fn deserialize_newtype_struct<V>(self, name: &str, visitor: V) -> Result<V::Value>
1702
0
    where
1703
0
        V: de::Visitor<'de>,
1704
    {
1705
        #[cfg(feature = "raw_value")]
1706
        {
1707
            if name == crate::raw::TOKEN {
1708
                return self.deserialize_raw_value(visitor);
1709
            }
1710
        }
1711
1712
0
        let _ = name;
1713
0
        visitor.visit_newtype_struct(self)
1714
0
    }
1715
1716
0
    fn deserialize_seq<V>(self, visitor: V) -> Result<V::Value>
1717
0
    where
1718
0
        V: de::Visitor<'de>,
1719
    {
1720
0
        let peek = match tri!(self.parse_whitespace()) {
1721
0
            Some(b) => b,
1722
            None => {
1723
0
                return Err(self.peek_error(ErrorCode::EofWhileParsingValue));
1724
            }
1725
        };
1726
1727
0
        let value = match peek {
1728
            b'[' => {
1729
0
                check_recursion! {
1730
                    self.eat_char();
1731
0
                    let ret = visitor.visit_seq(SeqAccess::new(self));
1732
                }
1733
1734
0
                match (ret, self.end_seq()) {
1735
0
                    (Ok(ret), Ok(())) => Ok(ret),
1736
0
                    (Err(err), _) | (_, Err(err)) => Err(err),
1737
                }
1738
            }
1739
0
            _ => Err(self.peek_invalid_type(&visitor)),
1740
        };
1741
1742
0
        match value {
1743
0
            Ok(value) => Ok(value),
1744
0
            Err(err) => Err(self.fix_position(err)),
1745
        }
1746
0
    }
Unexecuted instantiation: <&mut serde_json::de::Deserializer<serde_json::read::SliceRead> as serde::de::Deserializer>::deserialize_seq::<<alloc::vec::Vec<_> as serde::de::Deserialize>::deserialize::VecVisitor<audio_processor::config::Processor>>
Unexecuted instantiation: <&mut serde_json::de::Deserializer<serde_json::read::SliceRead> as serde::de::Deserializer>::deserialize_seq::<<alloc::vec::Vec<_> as serde::de::Deserialize>::deserialize::VecVisitor<usize>>
Unexecuted instantiation: <&mut serde_json::de::Deserializer<_> as serde::de::Deserializer>::deserialize_seq::<_>
1747
1748
0
    fn deserialize_tuple<V>(self, _len: usize, visitor: V) -> Result<V::Value>
1749
0
    where
1750
0
        V: de::Visitor<'de>,
1751
    {
1752
0
        self.deserialize_seq(visitor)
1753
0
    }
1754
1755
0
    fn deserialize_tuple_struct<V>(
1756
0
        self,
1757
0
        _name: &'static str,
1758
0
        _len: usize,
1759
0
        visitor: V,
1760
0
    ) -> Result<V::Value>
1761
0
    where
1762
0
        V: de::Visitor<'de>,
1763
    {
1764
0
        self.deserialize_seq(visitor)
1765
0
    }
1766
1767
0
    fn deserialize_map<V>(self, visitor: V) -> Result<V::Value>
1768
0
    where
1769
0
        V: de::Visitor<'de>,
1770
    {
1771
0
        let peek = match tri!(self.parse_whitespace()) {
1772
0
            Some(b) => b,
1773
            None => {
1774
0
                return Err(self.peek_error(ErrorCode::EofWhileParsingValue));
1775
            }
1776
        };
1777
1778
0
        let value = match peek {
1779
            b'{' => {
1780
0
                check_recursion! {
1781
                    self.eat_char();
1782
0
                    let ret = visitor.visit_map(MapAccess::new(self));
1783
                }
1784
1785
0
                match (ret, self.end_map()) {
1786
0
                    (Ok(ret), Ok(())) => Ok(ret),
1787
0
                    (Err(err), _) | (_, Err(err)) => Err(err),
1788
                }
1789
            }
1790
0
            _ => Err(self.peek_invalid_type(&visitor)),
1791
        };
1792
1793
0
        match value {
1794
0
            Ok(value) => Ok(value),
1795
0
            Err(err) => Err(self.fix_position(err)),
1796
        }
1797
0
    }
1798
1799
0
    fn deserialize_struct<V>(
1800
0
        self,
1801
0
        _name: &'static str,
1802
0
        _fields: &'static [&'static str],
1803
0
        visitor: V,
1804
0
    ) -> Result<V::Value>
1805
0
    where
1806
0
        V: de::Visitor<'de>,
1807
    {
1808
0
        let peek = match tri!(self.parse_whitespace()) {
1809
0
            Some(b) => b,
1810
            None => {
1811
0
                return Err(self.peek_error(ErrorCode::EofWhileParsingValue));
1812
            }
1813
        };
1814
1815
0
        let value = match peek {
1816
            b'[' => {
1817
0
                check_recursion! {
1818
                    self.eat_char();
1819
0
                    let ret = visitor.visit_seq(SeqAccess::new(self));
1820
                }
1821
1822
0
                match (ret, self.end_seq()) {
1823
0
                    (Ok(ret), Ok(())) => Ok(ret),
1824
0
                    (Err(err), _) | (_, Err(err)) => Err(err),
1825
                }
1826
            }
1827
            b'{' => {
1828
0
                check_recursion! {
1829
                    self.eat_char();
1830
0
                    let ret = visitor.visit_map(MapAccess::new(self));
1831
                }
1832
1833
0
                match (ret, self.end_map()) {
1834
0
                    (Ok(ret), Ok(())) => Ok(ret),
1835
0
                    (Err(err), _) | (_, Err(err)) => Err(err),
1836
                }
1837
            }
1838
0
            _ => Err(self.peek_invalid_type(&visitor)),
1839
        };
1840
1841
0
        match value {
1842
0
            Ok(value) => Ok(value),
1843
0
            Err(err) => Err(self.fix_position(err)),
1844
        }
1845
0
    }
Unexecuted instantiation: <&mut serde_json::de::Deserializer<serde_json::read::SliceRead> as serde::de::Deserializer>::deserialize_struct::<<audio_processor::shape::Format as serde::de::Deserialize>::deserialize::__Visitor>
Unexecuted instantiation: <&mut serde_json::de::Deserializer<serde_json::read::SliceRead> as serde::de::Deserializer>::deserialize_struct::<<audio_processor::processors::peer::messages::Init as serde::de::Deserialize>::deserialize::__Visitor>
Unexecuted instantiation: <&mut serde_json::de::Deserializer<serde_json::read::SliceRead> as serde::de::Deserializer>::deserialize_struct::<<<audio_processor::config::Processor as serde::de::Deserialize>::deserialize::__Visitor as serde::de::Visitor>::visit_enum::__Visitor>
Unexecuted instantiation: <&mut serde_json::de::Deserializer<serde_json::read::SliceRead> as serde::de::Deserializer>::deserialize_struct::<<<audio_processor::config::Processor as serde::de::Deserialize>::deserialize::__Visitor as serde::de::Visitor>::visit_enum::__Visitor>
Unexecuted instantiation: <&mut serde_json::de::Deserializer<serde_json::read::SliceRead> as serde::de::Deserializer>::deserialize_struct::<<<audio_processor::config::Processor as serde::de::Deserialize>::deserialize::__Visitor as serde::de::Visitor>::visit_enum::__Visitor>
Unexecuted instantiation: <&mut serde_json::de::Deserializer<serde_json::read::SliceRead> as serde::de::Deserializer>::deserialize_struct::<<<audio_processor::config::Processor as serde::de::Deserialize>::deserialize::__Visitor as serde::de::Visitor>::visit_enum::__Visitor>
Unexecuted instantiation: <&mut serde_json::de::Deserializer<serde_json::read::SliceRead> as serde::de::Deserializer>::deserialize_struct::<<<audio_processor::config::Processor as serde::de::Deserialize>::deserialize::__Visitor as serde::de::Visitor>::visit_enum::__Visitor>
Unexecuted instantiation: <&mut serde_json::de::Deserializer<serde_json::read::SliceRead> as serde::de::Deserializer>::deserialize_struct::<<<audio_processor::config::Processor as serde::de::Deserialize>::deserialize::__Visitor as serde::de::Visitor>::visit_enum::__Visitor>
Unexecuted instantiation: <&mut serde_json::de::Deserializer<serde_json::read::SliceRead> as serde::de::Deserializer>::deserialize_struct::<<<audio_processor::config::Processor as serde::de::Deserialize>::deserialize::__Visitor as serde::de::Visitor>::visit_enum::__Visitor>
Unexecuted instantiation: <&mut serde_json::de::Deserializer<serde_json::read::SliceRead> as serde::de::Deserializer>::deserialize_struct::<<<audio_processor::config::Processor as serde::de::Deserialize>::deserialize::__Visitor as serde::de::Visitor>::visit_enum::__Visitor>
Unexecuted instantiation: <&mut serde_json::de::Deserializer<_> as serde::de::Deserializer>::deserialize_struct::<_>
1846
1847
    /// Parses an enum as an object like `{"$KEY":$VALUE}`, where $VALUE is either a straight
1848
    /// value, a `[..]`, or a `{..}`.
1849
    #[inline]
1850
0
    fn deserialize_enum<V>(
1851
0
        self,
1852
0
        _name: &str,
1853
0
        _variants: &'static [&'static str],
1854
0
        visitor: V,
1855
0
    ) -> Result<V::Value>
1856
0
    where
1857
0
        V: de::Visitor<'de>,
1858
    {
1859
0
        match tri!(self.parse_whitespace()) {
1860
            Some(b'{') => {
1861
0
                check_recursion! {
1862
                    self.eat_char();
1863
0
                    let value = tri!(visitor.visit_enum(VariantAccess::new(self)));
1864
                }
1865
1866
0
                match tri!(self.parse_whitespace()) {
1867
                    Some(b'}') => {
1868
0
                        self.eat_char();
1869
0
                        Ok(value)
1870
                    }
1871
0
                    Some(_) => Err(self.error(ErrorCode::ExpectedSomeValue)),
1872
0
                    None => Err(self.error(ErrorCode::EofWhileParsingObject)),
1873
                }
1874
            }
1875
0
            Some(b'"') => visitor.visit_enum(UnitVariantAccess::new(self)),
1876
0
            Some(_) => Err(self.peek_error(ErrorCode::ExpectedSomeValue)),
1877
0
            None => Err(self.peek_error(ErrorCode::EofWhileParsingValue)),
1878
        }
1879
0
    }
Unexecuted instantiation: <&mut serde_json::de::Deserializer<serde_json::read::SliceRead> as serde::de::Deserializer>::deserialize_enum::<<audio_processor::config::Processor as serde::de::Deserialize>::deserialize::__Visitor>
Unexecuted instantiation: <&mut serde_json::de::Deserializer<_> as serde::de::Deserializer>::deserialize_enum::<_>
1880
1881
0
    fn deserialize_identifier<V>(self, visitor: V) -> Result<V::Value>
1882
0
    where
1883
0
        V: de::Visitor<'de>,
1884
    {
1885
0
        self.deserialize_str(visitor)
1886
0
    }
Unexecuted instantiation: <&mut serde_json::de::Deserializer<serde_json::read::SliceRead> as serde::de::Deserializer>::deserialize_identifier::<<audio_processor::config::Processor as serde::de::Deserialize>::deserialize::__FieldVisitor>
Unexecuted instantiation: <&mut serde_json::de::Deserializer<_> as serde::de::Deserializer>::deserialize_identifier::<_>
1887
1888
0
    fn deserialize_ignored_any<V>(self, visitor: V) -> Result<V::Value>
1889
0
    where
1890
0
        V: de::Visitor<'de>,
1891
    {
1892
0
        tri!(self.ignore_value());
1893
0
        visitor.visit_unit()
1894
0
    }
Unexecuted instantiation: <&mut serde_json::de::Deserializer<serde_json::read::SliceRead> as serde::de::Deserializer>::deserialize_ignored_any::<serde::de::ignored_any::IgnoredAny>
Unexecuted instantiation: <&mut serde_json::de::Deserializer<_> as serde::de::Deserializer>::deserialize_ignored_any::<_>
1895
}
1896
1897
struct SeqAccess<'a, R: 'a> {
1898
    de: &'a mut Deserializer<R>,
1899
    first: bool,
1900
}
1901
1902
impl<'a, R: 'a> SeqAccess<'a, R> {
1903
0
    fn new(de: &'a mut Deserializer<R>) -> Self {
1904
0
        SeqAccess { de, first: true }
1905
0
    }
Unexecuted instantiation: <serde_json::de::SeqAccess<serde_json::read::SliceRead>>::new
Unexecuted instantiation: <serde_json::de::SeqAccess<serde_json::read::StrRead>>::new
1906
}
1907
1908
impl<'de, 'a, R: Read<'de> + 'a> de::SeqAccess<'de> for SeqAccess<'a, R> {
1909
    type Error = Error;
1910
1911
0
    fn next_element_seed<T>(&mut self, seed: T) -> Result<Option<T::Value>>
1912
0
    where
1913
0
        T: de::DeserializeSeed<'de>,
1914
    {
1915
0
        let peek = match tri!(self.de.parse_whitespace()) {
1916
            Some(b']') => {
1917
0
                return Ok(None);
1918
            }
1919
0
            Some(b',') if !self.first => {
1920
0
                self.de.eat_char();
1921
0
                tri!(self.de.parse_whitespace())
1922
            }
1923
0
            Some(b) => {
1924
0
                if self.first {
1925
0
                    self.first = false;
1926
0
                    Some(b)
1927
                } else {
1928
0
                    return Err(self.de.peek_error(ErrorCode::ExpectedListCommaOrEnd));
1929
                }
1930
            }
1931
            None => {
1932
0
                return Err(self.de.peek_error(ErrorCode::EofWhileParsingList));
1933
            }
1934
        };
1935
1936
0
        match peek {
1937
0
            Some(b']') => Err(self.de.peek_error(ErrorCode::TrailingComma)),
1938
0
            Some(_) => Ok(Some(tri!(seed.deserialize(&mut *self.de)))),
1939
0
            None => Err(self.de.peek_error(ErrorCode::EofWhileParsingValue)),
1940
        }
1941
0
    }
Unexecuted instantiation: <serde_json::de::SeqAccess<serde_json::read::SliceRead> as serde::de::SeqAccess>::next_element_seed::<core::marker::PhantomData<core::option::Option<usize>>>
Unexecuted instantiation: <serde_json::de::SeqAccess<serde_json::read::SliceRead> as serde::de::SeqAccess>::next_element_seed::<core::marker::PhantomData<alloc::vec::Vec<audio_processor::config::Processor>>>
Unexecuted instantiation: <serde_json::de::SeqAccess<serde_json::read::SliceRead> as serde::de::SeqAccess>::next_element_seed::<core::marker::PhantomData<alloc::vec::Vec<usize>>>
Unexecuted instantiation: <serde_json::de::SeqAccess<serde_json::read::SliceRead> as serde::de::SeqAccess>::next_element_seed::<core::marker::PhantomData<alloc::boxed::Box<audio_processor::config::Processor>>>
Unexecuted instantiation: <serde_json::de::SeqAccess<serde_json::read::SliceRead> as serde::de::SeqAccess>::next_element_seed::<core::marker::PhantomData<alloc::string::String>>
Unexecuted instantiation: <serde_json::de::SeqAccess<serde_json::read::SliceRead> as serde::de::SeqAccess>::next_element_seed::<core::marker::PhantomData<audio_processor::shape::Format>>
Unexecuted instantiation: <serde_json::de::SeqAccess<serde_json::read::SliceRead> as serde::de::SeqAccess>::next_element_seed::<core::marker::PhantomData<audio_processor::config::Processor>>
Unexecuted instantiation: <serde_json::de::SeqAccess<serde_json::read::SliceRead> as serde::de::SeqAccess>::next_element_seed::<core::marker::PhantomData<std::path::PathBuf>>
Unexecuted instantiation: <serde_json::de::SeqAccess<serde_json::read::SliceRead> as serde::de::SeqAccess>::next_element_seed::<core::marker::PhantomData<bool>>
Unexecuted instantiation: <serde_json::de::SeqAccess<serde_json::read::SliceRead> as serde::de::SeqAccess>::next_element_seed::<core::marker::PhantomData<usize>>
Unexecuted instantiation: <serde_json::de::SeqAccess<serde_json::read::StrRead> as serde::de::SeqAccess>::next_element_seed::<core::marker::PhantomData<serde_json::value::Value>>
1942
}
1943
1944
struct MapAccess<'a, R: 'a> {
1945
    de: &'a mut Deserializer<R>,
1946
    first: bool,
1947
}
1948
1949
impl<'a, R: 'a> MapAccess<'a, R> {
1950
0
    fn new(de: &'a mut Deserializer<R>) -> Self {
1951
0
        MapAccess { de, first: true }
1952
0
    }
Unexecuted instantiation: <serde_json::de::MapAccess<serde_json::read::SliceRead>>::new
Unexecuted instantiation: <serde_json::de::MapAccess<serde_json::read::StrRead>>::new
1953
}
1954
1955
impl<'de, 'a, R: Read<'de> + 'a> de::MapAccess<'de> for MapAccess<'a, R> {
1956
    type Error = Error;
1957
1958
0
    fn next_key_seed<K>(&mut self, seed: K) -> Result<Option<K::Value>>
1959
0
    where
1960
0
        K: de::DeserializeSeed<'de>,
1961
    {
1962
0
        let peek = match tri!(self.de.parse_whitespace()) {
1963
            Some(b'}') => {
1964
0
                return Ok(None);
1965
            }
1966
0
            Some(b',') if !self.first => {
1967
0
                self.de.eat_char();
1968
0
                tri!(self.de.parse_whitespace())
1969
            }
1970
0
            Some(b) => {
1971
0
                if self.first {
1972
0
                    self.first = false;
1973
0
                    Some(b)
1974
                } else {
1975
0
                    return Err(self.de.peek_error(ErrorCode::ExpectedObjectCommaOrEnd));
1976
                }
1977
            }
1978
            None => {
1979
0
                return Err(self.de.peek_error(ErrorCode::EofWhileParsingObject));
1980
            }
1981
        };
1982
1983
0
        match peek {
1984
0
            Some(b'"') => seed.deserialize(MapKey { de: &mut *self.de }).map(Some),
1985
0
            Some(b'}') => Err(self.de.peek_error(ErrorCode::TrailingComma)),
1986
0
            Some(_) => Err(self.de.peek_error(ErrorCode::KeyMustBeAString)),
1987
0
            None => Err(self.de.peek_error(ErrorCode::EofWhileParsingValue)),
1988
        }
1989
0
    }
Unexecuted instantiation: <serde_json::de::MapAccess<serde_json::read::SliceRead> as serde::de::MapAccess>::next_key_seed::<core::marker::PhantomData<<audio_processor::shape::Format as serde::de::Deserialize>::deserialize::__Field>>
Unexecuted instantiation: <serde_json::de::MapAccess<serde_json::read::SliceRead> as serde::de::MapAccess>::next_key_seed::<core::marker::PhantomData<<audio_processor::processors::peer::messages::Init as serde::de::Deserialize>::deserialize::__Field>>
Unexecuted instantiation: <serde_json::de::MapAccess<serde_json::read::SliceRead> as serde::de::MapAccess>::next_key_seed::<core::marker::PhantomData<<<audio_processor::config::Processor as serde::de::Deserialize>::deserialize::__Visitor as serde::de::Visitor>::visit_enum::__Field>>
Unexecuted instantiation: <serde_json::de::MapAccess<serde_json::read::SliceRead> as serde::de::MapAccess>::next_key_seed::<core::marker::PhantomData<<<audio_processor::config::Processor as serde::de::Deserialize>::deserialize::__Visitor as serde::de::Visitor>::visit_enum::__Field>>
Unexecuted instantiation: <serde_json::de::MapAccess<serde_json::read::SliceRead> as serde::de::MapAccess>::next_key_seed::<core::marker::PhantomData<<<audio_processor::config::Processor as serde::de::Deserialize>::deserialize::__Visitor as serde::de::Visitor>::visit_enum::__Field>>
Unexecuted instantiation: <serde_json::de::MapAccess<serde_json::read::SliceRead> as serde::de::MapAccess>::next_key_seed::<core::marker::PhantomData<<<audio_processor::config::Processor as serde::de::Deserialize>::deserialize::__Visitor as serde::de::Visitor>::visit_enum::__Field>>
Unexecuted instantiation: <serde_json::de::MapAccess<serde_json::read::SliceRead> as serde::de::MapAccess>::next_key_seed::<core::marker::PhantomData<<<audio_processor::config::Processor as serde::de::Deserialize>::deserialize::__Visitor as serde::de::Visitor>::visit_enum::__Field>>
Unexecuted instantiation: <serde_json::de::MapAccess<serde_json::read::SliceRead> as serde::de::MapAccess>::next_key_seed::<core::marker::PhantomData<<<audio_processor::config::Processor as serde::de::Deserialize>::deserialize::__Visitor as serde::de::Visitor>::visit_enum::__Field>>
Unexecuted instantiation: <serde_json::de::MapAccess<serde_json::read::SliceRead> as serde::de::MapAccess>::next_key_seed::<core::marker::PhantomData<<<audio_processor::config::Processor as serde::de::Deserialize>::deserialize::__Visitor as serde::de::Visitor>::visit_enum::__Field>>
Unexecuted instantiation: <serde_json::de::MapAccess<serde_json::read::SliceRead> as serde::de::MapAccess>::next_key_seed::<core::marker::PhantomData<<<audio_processor::config::Processor as serde::de::Deserialize>::deserialize::__Visitor as serde::de::Visitor>::visit_enum::__Field>>
Unexecuted instantiation: <serde_json::de::MapAccess<serde_json::read::StrRead> as serde::de::MapAccess>::next_key_seed::<core::marker::PhantomData<alloc::string::String>>
Unexecuted instantiation: <serde_json::de::MapAccess<serde_json::read::StrRead> as serde::de::MapAccess>::next_key_seed::<serde_json::value::de::KeyClassifier>
1990
1991
0
    fn next_value_seed<V>(&mut self, seed: V) -> Result<V::Value>
1992
0
    where
1993
0
        V: de::DeserializeSeed<'de>,
1994
    {
1995
0
        tri!(self.de.parse_object_colon());
1996
1997
0
        seed.deserialize(&mut *self.de)
1998
0
    }
Unexecuted instantiation: <serde_json::de::MapAccess<serde_json::read::SliceRead> as serde::de::MapAccess>::next_value_seed::<core::marker::PhantomData<core::option::Option<usize>>>
Unexecuted instantiation: <serde_json::de::MapAccess<serde_json::read::SliceRead> as serde::de::MapAccess>::next_value_seed::<core::marker::PhantomData<alloc::vec::Vec<audio_processor::config::Processor>>>
Unexecuted instantiation: <serde_json::de::MapAccess<serde_json::read::SliceRead> as serde::de::MapAccess>::next_value_seed::<core::marker::PhantomData<alloc::vec::Vec<usize>>>
Unexecuted instantiation: <serde_json::de::MapAccess<serde_json::read::SliceRead> as serde::de::MapAccess>::next_value_seed::<core::marker::PhantomData<alloc::boxed::Box<audio_processor::config::Processor>>>
Unexecuted instantiation: <serde_json::de::MapAccess<serde_json::read::SliceRead> as serde::de::MapAccess>::next_value_seed::<core::marker::PhantomData<serde::de::ignored_any::IgnoredAny>>
Unexecuted instantiation: <serde_json::de::MapAccess<serde_json::read::SliceRead> as serde::de::MapAccess>::next_value_seed::<core::marker::PhantomData<alloc::string::String>>
Unexecuted instantiation: <serde_json::de::MapAccess<serde_json::read::SliceRead> as serde::de::MapAccess>::next_value_seed::<core::marker::PhantomData<audio_processor::shape::Format>>
Unexecuted instantiation: <serde_json::de::MapAccess<serde_json::read::SliceRead> as serde::de::MapAccess>::next_value_seed::<core::marker::PhantomData<audio_processor::config::Processor>>
Unexecuted instantiation: <serde_json::de::MapAccess<serde_json::read::SliceRead> as serde::de::MapAccess>::next_value_seed::<core::marker::PhantomData<std::path::PathBuf>>
Unexecuted instantiation: <serde_json::de::MapAccess<serde_json::read::SliceRead> as serde::de::MapAccess>::next_value_seed::<core::marker::PhantomData<bool>>
Unexecuted instantiation: <serde_json::de::MapAccess<serde_json::read::SliceRead> as serde::de::MapAccess>::next_value_seed::<core::marker::PhantomData<usize>>
Unexecuted instantiation: <serde_json::de::MapAccess<serde_json::read::StrRead> as serde::de::MapAccess>::next_value_seed::<core::marker::PhantomData<serde_json::value::Value>>
1999
}
2000
2001
struct VariantAccess<'a, R: 'a> {
2002
    de: &'a mut Deserializer<R>,
2003
}
2004
2005
impl<'a, R: 'a> VariantAccess<'a, R> {
2006
0
    fn new(de: &'a mut Deserializer<R>) -> Self {
2007
0
        VariantAccess { de }
2008
0
    }
Unexecuted instantiation: <serde_json::de::VariantAccess<serde_json::read::SliceRead>>::new
Unexecuted instantiation: <serde_json::de::VariantAccess<_>>::new
2009
}
2010
2011
impl<'de, 'a, R: Read<'de> + 'a> de::EnumAccess<'de> for VariantAccess<'a, R> {
2012
    type Error = Error;
2013
    type Variant = Self;
2014
2015
0
    fn variant_seed<V>(self, seed: V) -> Result<(V::Value, Self)>
2016
0
    where
2017
0
        V: de::DeserializeSeed<'de>,
2018
    {
2019
0
        let val = tri!(seed.deserialize(&mut *self.de));
2020
0
        tri!(self.de.parse_object_colon());
2021
0
        Ok((val, self))
2022
0
    }
Unexecuted instantiation: <serde_json::de::VariantAccess<serde_json::read::SliceRead> as serde::de::EnumAccess>::variant_seed::<core::marker::PhantomData<<audio_processor::config::Processor as serde::de::Deserialize>::deserialize::__Field>>
Unexecuted instantiation: <serde_json::de::VariantAccess<_> as serde::de::EnumAccess>::variant_seed::<_>
2023
}
2024
2025
impl<'de, 'a, R: Read<'de> + 'a> de::VariantAccess<'de> for VariantAccess<'a, R> {
2026
    type Error = Error;
2027
2028
0
    fn unit_variant(self) -> Result<()> {
2029
0
        de::Deserialize::deserialize(self.de)
2030
0
    }
Unexecuted instantiation: <serde_json::de::VariantAccess<serde_json::read::SliceRead> as serde::de::VariantAccess>::unit_variant
Unexecuted instantiation: <serde_json::de::VariantAccess<_> as serde::de::VariantAccess>::unit_variant
2031
2032
0
    fn newtype_variant_seed<T>(self, seed: T) -> Result<T::Value>
2033
0
    where
2034
0
        T: de::DeserializeSeed<'de>,
2035
    {
2036
0
        seed.deserialize(self.de)
2037
0
    }
Unexecuted instantiation: <serde_json::de::VariantAccess<serde_json::read::SliceRead> as serde::de::VariantAccess>::newtype_variant_seed::<core::marker::PhantomData<audio_processor::config::PreloadedProcessor>>
Unexecuted instantiation: <serde_json::de::VariantAccess<_> as serde::de::VariantAccess>::newtype_variant_seed::<_>
2038
2039
0
    fn tuple_variant<V>(self, _len: usize, visitor: V) -> Result<V::Value>
2040
0
    where
2041
0
        V: de::Visitor<'de>,
2042
    {
2043
0
        de::Deserializer::deserialize_seq(self.de, visitor)
2044
0
    }
2045
2046
0
    fn struct_variant<V>(self, fields: &'static [&'static str], visitor: V) -> Result<V::Value>
2047
0
    where
2048
0
        V: de::Visitor<'de>,
2049
    {
2050
0
        de::Deserializer::deserialize_struct(self.de, "", fields, visitor)
2051
0
    }
Unexecuted instantiation: <serde_json::de::VariantAccess<serde_json::read::SliceRead> as serde::de::VariantAccess>::struct_variant::<<<audio_processor::config::Processor as serde::de::Deserialize>::deserialize::__Visitor as serde::de::Visitor>::visit_enum::__Visitor>
Unexecuted instantiation: <serde_json::de::VariantAccess<serde_json::read::SliceRead> as serde::de::VariantAccess>::struct_variant::<<<audio_processor::config::Processor as serde::de::Deserialize>::deserialize::__Visitor as serde::de::Visitor>::visit_enum::__Visitor>
Unexecuted instantiation: <serde_json::de::VariantAccess<serde_json::read::SliceRead> as serde::de::VariantAccess>::struct_variant::<<<audio_processor::config::Processor as serde::de::Deserialize>::deserialize::__Visitor as serde::de::Visitor>::visit_enum::__Visitor>
Unexecuted instantiation: <serde_json::de::VariantAccess<serde_json::read::SliceRead> as serde::de::VariantAccess>::struct_variant::<<<audio_processor::config::Processor as serde::de::Deserialize>::deserialize::__Visitor as serde::de::Visitor>::visit_enum::__Visitor>
Unexecuted instantiation: <serde_json::de::VariantAccess<serde_json::read::SliceRead> as serde::de::VariantAccess>::struct_variant::<<<audio_processor::config::Processor as serde::de::Deserialize>::deserialize::__Visitor as serde::de::Visitor>::visit_enum::__Visitor>
Unexecuted instantiation: <serde_json::de::VariantAccess<serde_json::read::SliceRead> as serde::de::VariantAccess>::struct_variant::<<<audio_processor::config::Processor as serde::de::Deserialize>::deserialize::__Visitor as serde::de::Visitor>::visit_enum::__Visitor>
Unexecuted instantiation: <serde_json::de::VariantAccess<serde_json::read::SliceRead> as serde::de::VariantAccess>::struct_variant::<<<audio_processor::config::Processor as serde::de::Deserialize>::deserialize::__Visitor as serde::de::Visitor>::visit_enum::__Visitor>
Unexecuted instantiation: <serde_json::de::VariantAccess<serde_json::read::SliceRead> as serde::de::VariantAccess>::struct_variant::<<<audio_processor::config::Processor as serde::de::Deserialize>::deserialize::__Visitor as serde::de::Visitor>::visit_enum::__Visitor>
Unexecuted instantiation: <serde_json::de::VariantAccess<_> as serde::de::VariantAccess>::struct_variant::<_>
2052
}
2053
2054
struct UnitVariantAccess<'a, R: 'a> {
2055
    de: &'a mut Deserializer<R>,
2056
}
2057
2058
impl<'a, R: 'a> UnitVariantAccess<'a, R> {
2059
0
    fn new(de: &'a mut Deserializer<R>) -> Self {
2060
0
        UnitVariantAccess { de }
2061
0
    }
Unexecuted instantiation: <serde_json::de::UnitVariantAccess<serde_json::read::SliceRead>>::new
Unexecuted instantiation: <serde_json::de::UnitVariantAccess<_>>::new
2062
}
2063
2064
impl<'de, 'a, R: Read<'de> + 'a> de::EnumAccess<'de> for UnitVariantAccess<'a, R> {
2065
    type Error = Error;
2066
    type Variant = Self;
2067
2068
0
    fn variant_seed<V>(self, seed: V) -> Result<(V::Value, Self)>
2069
0
    where
2070
0
        V: de::DeserializeSeed<'de>,
2071
    {
2072
0
        let variant = tri!(seed.deserialize(&mut *self.de));
2073
0
        Ok((variant, self))
2074
0
    }
Unexecuted instantiation: <serde_json::de::UnitVariantAccess<serde_json::read::SliceRead> as serde::de::EnumAccess>::variant_seed::<core::marker::PhantomData<<audio_processor::config::Processor as serde::de::Deserialize>::deserialize::__Field>>
Unexecuted instantiation: <serde_json::de::UnitVariantAccess<_> as serde::de::EnumAccess>::variant_seed::<_>
2075
}
2076
2077
impl<'de, 'a, R: Read<'de> + 'a> de::VariantAccess<'de> for UnitVariantAccess<'a, R> {
2078
    type Error = Error;
2079
2080
0
    fn unit_variant(self) -> Result<()> {
2081
0
        Ok(())
2082
0
    }
Unexecuted instantiation: <serde_json::de::UnitVariantAccess<serde_json::read::SliceRead> as serde::de::VariantAccess>::unit_variant
Unexecuted instantiation: <serde_json::de::UnitVariantAccess<_> as serde::de::VariantAccess>::unit_variant
2083
2084
0
    fn newtype_variant_seed<T>(self, _seed: T) -> Result<T::Value>
2085
0
    where
2086
0
        T: de::DeserializeSeed<'de>,
2087
    {
2088
0
        Err(de::Error::invalid_type(
2089
0
            Unexpected::UnitVariant,
2090
0
            &"newtype variant",
2091
0
        ))
2092
0
    }
Unexecuted instantiation: <serde_json::de::UnitVariantAccess<serde_json::read::SliceRead> as serde::de::VariantAccess>::newtype_variant_seed::<core::marker::PhantomData<audio_processor::config::PreloadedProcessor>>
Unexecuted instantiation: <serde_json::de::UnitVariantAccess<_> as serde::de::VariantAccess>::newtype_variant_seed::<_>
2093
2094
0
    fn tuple_variant<V>(self, _len: usize, _visitor: V) -> Result<V::Value>
2095
0
    where
2096
0
        V: de::Visitor<'de>,
2097
    {
2098
0
        Err(de::Error::invalid_type(
2099
0
            Unexpected::UnitVariant,
2100
0
            &"tuple variant",
2101
0
        ))
2102
0
    }
2103
2104
0
    fn struct_variant<V>(self, _fields: &'static [&'static str], _visitor: V) -> Result<V::Value>
2105
0
    where
2106
0
        V: de::Visitor<'de>,
2107
    {
2108
0
        Err(de::Error::invalid_type(
2109
0
            Unexpected::UnitVariant,
2110
0
            &"struct variant",
2111
0
        ))
2112
0
    }
Unexecuted instantiation: <serde_json::de::UnitVariantAccess<serde_json::read::SliceRead> as serde::de::VariantAccess>::struct_variant::<<<audio_processor::config::Processor as serde::de::Deserialize>::deserialize::__Visitor as serde::de::Visitor>::visit_enum::__Visitor>
Unexecuted instantiation: <serde_json::de::UnitVariantAccess<serde_json::read::SliceRead> as serde::de::VariantAccess>::struct_variant::<<<audio_processor::config::Processor as serde::de::Deserialize>::deserialize::__Visitor as serde::de::Visitor>::visit_enum::__Visitor>
Unexecuted instantiation: <serde_json::de::UnitVariantAccess<serde_json::read::SliceRead> as serde::de::VariantAccess>::struct_variant::<<<audio_processor::config::Processor as serde::de::Deserialize>::deserialize::__Visitor as serde::de::Visitor>::visit_enum::__Visitor>
Unexecuted instantiation: <serde_json::de::UnitVariantAccess<serde_json::read::SliceRead> as serde::de::VariantAccess>::struct_variant::<<<audio_processor::config::Processor as serde::de::Deserialize>::deserialize::__Visitor as serde::de::Visitor>::visit_enum::__Visitor>
Unexecuted instantiation: <serde_json::de::UnitVariantAccess<serde_json::read::SliceRead> as serde::de::VariantAccess>::struct_variant::<<<audio_processor::config::Processor as serde::de::Deserialize>::deserialize::__Visitor as serde::de::Visitor>::visit_enum::__Visitor>
Unexecuted instantiation: <serde_json::de::UnitVariantAccess<serde_json::read::SliceRead> as serde::de::VariantAccess>::struct_variant::<<<audio_processor::config::Processor as serde::de::Deserialize>::deserialize::__Visitor as serde::de::Visitor>::visit_enum::__Visitor>
Unexecuted instantiation: <serde_json::de::UnitVariantAccess<serde_json::read::SliceRead> as serde::de::VariantAccess>::struct_variant::<<<audio_processor::config::Processor as serde::de::Deserialize>::deserialize::__Visitor as serde::de::Visitor>::visit_enum::__Visitor>
Unexecuted instantiation: <serde_json::de::UnitVariantAccess<serde_json::read::SliceRead> as serde::de::VariantAccess>::struct_variant::<<<audio_processor::config::Processor as serde::de::Deserialize>::deserialize::__Visitor as serde::de::Visitor>::visit_enum::__Visitor>
Unexecuted instantiation: <serde_json::de::UnitVariantAccess<_> as serde::de::VariantAccess>::struct_variant::<_>
2113
}
2114
2115
/// Only deserialize from this after peeking a '"' byte! Otherwise it may
2116
/// deserialize invalid JSON successfully.
2117
struct MapKey<'a, R: 'a> {
2118
    de: &'a mut Deserializer<R>,
2119
}
2120
2121
macro_rules! deserialize_integer_key {
2122
    ($method:ident => $visit:ident) => {
2123
0
        fn $method<V>(self, visitor: V) -> Result<V::Value>
2124
0
        where
2125
0
            V: de::Visitor<'de>,
2126
        {
2127
0
            self.de.eat_char();
2128
0
            self.de.scratch.clear();
2129
0
            let string = tri!(self.de.read.parse_str(&mut self.de.scratch));
2130
0
            match (string.parse(), string) {
2131
0
                (Ok(integer), _) => visitor.$visit(integer),
2132
0
                (Err(_), Reference::Borrowed(s)) => visitor.visit_borrowed_str(s),
2133
0
                (Err(_), Reference::Copied(s)) => visitor.visit_str(s),
2134
            }
2135
0
        }
Unexecuted instantiation: <serde_json::de::MapKey<_> as serde::de::Deserializer>::deserialize_i8::<_>
Unexecuted instantiation: <serde_json::de::MapKey<_> as serde::de::Deserializer>::deserialize_u8::<_>
Unexecuted instantiation: <serde_json::de::MapKey<_> as serde::de::Deserializer>::deserialize_i16::<_>
Unexecuted instantiation: <serde_json::de::MapKey<_> as serde::de::Deserializer>::deserialize_i32::<_>
Unexecuted instantiation: <serde_json::de::MapKey<_> as serde::de::Deserializer>::deserialize_i64::<_>
Unexecuted instantiation: <serde_json::de::MapKey<_> as serde::de::Deserializer>::deserialize_u16::<_>
Unexecuted instantiation: <serde_json::de::MapKey<_> as serde::de::Deserializer>::deserialize_u32::<_>
Unexecuted instantiation: <serde_json::de::MapKey<_> as serde::de::Deserializer>::deserialize_u64::<_>
Unexecuted instantiation: <serde_json::de::MapKey<_> as serde::de::Deserializer>::deserialize_i128::<_>
Unexecuted instantiation: <serde_json::de::MapKey<_> as serde::de::Deserializer>::deserialize_u128::<_>
2136
    };
2137
}
2138
2139
impl<'de, 'a, R> de::Deserializer<'de> for MapKey<'a, R>
2140
where
2141
    R: Read<'de>,
2142
{
2143
    type Error = Error;
2144
2145
    #[inline]
2146
0
    fn deserialize_any<V>(self, visitor: V) -> Result<V::Value>
2147
0
    where
2148
0
        V: de::Visitor<'de>,
2149
    {
2150
0
        self.de.eat_char();
2151
0
        self.de.scratch.clear();
2152
0
        match tri!(self.de.read.parse_str(&mut self.de.scratch)) {
2153
0
            Reference::Borrowed(s) => visitor.visit_borrowed_str(s),
2154
0
            Reference::Copied(s) => visitor.visit_str(s),
2155
        }
2156
0
    }
Unexecuted instantiation: <serde_json::de::MapKey<serde_json::read::SliceRead> as serde::de::Deserializer>::deserialize_any::<<audio_processor::shape::Format as serde::de::Deserialize>::deserialize::__FieldVisitor>
Unexecuted instantiation: <serde_json::de::MapKey<serde_json::read::SliceRead> as serde::de::Deserializer>::deserialize_any::<<audio_processor::processors::peer::messages::Init as serde::de::Deserialize>::deserialize::__FieldVisitor>
Unexecuted instantiation: <serde_json::de::MapKey<serde_json::read::SliceRead> as serde::de::Deserializer>::deserialize_any::<<<audio_processor::config::Processor as serde::de::Deserialize>::deserialize::__Visitor as serde::de::Visitor>::visit_enum::__FieldVisitor>
Unexecuted instantiation: <serde_json::de::MapKey<serde_json::read::SliceRead> as serde::de::Deserializer>::deserialize_any::<<<audio_processor::config::Processor as serde::de::Deserialize>::deserialize::__Visitor as serde::de::Visitor>::visit_enum::__FieldVisitor>
Unexecuted instantiation: <serde_json::de::MapKey<serde_json::read::SliceRead> as serde::de::Deserializer>::deserialize_any::<<<audio_processor::config::Processor as serde::de::Deserialize>::deserialize::__Visitor as serde::de::Visitor>::visit_enum::__FieldVisitor>
Unexecuted instantiation: <serde_json::de::MapKey<serde_json::read::SliceRead> as serde::de::Deserializer>::deserialize_any::<<<audio_processor::config::Processor as serde::de::Deserialize>::deserialize::__Visitor as serde::de::Visitor>::visit_enum::__FieldVisitor>
Unexecuted instantiation: <serde_json::de::MapKey<serde_json::read::SliceRead> as serde::de::Deserializer>::deserialize_any::<<<audio_processor::config::Processor as serde::de::Deserialize>::deserialize::__Visitor as serde::de::Visitor>::visit_enum::__FieldVisitor>
Unexecuted instantiation: <serde_json::de::MapKey<serde_json::read::SliceRead> as serde::de::Deserializer>::deserialize_any::<<<audio_processor::config::Processor as serde::de::Deserialize>::deserialize::__Visitor as serde::de::Visitor>::visit_enum::__FieldVisitor>
Unexecuted instantiation: <serde_json::de::MapKey<serde_json::read::SliceRead> as serde::de::Deserializer>::deserialize_any::<<<audio_processor::config::Processor as serde::de::Deserialize>::deserialize::__Visitor as serde::de::Visitor>::visit_enum::__FieldVisitor>
Unexecuted instantiation: <serde_json::de::MapKey<serde_json::read::SliceRead> as serde::de::Deserializer>::deserialize_any::<<<audio_processor::config::Processor as serde::de::Deserialize>::deserialize::__Visitor as serde::de::Visitor>::visit_enum::__FieldVisitor>
Unexecuted instantiation: <serde_json::de::MapKey<serde_json::read::StrRead> as serde::de::Deserializer>::deserialize_any::<serde_json::value::de::KeyClassifier>
Unexecuted instantiation: <serde_json::de::MapKey<serde_json::read::StrRead> as serde::de::Deserializer>::deserialize_any::<serde::de::impls::StringVisitor>
2157
2158
    deserialize_integer_key!(deserialize_i8 => visit_i8);
2159
    deserialize_integer_key!(deserialize_i16 => visit_i16);
2160
    deserialize_integer_key!(deserialize_i32 => visit_i32);
2161
    deserialize_integer_key!(deserialize_i64 => visit_i64);
2162
    deserialize_integer_key!(deserialize_i128 => visit_i128);
2163
    deserialize_integer_key!(deserialize_u8 => visit_u8);
2164
    deserialize_integer_key!(deserialize_u16 => visit_u16);
2165
    deserialize_integer_key!(deserialize_u32 => visit_u32);
2166
    deserialize_integer_key!(deserialize_u64 => visit_u64);
2167
    deserialize_integer_key!(deserialize_u128 => visit_u128);
2168
2169
    #[inline]
2170
0
    fn deserialize_option<V>(self, visitor: V) -> Result<V::Value>
2171
0
    where
2172
0
        V: de::Visitor<'de>,
2173
    {
2174
        // Map keys cannot be null.
2175
0
        visitor.visit_some(self)
2176
0
    }
2177
2178
    #[inline]
2179
0
    fn deserialize_newtype_struct<V>(self, name: &'static str, visitor: V) -> Result<V::Value>
2180
0
    where
2181
0
        V: de::Visitor<'de>,
2182
    {
2183
        #[cfg(feature = "raw_value")]
2184
        {
2185
            if name == crate::raw::TOKEN {
2186
                return self.de.deserialize_raw_value(visitor);
2187
            }
2188
        }
2189
2190
0
        let _ = name;
2191
0
        visitor.visit_newtype_struct(self)
2192
0
    }
2193
2194
    #[inline]
2195
0
    fn deserialize_enum<V>(
2196
0
        self,
2197
0
        name: &'static str,
2198
0
        variants: &'static [&'static str],
2199
0
        visitor: V,
2200
0
    ) -> Result<V::Value>
2201
0
    where
2202
0
        V: de::Visitor<'de>,
2203
    {
2204
0
        self.de.deserialize_enum(name, variants, visitor)
2205
0
    }
2206
2207
    #[inline]
2208
0
    fn deserialize_bytes<V>(self, visitor: V) -> Result<V::Value>
2209
0
    where
2210
0
        V: de::Visitor<'de>,
2211
    {
2212
0
        self.de.deserialize_bytes(visitor)
2213
0
    }
2214
2215
    #[inline]
2216
0
    fn deserialize_byte_buf<V>(self, visitor: V) -> Result<V::Value>
2217
0
    where
2218
0
        V: de::Visitor<'de>,
2219
    {
2220
0
        self.de.deserialize_bytes(visitor)
2221
0
    }
2222
2223
    forward_to_deserialize_any! {
2224
        bool f32 f64 char str string unit unit_struct seq tuple tuple_struct map
2225
        struct identifier ignored_any
2226
    }
2227
}
2228
2229
//////////////////////////////////////////////////////////////////////////////
2230
2231
/// Iterator that deserializes a stream into multiple JSON values.
2232
///
2233
/// A stream deserializer can be created from any JSON deserializer using the
2234
/// `Deserializer::into_iter` method.
2235
///
2236
/// The data can consist of any JSON value. Values need to be a self-delineating value e.g.
2237
/// arrays, objects, or strings, or be followed by whitespace or a self-delineating value.
2238
///
2239
/// ```
2240
/// use serde_json::{Deserializer, Value};
2241
///
2242
/// fn main() {
2243
///     let data = "{\"k\": 3}1\"cool\"\"stuff\" 3{}  [0, 1, 2]";
2244
///
2245
///     let stream = Deserializer::from_str(data).into_iter::<Value>();
2246
///
2247
///     for value in stream {
2248
///         println!("{}", value.unwrap());
2249
///     }
2250
/// }
2251
/// ```
2252
pub struct StreamDeserializer<'de, R, T> {
2253
    de: Deserializer<R>,
2254
    offset: usize,
2255
    failed: bool,
2256
    output: PhantomData<T>,
2257
    lifetime: PhantomData<&'de ()>,
2258
}
2259
2260
impl<'de, R, T> StreamDeserializer<'de, R, T>
2261
where
2262
    R: read::Read<'de>,
2263
    T: de::Deserialize<'de>,
2264
{
2265
    /// Create a JSON stream deserializer from one of the possible serde_json
2266
    /// input sources.
2267
    ///
2268
    /// Typically it is more convenient to use one of these methods instead:
2269
    ///
2270
    ///   - Deserializer::from_str(...).into_iter()
2271
    ///   - Deserializer::from_slice(...).into_iter()
2272
    ///   - Deserializer::from_reader(...).into_iter()
2273
0
    pub fn new(read: R) -> Self {
2274
0
        let offset = read.byte_offset();
2275
0
        StreamDeserializer {
2276
0
            de: Deserializer::new(read),
2277
0
            offset,
2278
0
            failed: false,
2279
0
            output: PhantomData,
2280
0
            lifetime: PhantomData,
2281
0
        }
2282
0
    }
2283
2284
    /// Returns the number of bytes so far deserialized into a successful `T`.
2285
    ///
2286
    /// If a stream deserializer returns an EOF error, new data can be joined to
2287
    /// `old_data[stream.byte_offset()..]` to try again.
2288
    ///
2289
    /// ```
2290
    /// let data = b"[0] [1] [";
2291
    ///
2292
    /// let de = serde_json::Deserializer::from_slice(data);
2293
    /// let mut stream = de.into_iter::<Vec<i32>>();
2294
    /// assert_eq!(0, stream.byte_offset());
2295
    ///
2296
    /// println!("{:?}", stream.next()); // [0]
2297
    /// assert_eq!(3, stream.byte_offset());
2298
    ///
2299
    /// println!("{:?}", stream.next()); // [1]
2300
    /// assert_eq!(7, stream.byte_offset());
2301
    ///
2302
    /// println!("{:?}", stream.next()); // error
2303
    /// assert_eq!(8, stream.byte_offset());
2304
    ///
2305
    /// // If err.is_eof(), can join the remaining data to new data and continue.
2306
    /// let remaining = &data[stream.byte_offset()..];
2307
    /// ```
2308
    ///
2309
    /// *Note:* In the future this method may be changed to return the number of
2310
    /// bytes so far deserialized into a successful T *or* syntactically valid
2311
    /// JSON skipped over due to a type error. See [serde-rs/json#70] for an
2312
    /// example illustrating this.
2313
    ///
2314
    /// [serde-rs/json#70]: https://github.com/serde-rs/json/issues/70
2315
0
    pub fn byte_offset(&self) -> usize {
2316
0
        self.offset
2317
0
    }
2318
2319
0
    fn peek_end_of_value(&mut self) -> Result<()> {
2320
0
        match tri!(self.de.peek()) {
2321
            Some(b' ') | Some(b'\n') | Some(b'\t') | Some(b'\r') | Some(b'"') | Some(b'[')
2322
0
            | Some(b']') | Some(b'{') | Some(b'}') | Some(b',') | Some(b':') | None => Ok(()),
2323
            Some(_) => {
2324
0
                let position = self.de.read.peek_position();
2325
0
                Err(Error::syntax(
2326
0
                    ErrorCode::TrailingCharacters,
2327
0
                    position.line,
2328
0
                    position.column,
2329
0
                ))
2330
            }
2331
        }
2332
0
    }
2333
}
2334
2335
impl<'de, R, T> Iterator for StreamDeserializer<'de, R, T>
2336
where
2337
    R: Read<'de>,
2338
    T: de::Deserialize<'de>,
2339
{
2340
    type Item = Result<T>;
2341
2342
0
    fn next(&mut self) -> Option<Result<T>> {
2343
0
        if R::should_early_return_if_failed && self.failed {
2344
0
            return None;
2345
0
        }
2346
2347
        // skip whitespaces, if any
2348
        // this helps with trailing whitespaces, since whitespaces between
2349
        // values are handled for us.
2350
0
        match self.de.parse_whitespace() {
2351
            Ok(None) => {
2352
0
                self.offset = self.de.read.byte_offset();
2353
0
                None
2354
            }
2355
0
            Ok(Some(b)) => {
2356
                // If the value does not have a clear way to show the end of the value
2357
                // (like numbers, null, true etc.) we have to look for whitespace or
2358
                // the beginning of a self-delineated value.
2359
0
                let self_delineated_value = match b {
2360
0
                    b'[' | b'"' | b'{' => true,
2361
0
                    _ => false,
2362
                };
2363
0
                self.offset = self.de.read.byte_offset();
2364
0
                let result = de::Deserialize::deserialize(&mut self.de);
2365
2366
0
                Some(match result {
2367
0
                    Ok(value) => {
2368
0
                        self.offset = self.de.read.byte_offset();
2369
0
                        if self_delineated_value {
2370
0
                            Ok(value)
2371
                        } else {
2372
0
                            self.peek_end_of_value().map(|_| value)
2373
                        }
2374
                    }
2375
0
                    Err(e) => {
2376
0
                        self.de.read.set_failed(&mut self.failed);
2377
0
                        Err(e)
2378
                    }
2379
                })
2380
            }
2381
0
            Err(e) => {
2382
0
                self.de.read.set_failed(&mut self.failed);
2383
0
                Some(Err(e))
2384
            }
2385
        }
2386
0
    }
2387
}
2388
2389
impl<'de, R, T> FusedIterator for StreamDeserializer<'de, R, T>
2390
where
2391
    R: Read<'de> + Fused,
2392
    T: de::Deserialize<'de>,
2393
{
2394
}
2395
2396
//////////////////////////////////////////////////////////////////////////////
2397
2398
0
fn from_trait<'de, R, T>(read: R) -> Result<T>
2399
0
where
2400
0
    R: Read<'de>,
2401
0
    T: de::Deserialize<'de>,
2402
{
2403
0
    let mut de = Deserializer::new(read);
2404
0
    let value = tri!(de::Deserialize::deserialize(&mut de));
2405
2406
    // Make sure the whole stream has been consumed.
2407
0
    tri!(de.end());
2408
0
    Ok(value)
2409
0
}
Unexecuted instantiation: serde_json::de::from_trait::<serde_json::read::SliceRead, audio_processor::shape::Format>
Unexecuted instantiation: serde_json::de::from_trait::<serde_json::read::SliceRead, audio_processor::processors::peer::messages::Init>
Unexecuted instantiation: serde_json::de::from_trait::<serde_json::read::StrRead, serde_json::value::Value>
2410
2411
/// Deserialize an instance of type `T` from an IO stream of JSON.
2412
///
2413
/// The content of the IO stream is deserialized directly from the stream
2414
/// without being buffered in memory by serde_json.
2415
///
2416
/// When reading from a source against which short reads are not efficient, such
2417
/// as a [`File`], you will want to apply your own buffering because serde_json
2418
/// will not buffer the input. See [`std::io::BufReader`].
2419
///
2420
/// It is expected that the input stream ends after the deserialized object.
2421
/// If the stream does not end, such as in the case of a persistent socket connection,
2422
/// this function will not return. It is possible instead to deserialize from a prefix of an input
2423
/// stream without looking for EOF by managing your own [`Deserializer`].
2424
///
2425
/// Note that counter to intuition, this function is usually slower than
2426
/// reading a file completely into memory and then applying [`from_str`]
2427
/// or [`from_slice`] on it. See [issue #160].
2428
///
2429
/// [`File`]: https://doc.rust-lang.org/std/fs/struct.File.html
2430
/// [`std::io::BufReader`]: https://doc.rust-lang.org/std/io/struct.BufReader.html
2431
/// [`from_str`]: ./fn.from_str.html
2432
/// [`from_slice`]: ./fn.from_slice.html
2433
/// [issue #160]: https://github.com/serde-rs/json/issues/160
2434
///
2435
/// # Example
2436
///
2437
/// Reading the contents of a file.
2438
///
2439
/// ```
2440
/// use serde::Deserialize;
2441
///
2442
/// use std::error::Error;
2443
/// use std::fs::File;
2444
/// use std::io::BufReader;
2445
/// use std::path::Path;
2446
///
2447
/// #[derive(Deserialize, Debug)]
2448
/// struct User {
2449
///     fingerprint: String,
2450
///     location: String,
2451
/// }
2452
///
2453
/// fn read_user_from_file<P: AsRef<Path>>(path: P) -> Result<User, Box<dyn Error>> {
2454
///     // Open the file in read-only mode with buffer.
2455
///     let file = File::open(path)?;
2456
///     let reader = BufReader::new(file);
2457
///
2458
///     // Read the JSON contents of the file as an instance of `User`.
2459
///     let u = serde_json::from_reader(reader)?;
2460
///
2461
///     // Return the `User`.
2462
///     Ok(u)
2463
/// }
2464
///
2465
/// fn main() {
2466
/// # }
2467
/// # fn fake_main() {
2468
///     let u = read_user_from_file("test.json").unwrap();
2469
///     println!("{:#?}", u);
2470
/// }
2471
/// ```
2472
///
2473
/// Reading from a persistent socket connection.
2474
///
2475
/// ```
2476
/// use serde::Deserialize;
2477
///
2478
/// use std::error::Error;
2479
/// use std::net::{TcpListener, TcpStream};
2480
///
2481
/// #[derive(Deserialize, Debug)]
2482
/// struct User {
2483
///     fingerprint: String,
2484
///     location: String,
2485
/// }
2486
///
2487
/// fn read_user_from_stream(tcp_stream: TcpStream) -> Result<User, Box<dyn Error>> {
2488
///     let mut de = serde_json::Deserializer::from_reader(tcp_stream);
2489
///     let u = User::deserialize(&mut de)?;
2490
///
2491
///     Ok(u)
2492
/// }
2493
///
2494
/// fn main() {
2495
/// # }
2496
/// # fn fake_main() {
2497
///     let listener = TcpListener::bind("127.0.0.1:4000").unwrap();
2498
///
2499
///     for stream in listener.incoming() {
2500
///         println!("{:#?}", read_user_from_stream(stream.unwrap()));
2501
///     }
2502
/// }
2503
/// ```
2504
///
2505
/// # Errors
2506
///
2507
/// This conversion can fail if the structure of the input does not match the
2508
/// structure expected by `T`, for example if `T` is a struct type but the input
2509
/// contains something other than a JSON map. It can also fail if the structure
2510
/// is correct but `T`'s implementation of `Deserialize` decides that something
2511
/// is wrong with the data, for example required struct fields are missing from
2512
/// the JSON map or some number is too big to fit in the expected primitive
2513
/// type.
2514
#[cfg(feature = "std")]
2515
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
2516
0
pub fn from_reader<R, T>(rdr: R) -> Result<T>
2517
0
where
2518
0
    R: crate::io::Read,
2519
0
    T: de::DeserializeOwned,
2520
{
2521
0
    from_trait(read::IoRead::new(rdr))
2522
0
}
2523
2524
/// Deserialize an instance of type `T` from bytes of JSON text.
2525
///
2526
/// # Example
2527
///
2528
/// ```
2529
/// use serde::Deserialize;
2530
///
2531
/// #[derive(Deserialize, Debug)]
2532
/// struct User {
2533
///     fingerprint: String,
2534
///     location: String,
2535
/// }
2536
///
2537
/// fn main() {
2538
///     // The type of `j` is `&[u8]`
2539
///     let j = b"
2540
///         {
2541
///             \"fingerprint\": \"0xF9BA143B95FF6D82\",
2542
///             \"location\": \"Menlo Park, CA\"
2543
///         }";
2544
///
2545
///     let u: User = serde_json::from_slice(j).unwrap();
2546
///     println!("{:#?}", u);
2547
/// }
2548
/// ```
2549
///
2550
/// # Errors
2551
///
2552
/// This conversion can fail if the structure of the input does not match the
2553
/// structure expected by `T`, for example if `T` is a struct type but the input
2554
/// contains something other than a JSON map. It can also fail if the structure
2555
/// is correct but `T`'s implementation of `Deserialize` decides that something
2556
/// is wrong with the data, for example required struct fields are missing from
2557
/// the JSON map or some number is too big to fit in the expected primitive
2558
/// type.
2559
0
pub fn from_slice<'a, T>(v: &'a [u8]) -> Result<T>
2560
0
where
2561
0
    T: de::Deserialize<'a>,
2562
{
2563
0
    from_trait(read::SliceRead::new(v))
2564
0
}
Unexecuted instantiation: serde_json::de::from_slice::<audio_processor::processors::peer::messages::Init>
Unexecuted instantiation: serde_json::de::from_slice::<audio_processor::shape::Format>
Unexecuted instantiation: serde_json::de::from_slice::<_>
2565
2566
/// Deserialize an instance of type `T` from a string of JSON text.
2567
///
2568
/// # Example
2569
///
2570
/// ```
2571
/// use serde::Deserialize;
2572
///
2573
/// #[derive(Deserialize, Debug)]
2574
/// struct User {
2575
///     fingerprint: String,
2576
///     location: String,
2577
/// }
2578
///
2579
/// fn main() {
2580
///     // The type of `j` is `&str`
2581
///     let j = "
2582
///         {
2583
///             \"fingerprint\": \"0xF9BA143B95FF6D82\",
2584
///             \"location\": \"Menlo Park, CA\"
2585
///         }";
2586
///
2587
///     let u: User = serde_json::from_str(j).unwrap();
2588
///     println!("{:#?}", u);
2589
/// }
2590
/// ```
2591
///
2592
/// # Errors
2593
///
2594
/// This conversion can fail if the structure of the input does not match the
2595
/// structure expected by `T`, for example if `T` is a struct type but the input
2596
/// contains something other than a JSON map. It can also fail if the structure
2597
/// is correct but `T`'s implementation of `Deserialize` decides that something
2598
/// is wrong with the data, for example required struct fields are missing from
2599
/// the JSON map or some number is too big to fit in the expected primitive
2600
/// type.
2601
0
pub fn from_str<'a, T>(s: &'a str) -> Result<T>
2602
0
where
2603
0
    T: de::Deserialize<'a>,
2604
{
2605
0
    from_trait(read::StrRead::new(s))
2606
0
}