ktav 0.1.1

Ktav — a plain configuration format. Three rules, zero indentation, zero quoting. Serde-native.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
//! `serde::Deserializer` over a flat [`Event`] stream.
//!
//! The driver is a single shared cursor (`EventCursor`) into the events
//! slice; sub-deserializers (`EventDeserializer`) and access objects
//! (`EventMap`, `EventSeq`) borrow `&mut` to it and advance it as they
//! consume tokens. There is no per-compound allocation, no recursion
//! into a tree — just `cursor.next()` walking forward.
//!
//! Number deserialization re-uses [`super::fast_num`] for the byte-loop
//! atoi; floats stay on `<f64 as FromStr>::from_str`.

use std::str::FromStr;

use serde::de::{
    self, DeserializeSeed, Deserializer, EnumAccess, MapAccess, SeqAccess, VariantAccess, Visitor,
};

use crate::error::{Error, Result};

use super::event::Event;
use super::fast_num;

// ---------------------------------------------------------------------------
// Cursor
// ---------------------------------------------------------------------------

pub(crate) struct EventCursor<'a, 'e> {
    events: &'e [Event<'a>],
    pos: usize,
}

impl<'a, 'e> EventCursor<'a, 'e> {
    pub(crate) fn new(events: &'e [Event<'a>]) -> Self {
        Self { events, pos: 0 }
    }

    #[inline]
    fn peek(&self) -> Option<&Event<'a>> {
        self.events.get(self.pos)
    }

    #[inline]
    fn next(&mut self) -> Option<Event<'a>> {
        let e = self.events.get(self.pos).copied();
        if e.is_some() {
            self.pos += 1;
        }
        e
    }

    /// Consume one full value starting at the cursor — for
    /// `IgnoredAny` / unknown-field skipping.
    fn skip_value(&mut self) -> Result<()> {
        let mut depth: usize = 0;
        loop {
            let ev = self.next().ok_or_else(|| {
                <Error as de::Error>::custom("unexpected end of event stream while skipping")
            })?;
            match ev {
                Event::BeginObject | Event::BeginArray => depth += 1,
                Event::EndObject | Event::EndArray => {
                    if depth == 0 {
                        return Err(<Error as de::Error>::custom(
                            "unexpected close while skipping value",
                        ));
                    }
                    depth -= 1;
                    if depth == 0 {
                        return Ok(());
                    }
                }
                // Key is part of an object body — don't terminate on it.
                Event::Key(_) => {}
                _ => {
                    if depth == 0 {
                        return Ok(());
                    }
                }
            }
        }
    }
}

// ---------------------------------------------------------------------------
// Deserializer
// ---------------------------------------------------------------------------

pub(crate) struct EventDeserializer<'a, 'e, 'c> {
    cursor: &'c mut EventCursor<'a, 'e>,
}

impl<'a, 'e, 'c> EventDeserializer<'a, 'e, 'c> {
    pub(crate) fn new(cursor: &'c mut EventCursor<'a, 'e>) -> Self {
        Self { cursor }
    }

    #[inline(never)]
    fn parse_error(s: &str, type_name: &'static str) -> Error {
        <Error as de::Error>::custom(format!("failed to parse '{}' as {}", s, type_name))
    }

    /// Pull the next event and require it to be a numeric/string scalar
    /// — return its inner text. Anything else is a type error.
    #[inline]
    fn next_numeric_text(&mut self, type_name: &'static str) -> Result<&'a str> {
        match self.cursor.next() {
            Some(Event::Integer(s)) | Some(Event::Float(s)) | Some(Event::Str(s)) => Ok(s),
            other => Err(<Error as de::Error>::custom(format!(
                "expected {}, got {:?}",
                type_name, other
            ))),
        }
    }
}

impl<'de, 'e, 'c> Deserializer<'de> for EventDeserializer<'de, 'e, 'c> {
    type Error = Error;

    fn deserialize_any<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value> {
        match self.cursor.next() {
            Some(Event::Null) => visitor.visit_unit(),
            Some(Event::Bool(b)) => visitor.visit_bool(b),
            Some(Event::Integer(s)) => {
                if let Some(i) = fast_num::parse_i64(s) {
                    visitor.visit_i64(i)
                } else if let Some(u) = fast_num::parse_u64(s) {
                    visitor.visit_u64(u)
                } else {
                    visitor.visit_borrowed_str(s)
                }
            }
            Some(Event::Float(s)) => match s.parse::<f64>() {
                Ok(f) => visitor.visit_f64(f),
                Err(_) => visitor.visit_borrowed_str(s),
            },
            Some(Event::Str(s)) => visitor.visit_borrowed_str(s),
            Some(Event::BeginObject) => visitor.visit_map(EventMap { cursor: self.cursor }),
            Some(Event::BeginArray) => visitor.visit_seq(EventSeq { cursor: self.cursor }),
            other => Err(<Error as de::Error>::custom(format!(
                "deserialize_any: unexpected event {:?}",
                other
            ))),
        }
    }

    fn deserialize_bool<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value> {
        match self.cursor.next() {
            Some(Event::Bool(b)) => visitor.visit_bool(b),
            Some(Event::Str(s)) => match s {
                "true" => visitor.visit_bool(true),
                "false" => visitor.visit_bool(false),
                _ => Err(Self::parse_error(s, "bool")),
            },
            other => Err(<Error as de::Error>::custom(format!(
                "expected bool, got {:?}",
                other
            ))),
        }
    }

    #[inline]
    fn deserialize_i8<V: Visitor<'de>>(mut self, visitor: V) -> Result<V::Value> {
        let s = self.next_numeric_text("i8")?;
        let v = fast_num::parse_i_bounded(s, i8::MIN as i64, i8::MAX as i64)
            .ok_or_else(|| Self::parse_error(s, "i8"))?;
        visitor.visit_i8(v as i8)
    }
    #[inline]
    fn deserialize_i16<V: Visitor<'de>>(mut self, visitor: V) -> Result<V::Value> {
        let s = self.next_numeric_text("i16")?;
        let v = fast_num::parse_i_bounded(s, i16::MIN as i64, i16::MAX as i64)
            .ok_or_else(|| Self::parse_error(s, "i16"))?;
        visitor.visit_i16(v as i16)
    }
    #[inline]
    fn deserialize_i32<V: Visitor<'de>>(mut self, visitor: V) -> Result<V::Value> {
        let s = self.next_numeric_text("i32")?;
        let v = fast_num::parse_i_bounded(s, i32::MIN as i64, i32::MAX as i64)
            .ok_or_else(|| Self::parse_error(s, "i32"))?;
        visitor.visit_i32(v as i32)
    }
    #[inline]
    fn deserialize_i64<V: Visitor<'de>>(mut self, visitor: V) -> Result<V::Value> {
        let s = self.next_numeric_text("i64")?;
        let v = fast_num::parse_i64(s).ok_or_else(|| Self::parse_error(s, "i64"))?;
        visitor.visit_i64(v)
    }
    #[inline]
    fn deserialize_u8<V: Visitor<'de>>(mut self, visitor: V) -> Result<V::Value> {
        let s = self.next_numeric_text("u8")?;
        let v = fast_num::parse_u_bounded(s, u8::MAX as u64)
            .ok_or_else(|| Self::parse_error(s, "u8"))?;
        visitor.visit_u8(v as u8)
    }
    #[inline]
    fn deserialize_u16<V: Visitor<'de>>(mut self, visitor: V) -> Result<V::Value> {
        let s = self.next_numeric_text("u16")?;
        let v = fast_num::parse_u_bounded(s, u16::MAX as u64)
            .ok_or_else(|| Self::parse_error(s, "u16"))?;
        visitor.visit_u16(v as u16)
    }
    #[inline]
    fn deserialize_u32<V: Visitor<'de>>(mut self, visitor: V) -> Result<V::Value> {
        let s = self.next_numeric_text("u32")?;
        let v = fast_num::parse_u_bounded(s, u32::MAX as u64)
            .ok_or_else(|| Self::parse_error(s, "u32"))?;
        visitor.visit_u32(v as u32)
    }
    #[inline]
    fn deserialize_u64<V: Visitor<'de>>(mut self, visitor: V) -> Result<V::Value> {
        let s = self.next_numeric_text("u64")?;
        let v = fast_num::parse_u64(s).ok_or_else(|| Self::parse_error(s, "u64"))?;
        visitor.visit_u64(v)
    }
    fn deserialize_f32<V: Visitor<'de>>(mut self, visitor: V) -> Result<V::Value> {
        let s = self.next_numeric_text("f32")?;
        visitor.visit_f32(f32::from_str(s).map_err(|_| Self::parse_error(s, "f32"))?)
    }
    fn deserialize_f64<V: Visitor<'de>>(mut self, visitor: V) -> Result<V::Value> {
        let s = self.next_numeric_text("f64")?;
        visitor.visit_f64(f64::from_str(s).map_err(|_| Self::parse_error(s, "f64"))?)
    }

    fn deserialize_char<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value> {
        match self.cursor.next() {
            Some(Event::Str(s)) => {
                let mut chars = s.chars();
                match (chars.next(), chars.next()) {
                    (Some(c), None) => visitor.visit_char(c),
                    _ => Err(<Error as de::Error>::custom(format!(
                        "expected single character, got '{}'",
                        s
                    ))),
                }
            }
            other => Err(<Error as de::Error>::custom(format!(
                "expected char, got {:?}",
                other
            ))),
        }
    }

    fn deserialize_str<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value> {
        match self.cursor.next() {
            Some(Event::Str(s)) | Some(Event::Integer(s)) | Some(Event::Float(s)) => {
                visitor.visit_borrowed_str(s)
            }
            other => Err(<Error as de::Error>::custom(format!(
                "expected string, got {:?}",
                other
            ))),
        }
    }

    fn deserialize_string<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value> {
        self.deserialize_str(visitor)
    }

    fn deserialize_bytes<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value> {
        match self.cursor.next() {
            Some(Event::Str(s)) => visitor.visit_borrowed_bytes(s.as_bytes()),
            other => Err(<Error as de::Error>::custom(format!(
                "expected bytes, got {:?}",
                other
            ))),
        }
    }

    fn deserialize_byte_buf<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value> {
        match self.cursor.next() {
            Some(Event::Str(s)) => visitor.visit_byte_buf(s.as_bytes().to_vec()),
            other => Err(<Error as de::Error>::custom(format!(
                "expected bytes, got {:?}",
                other
            ))),
        }
    }

    fn deserialize_option<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value> {
        match self.cursor.peek() {
            Some(Event::Null) => {
                self.cursor.next();
                visitor.visit_none()
            }
            _ => visitor.visit_some(self),
        }
    }

    fn deserialize_unit<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value> {
        match self.cursor.next() {
            Some(Event::Null) => visitor.visit_unit(),
            other => Err(<Error as de::Error>::custom(format!(
                "expected unit, got {:?}",
                other
            ))),
        }
    }

    fn deserialize_unit_struct<V: Visitor<'de>>(
        self,
        _: &'static str,
        visitor: V,
    ) -> Result<V::Value> {
        self.deserialize_unit(visitor)
    }

    fn deserialize_newtype_struct<V: Visitor<'de>>(
        self,
        _: &'static str,
        visitor: V,
    ) -> Result<V::Value> {
        visitor.visit_newtype_struct(self)
    }

    fn deserialize_seq<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value> {
        match self.cursor.next() {
            Some(Event::BeginArray) => visitor.visit_seq(EventSeq { cursor: self.cursor }),
            other => Err(<Error as de::Error>::custom(format!(
                "expected array, got {:?}",
                other
            ))),
        }
    }

    fn deserialize_tuple<V: Visitor<'de>>(self, _: usize, visitor: V) -> Result<V::Value> {
        self.deserialize_seq(visitor)
    }

    fn deserialize_tuple_struct<V: Visitor<'de>>(
        self,
        _: &'static str,
        _: usize,
        visitor: V,
    ) -> Result<V::Value> {
        self.deserialize_seq(visitor)
    }

    fn deserialize_map<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value> {
        match self.cursor.next() {
            Some(Event::BeginObject) => visitor.visit_map(EventMap { cursor: self.cursor }),
            other => Err(<Error as de::Error>::custom(format!(
                "expected object, got {:?}",
                other
            ))),
        }
    }

    fn deserialize_struct<V: Visitor<'de>>(
        self,
        _: &'static str,
        _: &'static [&'static str],
        visitor: V,
    ) -> Result<V::Value> {
        self.deserialize_map(visitor)
    }

    fn deserialize_enum<V: Visitor<'de>>(
        self,
        _: &'static str,
        _: &'static [&'static str],
        visitor: V,
    ) -> Result<V::Value> {
        // Two shapes: bare string variant, or `{ name: payload }` object.
        match self.cursor.peek() {
            Some(Event::Str(_)) => visitor.visit_enum(EventEnum {
                cursor: self.cursor,
                from_object: false,
            }),
            Some(Event::BeginObject) => {
                self.cursor.next(); // consume BeginObject
                visitor.visit_enum(EventEnum {
                    cursor: self.cursor,
                    from_object: true,
                })
            }
            other => Err(<Error as de::Error>::custom(format!(
                "expected enum representation, got {:?}",
                other
            ))),
        }
    }

    fn deserialize_identifier<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value> {
        self.deserialize_str(visitor)
    }

    fn deserialize_ignored_any<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value> {
        // Skip however many events make up the next value, then visit
        // unit so the caller sees something.
        self.cursor.skip_value()?;
        visitor.visit_unit()
    }
}

// ---------------------------------------------------------------------------
// MapAccess
// ---------------------------------------------------------------------------

struct EventMap<'a, 'e, 'c> {
    cursor: &'c mut EventCursor<'a, 'e>,
}

impl<'de, 'e, 'c> MapAccess<'de> for EventMap<'de, 'e, 'c> {
    type Error = Error;

    #[inline]
    fn next_key_seed<K: DeserializeSeed<'de>>(&mut self, seed: K) -> Result<Option<K::Value>> {
        match self.cursor.peek() {
            Some(Event::EndObject) => {
                self.cursor.next();
                Ok(None)
            }
            Some(Event::Key(_)) => {
                // Consume the Key event and feed the borrowed slice to
                // the seed via a borrowed-str deserializer.
                let k = match self.cursor.next() {
                    Some(Event::Key(k)) => k,
                    _ => unreachable!(),
                };
                seed.deserialize(BorrowedStrDeserializer { value: k }).map(Some)
            }
            other => Err(<Error as de::Error>::custom(format!(
                "expected Key or EndObject in map, got {:?}",
                other
            ))),
        }
    }

    #[inline]
    fn next_value_seed<V: DeserializeSeed<'de>>(&mut self, seed: V) -> Result<V::Value> {
        seed.deserialize(EventDeserializer::new(self.cursor))
    }
}

// ---------------------------------------------------------------------------
// SeqAccess
// ---------------------------------------------------------------------------

struct EventSeq<'a, 'e, 'c> {
    cursor: &'c mut EventCursor<'a, 'e>,
}

impl<'de, 'e, 'c> SeqAccess<'de> for EventSeq<'de, 'e, 'c> {
    type Error = Error;

    #[inline]
    fn next_element_seed<T: DeserializeSeed<'de>>(&mut self, seed: T) -> Result<Option<T::Value>> {
        match self.cursor.peek() {
            Some(Event::EndArray) => {
                self.cursor.next();
                Ok(None)
            }
            _ => seed.deserialize(EventDeserializer::new(self.cursor)).map(Some),
        }
    }
}

// ---------------------------------------------------------------------------
// EnumAccess
// ---------------------------------------------------------------------------

struct EventEnum<'a, 'e, 'c> {
    cursor: &'c mut EventCursor<'a, 'e>,
    from_object: bool,
}

impl<'de, 'e, 'c> EnumAccess<'de> for EventEnum<'de, 'e, 'c> {
    type Error = Error;
    type Variant = EventVariant<'de, 'e, 'c>;

    fn variant_seed<V: DeserializeSeed<'de>>(self, seed: V) -> Result<(V::Value, Self::Variant)> {
        if self.from_object {
            // Inside object: next event MUST be Key.
            let name = match self.cursor.next() {
                Some(Event::Key(k)) => k,
                other => {
                    return Err(<Error as de::Error>::custom(format!(
                        "expected enum variant key, got {:?}",
                        other
                    )))
                }
            };
            let v = seed.deserialize(BorrowedStrDeserializer { value: name })?;
            Ok((
                v,
                EventVariant {
                    cursor: self.cursor,
                    has_payload: true,
                },
            ))
        } else {
            // Bare string: this is the variant name; no payload follows.
            let name = match self.cursor.next() {
                Some(Event::Str(s)) => s,
                other => {
                    return Err(<Error as de::Error>::custom(format!(
                        "expected enum string, got {:?}",
                        other
                    )))
                }
            };
            let v = seed.deserialize(BorrowedStrDeserializer { value: name })?;
            Ok((
                v,
                EventVariant {
                    cursor: self.cursor,
                    has_payload: false,
                },
            ))
        }
    }
}

struct EventVariant<'a, 'e, 'c> {
    cursor: &'c mut EventCursor<'a, 'e>,
    has_payload: bool,
}

impl<'de, 'e, 'c> VariantAccess<'de> for EventVariant<'de, 'e, 'c> {
    type Error = Error;

    fn unit_variant(self) -> Result<()> {
        if !self.has_payload {
            Ok(())
        } else {
            // Object-form unit variant: consume the value+EndObject.
            self.cursor.skip_value()?;
            // Then the closing EndObject of the wrapping enum object.
            match self.cursor.next() {
                Some(Event::EndObject) => Ok(()),
                other => Err(<Error as de::Error>::custom(format!(
                    "expected EndObject after enum variant, got {:?}",
                    other
                ))),
            }
        }
    }

    fn newtype_variant_seed<T: DeserializeSeed<'de>>(self, seed: T) -> Result<T::Value> {
        if !self.has_payload {
            return Err(<Error as de::Error>::custom(
                "newtype variant requires a payload",
            ));
        }
        let value = seed.deserialize(EventDeserializer::new(self.cursor))?;
        // Consume the closing EndObject of the wrapping enum object.
        match self.cursor.next() {
            Some(Event::EndObject) => Ok(value),
            other => Err(<Error as de::Error>::custom(format!(
                "expected EndObject after enum variant, got {:?}",
                other
            ))),
        }
    }

    fn tuple_variant<V: Visitor<'de>>(self, _: usize, visitor: V) -> Result<V::Value> {
        if !self.has_payload {
            return Err(<Error as de::Error>::custom(
                "tuple variant requires a payload",
            ));
        }
        let value = EventDeserializer::new(self.cursor).deserialize_seq(visitor)?;
        match self.cursor.next() {
            Some(Event::EndObject) => Ok(value),
            other => Err(<Error as de::Error>::custom(format!(
                "expected EndObject after enum variant, got {:?}",
                other
            ))),
        }
    }

    fn struct_variant<V: Visitor<'de>>(
        self,
        _: &'static [&'static str],
        visitor: V,
    ) -> Result<V::Value> {
        if !self.has_payload {
            return Err(<Error as de::Error>::custom(
                "struct variant requires a payload",
            ));
        }
        let value = EventDeserializer::new(self.cursor).deserialize_map(visitor)?;
        match self.cursor.next() {
            Some(Event::EndObject) => Ok(value),
            other => Err(<Error as de::Error>::custom(format!(
                "expected EndObject after enum variant, got {:?}",
                other
            ))),
        }
    }
}

// ---------------------------------------------------------------------------
// BorrowedStrDeserializer — exact same shape as the tree-builder's, kept
// local so the modules don't cross-depend.
// ---------------------------------------------------------------------------

struct BorrowedStrDeserializer<'de> {
    value: &'de str,
}

impl<'de> BorrowedStrDeserializer<'de> {
    fn parse<T: FromStr>(&self, ty: &str) -> Result<T> {
        self.value.parse::<T>().map_err(|_| {
            <Error as de::Error>::custom(format!(
                "failed to parse map key '{}' as {}",
                self.value, ty
            ))
        })
    }
}

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

    fn deserialize_any<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value> {
        visitor.visit_borrowed_str(self.value)
    }
    fn deserialize_str<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value> {
        visitor.visit_borrowed_str(self.value)
    }
    fn deserialize_string<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value> {
        visitor.visit_str(self.value)
    }
    fn deserialize_identifier<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value> {
        visitor.visit_borrowed_str(self.value)
    }
    fn deserialize_bool<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value> {
        visitor.visit_bool(self.parse::<bool>("bool")?)
    }
    fn deserialize_i8<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value> {
        visitor.visit_i8(self.parse::<i8>("i8")?)
    }
    fn deserialize_i16<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value> {
        visitor.visit_i16(self.parse::<i16>("i16")?)
    }
    fn deserialize_i32<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value> {
        visitor.visit_i32(self.parse::<i32>("i32")?)
    }
    fn deserialize_i64<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value> {
        visitor.visit_i64(self.parse::<i64>("i64")?)
    }
    fn deserialize_u8<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value> {
        visitor.visit_u8(self.parse::<u8>("u8")?)
    }
    fn deserialize_u16<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value> {
        visitor.visit_u16(self.parse::<u16>("u16")?)
    }
    fn deserialize_u32<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value> {
        visitor.visit_u32(self.parse::<u32>("u32")?)
    }
    fn deserialize_u64<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value> {
        visitor.visit_u64(self.parse::<u64>("u64")?)
    }
    fn deserialize_f32<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value> {
        visitor.visit_f32(self.parse::<f32>("f32")?)
    }
    fn deserialize_f64<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value> {
        visitor.visit_f64(self.parse::<f64>("f64")?)
    }
    fn deserialize_char<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value> {
        let mut chars = self.value.chars();
        match (chars.next(), chars.next()) {
            (Some(c), None) => visitor.visit_char(c),
            _ => Err(<Error as de::Error>::custom(format!(
                "expected single character map key, got '{}'",
                self.value
            ))),
        }
    }

    serde::forward_to_deserialize_any! {
        i128 u128 bytes byte_buf option unit unit_struct newtype_struct
        seq tuple tuple_struct map struct enum ignored_any
    }
}