ion-rs 1.0.0

Implementation of Amazon Ion
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
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
use serde::de;
use serde::de::{DeserializeOwned, DeserializeSeed, EnumAccess, MapAccess, SeqAccess, Visitor};

use crate::lazy::any_encoding::AnyEncoding;
use crate::lazy::r#struct::{LazyField, StructIterator};
use crate::lazy::streaming_raw_reader::IonInput;
use crate::lazy::value::LazyValue;
use crate::lazy::value_ref::ValueRef;
use crate::result::IonFailure;
use crate::serde::decimal::TUNNELED_DECIMAL_TYPE_NAME;
use crate::serde::timestamp::TUNNELED_TIMESTAMP_TYPE_NAME;
use crate::{
    Decimal, IonEncoding, IonError, IonResult, IonType, RawVersionMarker, SystemReader,
    SystemStreamItem, Timestamp,
};

/// Generic method that can deserialize an object from any given type
/// that implements `IonInput`.
pub fn from_ion<T, I>(input: I) -> IonResult<T>
where
    T: DeserializeOwned,
    I: IonInput,
{
    let mut ion_encoding = IonEncoding::default();
    let mut reader = SystemReader::new(AnyEncoding, input);
    loop {
        match reader.next_item()? {
            SystemStreamItem::VersionMarker(marker) => {
                // It's a version marker; update the detected Ion encoding
                ion_encoding = marker.stream_encoding_after_marker()?;
            }
            SystemStreamItem::Value(value) => {
                let value_deserializer = ValueDeserializer::new(
                    &value,
                    /*is_human_readable=*/ ion_encoding.is_text(),
                );
                return T::deserialize(value_deserializer);
            }
            SystemStreamItem::EndOfStream(_end) => {
                return IonResult::decoding_error("stream did not contain any values")
            }
            _system_value => {
                // Ignore system values
            }
        }
    }
}

#[derive(Clone, Copy)]
pub struct ValueDeserializer<'a, 'de> {
    pub(crate) value: &'a LazyValue<'de, AnyEncoding>,
    is_human_readable: bool,
    variant_nesting_depth: usize, // Holds the number of nested variants we are for tracking
                                  // variant names in annotations. 0 indicates we're not in a
                                  // variant.
}

impl<'a, 'de> ValueDeserializer<'a, 'de> {
    pub(crate) fn new(value: &'a LazyValue<'de, AnyEncoding>, is_human_readable: bool) -> Self {
        Self {
            value,
            is_human_readable,
            variant_nesting_depth: 0,
        }
    }

    fn deserialize_as_sequence<V: Visitor<'de>>(
        self,
        visitor: V,
    ) -> Result<V::Value, <Self as de::Deserializer<'de>>::Error> {
        use ValueRef::*;
        match self.value.read()? {
            List(l) => visitor.visit_seq(SequenceIterator(l.iter(), self.is_human_readable)),
            SExp(l) => visitor.visit_seq(SequenceIterator(l.iter(), self.is_human_readable)),
            _ => IonResult::decoding_error("expected a list or sexp"),
        }
    }
    fn deserialize_as_map<V: Visitor<'de>>(
        self,
        visitor: V,
    ) -> Result<V::Value, <Self as de::Deserializer<'de>>::Error> {
        let strukt = self.value.read()?.expect_struct()?;
        let struct_as_map = StructAsMap::new(strukt.iter(), self.is_human_readable);

        visitor.visit_map(struct_as_map)
    }
}

impl<'de> de::Deserializer<'de> for ValueDeserializer<'_, 'de> {
    type Error = IonError;

    /// Determine whether Deserialize implementations should expect to deserialize their human-readable form.
    /// For binary Ion this will return `false` and for text Ion this will return `true`.
    fn is_human_readable(&self) -> bool {
        self.is_human_readable
    }

    fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>
    where
        V: Visitor<'de>,
    {
        use IonType::*;
        // We look at the IonType because it doesn't require performing a `read()` operation.
        // The appropriate delegate can perform the `read()`.
        match self.value.ion_type() {
            Null => self.deserialize_unit(visitor),
            Bool => self.deserialize_bool(visitor),
            Int => self.deserialize_i64(visitor),
            Float => self.deserialize_f64(visitor),
            Decimal => self.deserialize_newtype_struct(TUNNELED_DECIMAL_TYPE_NAME, visitor),
            Timestamp => self.deserialize_newtype_struct(TUNNELED_TIMESTAMP_TYPE_NAME, visitor),
            String | Symbol => self.deserialize_str(visitor),
            Blob | Clob => self.deserialize_bytes(visitor),
            List | SExp => self.deserialize_seq(visitor),
            Struct => self.deserialize_struct("", &[], visitor),
        }
    }

    fn deserialize_bool<V>(self, visitor: V) -> Result<V::Value, Self::Error>
    where
        V: Visitor<'de>,
    {
        visitor.visit_bool(self.value.read()?.expect_bool()?)
    }

    fn deserialize_i8<V>(self, visitor: V) -> Result<V::Value, Self::Error>
    where
        V: Visitor<'de>,
    {
        let value = self
            .value
            .read()?
            .expect_i64()
            .map(i8::try_from)?
            .map_err(|_| {
                IonError::decoding_error("found an integer was out of bounds for an `i8`")
            })?;
        visitor.visit_i8(value)
    }

    fn deserialize_i16<V>(self, visitor: V) -> Result<V::Value, Self::Error>
    where
        V: Visitor<'de>,
    {
        let value = self
            .value
            .read()?
            .expect_i64()
            .map(i16::try_from)?
            .map_err(|_| {
                IonError::decoding_error("found an integer was out of bounds for an `i16`")
            })?;
        visitor.visit_i16(value)
    }

    fn deserialize_i32<V>(self, visitor: V) -> Result<V::Value, Self::Error>
    where
        V: Visitor<'de>,
    {
        let value = self
            .value
            .read()?
            .expect_i64()
            .map(i32::try_from)?
            .map_err(|_| {
                IonError::decoding_error("found an integer was out of bounds for an `i32`")
            })?;
        visitor.visit_i32(value)
    }

    fn deserialize_i64<V>(self, visitor: V) -> Result<V::Value, Self::Error>
    where
        V: Visitor<'de>,
    {
        visitor.visit_i64(self.value.read()?.expect_i64()?)
    }

    fn deserialize_u8<V>(self, visitor: V) -> Result<V::Value, Self::Error>
    where
        V: Visitor<'de>,
    {
        let value = self
            .value
            .read()?
            .expect_i64()
            .map(u8::try_from)?
            .map_err(|_| {
                IonError::decoding_error("found an integer was out of bounds for a `u8`")
            })?;
        visitor.visit_u8(value)
    }

    fn deserialize_u16<V>(self, visitor: V) -> Result<V::Value, Self::Error>
    where
        V: Visitor<'de>,
    {
        let value = self
            .value
            .read()?
            .expect_i64()
            .map(u16::try_from)?
            .map_err(|_| {
                IonError::decoding_error("found an integer was out of bounds for an `u16`")
            })?;
        visitor.visit_u16(value)
    }

    fn deserialize_u32<V>(self, visitor: V) -> Result<V::Value, Self::Error>
    where
        V: Visitor<'de>,
    {
        let value = self
            .value
            .read()?
            .expect_i64()
            .map(u32::try_from)?
            .map_err(|_| {
                IonError::decoding_error("found an integer was out of bounds for an `u32`")
            })?;
        visitor.visit_u32(value)
    }

    fn deserialize_u64<V>(self, visitor: V) -> Result<V::Value, Self::Error>
    where
        V: Visitor<'de>,
    {
        let value = self
            .value
            .read()?
            // There are integer values that fit in a u64 but not an i64, so we use
            // `expect_int` instead of `expect_i64` to accommodate that case.
            .expect_int()
            .map(u64::try_from)?
            .map_err(|_| {
                IonError::decoding_error("found an integer was out of bounds for an `u64`")
            })?;
        visitor.visit_u64(value)
    }

    fn deserialize_f32<V>(self, visitor: V) -> Result<V::Value, Self::Error>
    where
        V: Visitor<'de>,
    {
        // XXX: This risks loss of fidelity. If the input stream has an f64 and serde asks for an
        //      f32, this will lose precision.
        visitor.visit_f32(self.value.read()?.expect_float()? as f32)
    }

    fn deserialize_f64<V>(self, visitor: V) -> Result<V::Value, Self::Error>
    where
        V: Visitor<'de>,
    {
        visitor.visit_f64(self.value.read()?.expect_float()?)
    }

    fn deserialize_char<V>(self, visitor: V) -> Result<V::Value, Self::Error>
    where
        V: Visitor<'de>,
    {
        let value = self.value.read()?.expect_string().and_then(|s| {
            let mut chars = s.chars();
            let Some(first_char) = chars.next() else {
                return IonResult::decoding_error("expected a char, found an empty string");
            };
            if let Some(_second_char) = chars.next() {
                return IonResult::decoding_error(
                    "expected a char, found a string with two or more characters",
                );
            }
            Ok(first_char)
        })?;
        visitor.visit_char(value)
    }

    fn deserialize_str<V>(self, visitor: V) -> Result<V::Value, Self::Error>
    where
        V: Visitor<'de>,
    {
        visitor.visit_str(self.value.read()?.expect_text()?)
    }

    fn deserialize_string<V>(self, visitor: V) -> Result<V::Value, Self::Error>
    where
        V: Visitor<'de>,
    {
        visitor.visit_string(self.value.read()?.expect_text()?.to_owned())
    }

    fn deserialize_bytes<V>(self, visitor: V) -> Result<V::Value, Self::Error>
    where
        V: Visitor<'de>,
    {
        let value = self.value.read()?.expect_lob()?;
        visitor.visit_bytes(value.as_ref())
    }

    fn deserialize_byte_buf<V>(self, visitor: V) -> Result<V::Value, Self::Error>
    where
        V: Visitor<'de>,
    {
        let value = self.value.read()?.expect_lob()?;
        // If the BytesRef is already backed by a Vec<u8>, this will use the Vec<u8>
        // instead of creating a clone.
        visitor.visit_bytes(value.as_ref())
    }

    fn deserialize_option<V>(self, visitor: V) -> Result<V::Value, Self::Error>
    where
        V: Visitor<'de>,
    {
        if self.value.is_null() {
            visitor.visit_none()
        } else {
            visitor.visit_some(self)
        }
    }

    fn deserialize_unit<V>(self, visitor: V) -> Result<V::Value, Self::Error>
    where
        V: Visitor<'de>,
    {
        visitor.visit_unit()
    }

    fn deserialize_unit_struct<V>(
        self,
        _name: &'static str,
        visitor: V,
    ) -> Result<V::Value, Self::Error>
    where
        V: Visitor<'de>,
    {
        visitor.visit_unit()
    }

    fn deserialize_newtype_struct<V>(
        self,
        name: &'static str,
        visitor: V,
    ) -> Result<V::Value, Self::Error>
    where
        V: Visitor<'de>,
    {
        let value = self.value.read()?;
        if name == TUNNELED_TIMESTAMP_TYPE_NAME {
            let timestamp = value.expect_timestamp()?;
            assert_eq!(
                std::mem::size_of::<V::Value>(),
                std::mem::size_of::<Timestamp>()
            );
            // # Safety
            // compiler doesn't understand that the generic Timestamp here is actually V::Value here
            // The assert statement above that compares the sizes of the Timestamp and V::Value types
            let visitor_value =
                unsafe { std::mem::transmute_copy::<Timestamp, V::Value>(&timestamp) };
            return Ok(visitor_value);
        } else if name == TUNNELED_DECIMAL_TYPE_NAME {
            let decimal = value.expect_decimal()?;
            assert_eq!(
                std::mem::size_of::<V::Value>(),
                std::mem::size_of::<Decimal>()
            );
            // # Safety
            // compiler doesn't understand that the generic Decimal here is actually V::Value here
            // The assert statement above that compares the sizes of the Decimal and V::Value types
            let visitor_value = unsafe { std::mem::transmute_copy::<Decimal, V::Value>(&decimal) };
            return Ok(visitor_value);
        }

        visitor.visit_newtype_struct(self)
    }

    fn deserialize_seq<V>(self, visitor: V) -> Result<V::Value, Self::Error>
    where
        V: Visitor<'de>,
    {
        self.deserialize_as_sequence(visitor)
    }

    fn deserialize_tuple<V>(self, _len: usize, visitor: V) -> Result<V::Value, Self::Error>
    where
        V: Visitor<'de>,
    {
        self.deserialize_as_sequence(visitor)
    }

    fn deserialize_tuple_struct<V>(
        self,
        _name: &'static str,
        _len: usize,
        visitor: V,
    ) -> Result<V::Value, Self::Error>
    where
        V: Visitor<'de>,
    {
        self.deserialize_as_sequence(visitor)
    }

    fn deserialize_map<V>(self, visitor: V) -> Result<V::Value, Self::Error>
    where
        V: Visitor<'de>,
    {
        self.deserialize_as_map(visitor)
    }

    fn deserialize_struct<V>(
        self,
        _name: &'static str,
        _fields: &'static [&'static str],
        visitor: V,
    ) -> Result<V::Value, Self::Error>
    where
        V: Visitor<'de>,
    {
        self.deserialize_as_map(visitor)
    }

    fn deserialize_enum<V>(
        self,
        _name: &'static str,
        _variants: &'static [&'static str],
        visitor: V,
    ) -> Result<V::Value, Self::Error>
    where
        V: Visitor<'de>,
    {
        visitor.visit_enum(VariantAccess::new(self))
    }

    fn deserialize_identifier<V>(self, visitor: V) -> Result<V::Value, Self::Error>
    where
        V: Visitor<'de>,
    {
        // Make sure we've started reading an enum.
        if self.variant_nesting_depth == 0 {
            return IonResult::decoding_error(
                "unexpected serde state; was not expecting to read an identifier",
            );
        }

        let mut annotations = self.value.annotations();
        let our_annotation = annotations
            .nth(self.variant_nesting_depth - 1)
            .transpose()?;
        match our_annotation {
            None => {
                let symbol = self.value.read()?.expect_symbol()?;
                let symbol_text = symbol.text().ok_or_else(|| {
                    IonError::decoding_error(
                        "expected a symbol representing an enum's unit struct variant",
                    )
                })?;
                visitor.visit_str(symbol_text)
            }
            Some(variant_name) => {
                let variant_id = variant_name.text().ok_or_else(|| {
                    IonError::decoding_error("expected an enum variant identifier annotation")
                })?;
                visitor.visit_str(variant_id)
            }
        }
    }

    fn deserialize_ignored_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>
    where
        V: Visitor<'de>,
    {
        // Ignore the value itself, return a `null` that will be also ignored
        visitor.visit_unit()
    }
}

pub(crate) struct SequenceIterator<S>(pub(crate) S, bool);

impl<'de, S> SeqAccess<'de> for SequenceIterator<S>
where
    S: Iterator<Item = IonResult<LazyValue<'de, AnyEncoding>>>,
{
    type Error = IonError;

    fn next_element_seed<T>(&mut self, seed: T) -> Result<Option<T::Value>, Self::Error>
    where
        T: DeserializeSeed<'de>,
    {
        let Some(lazy_value) = self.0.next().transpose()? else {
            return Ok(None);
        };
        let deserializer = ValueDeserializer::new(&lazy_value, self.1);
        seed.deserialize(deserializer).map(Some)
    }
}

struct StructAsMap<'de> {
    iter: StructIterator<'de, AnyEncoding>,
    current_field: Option<LazyField<'de, AnyEncoding>>,
    is_human_readable: bool,
}

impl<'de> StructAsMap<'de> {
    pub fn new(iter: StructIterator<'de, AnyEncoding>, is_human_readable: bool) -> Self {
        Self {
            iter,
            current_field: None,
            is_human_readable,
        }
    }
}

impl<'de> MapAccess<'de> for StructAsMap<'de> {
    type Error = IonError;

    fn next_key_seed<K>(&mut self, seed: K) -> Result<Option<K::Value>, Self::Error>
    where
        K: DeserializeSeed<'de>,
    {
        let Some(field) = self.iter.next_field()? else {
            return Ok(None);
        };

        let name = field
            .name()?
            .text()
            .ok_or_else(|| IonError::decoding_error("found a symbol with unknown text"))?
            .to_owned();
        self.current_field = Some(field);

        let deserializer = MapKeyDeserializer { key: name };
        seed.deserialize(deserializer).map(Some)
    }

    fn next_value_seed<V>(&mut self, seed: V) -> Result<V::Value, Self::Error>
    where
        V: DeserializeSeed<'de>,
    {
        seed.deserialize(ValueDeserializer::new(
            // This method will only be called when `next_key_seed` reported another field,
            // so we can unwrap this safely.
            &self.current_field.as_ref().unwrap().value(),
            self.is_human_readable,
        ))
    }
}

#[derive(Clone, Copy)]
struct VariantAccess<'a, 'de> {
    de: ValueDeserializer<'a, 'de>,
}

impl<'a, 'de> VariantAccess<'a, 'de> {
    fn new(de: ValueDeserializer<'a, 'de>) -> Self {
        let de = ValueDeserializer {
            variant_nesting_depth: de.variant_nesting_depth + 1,
            ..de
        };

        VariantAccess { de }
    }
}

impl<'de> EnumAccess<'de> for VariantAccess<'_, 'de> {
    type Error = IonError;
    type Variant = Self;

    fn variant_seed<V>(self, seed: V) -> Result<(V::Value, Self::Variant), Self::Error>
    where
        V: DeserializeSeed<'de>,
    {
        Ok((seed.deserialize(self.de)?, self))
    }
}

impl<'de> de::VariantAccess<'de> for VariantAccess<'_, 'de> {
    type Error = IonError;

    fn unit_variant(self) -> Result<(), Self::Error> {
        de::Deserialize::deserialize(self.de)
    }

    fn newtype_variant_seed<T>(self, seed: T) -> Result<T::Value, Self::Error>
    where
        T: DeserializeSeed<'de>,
    {
        seed.deserialize(self.de)
    }

    fn tuple_variant<V>(self, _len: usize, visitor: V) -> Result<V::Value, Self::Error>
    where
        V: Visitor<'de>,
    {
        de::Deserializer::deserialize_seq(self.de, visitor)
    }

    fn struct_variant<V>(
        self,
        fields: &'static [&'static str],
        visitor: V,
    ) -> Result<V::Value, Self::Error>
    where
        V: Visitor<'de>,
    {
        de::Deserializer::deserialize_struct(self.de, "", fields, visitor)
    }
}

struct MapKeyDeserializer {
    key: String,
}

impl<'de> de::Deserializer<'de> for MapKeyDeserializer {
    type Error = IonError;

    fn deserialize_any<V>(self, _visitor: V) -> Result<V::Value, Self::Error>
    where
        V: Visitor<'de>,
    {
        IonResult::decoding_error("expected a string value")
    }

    fn deserialize_bool<V>(self, _visitor: V) -> Result<V::Value, Self::Error>
    where
        V: Visitor<'de>,
    {
        IonResult::decoding_error("expected a string value")
    }

    fn deserialize_i8<V>(self, _visitor: V) -> Result<V::Value, Self::Error>
    where
        V: Visitor<'de>,
    {
        IonResult::decoding_error("expected a string value")
    }

    fn deserialize_i16<V>(self, _visitor: V) -> Result<V::Value, Self::Error>
    where
        V: Visitor<'de>,
    {
        IonResult::decoding_error("expected a string value")
    }

    fn deserialize_i32<V>(self, _visitor: V) -> Result<V::Value, Self::Error>
    where
        V: Visitor<'de>,
    {
        IonResult::decoding_error("expected a string value")
    }

    fn deserialize_i64<V>(self, _visitor: V) -> Result<V::Value, Self::Error>
    where
        V: Visitor<'de>,
    {
        IonResult::decoding_error("expected a string value")
    }

    fn deserialize_u8<V>(self, _visitor: V) -> Result<V::Value, Self::Error>
    where
        V: Visitor<'de>,
    {
        IonResult::decoding_error("expected a string value")
    }

    fn deserialize_u16<V>(self, _visitor: V) -> Result<V::Value, Self::Error>
    where
        V: Visitor<'de>,
    {
        IonResult::decoding_error("expected a string value")
    }

    fn deserialize_u32<V>(self, _visitor: V) -> Result<V::Value, Self::Error>
    where
        V: Visitor<'de>,
    {
        IonResult::decoding_error("expected a string value")
    }

    fn deserialize_u64<V>(self, _visitor: V) -> Result<V::Value, Self::Error>
    where
        V: Visitor<'de>,
    {
        IonResult::decoding_error("expected a string value")
    }

    fn deserialize_f32<V>(self, _visitor: V) -> Result<V::Value, Self::Error>
    where
        V: Visitor<'de>,
    {
        IonResult::decoding_error("expected a string value")
    }

    fn deserialize_f64<V>(self, _visitor: V) -> Result<V::Value, Self::Error>
    where
        V: Visitor<'de>,
    {
        IonResult::decoding_error("expected a string value")
    }

    fn deserialize_char<V>(self, _visitor: V) -> Result<V::Value, Self::Error>
    where
        V: Visitor<'de>,
    {
        IonResult::decoding_error("expected a string value")
    }

    fn deserialize_str<V>(self, visitor: V) -> Result<V::Value, Self::Error>
    where
        V: Visitor<'de>,
    {
        visitor.visit_str(&self.key)
    }

    fn deserialize_string<V>(self, visitor: V) -> Result<V::Value, Self::Error>
    where
        V: Visitor<'de>,
    {
        visitor.visit_string(self.key)
    }

    fn deserialize_bytes<V>(self, _visitor: V) -> Result<V::Value, Self::Error>
    where
        V: Visitor<'de>,
    {
        IonResult::decoding_error("expected a string value")
    }

    fn deserialize_byte_buf<V>(self, _visitor: V) -> Result<V::Value, Self::Error>
    where
        V: Visitor<'de>,
    {
        IonResult::decoding_error("expected a string value")
    }

    fn deserialize_option<V>(self, _visitor: V) -> Result<V::Value, Self::Error>
    where
        V: Visitor<'de>,
    {
        IonResult::decoding_error("expected a string value")
    }

    fn deserialize_unit<V>(self, _visitor: V) -> Result<V::Value, Self::Error>
    where
        V: Visitor<'de>,
    {
        IonResult::decoding_error("expected a string value")
    }

    fn deserialize_unit_struct<V>(
        self,
        _name: &'static str,
        _visitor: V,
    ) -> Result<V::Value, Self::Error>
    where
        V: Visitor<'de>,
    {
        IonResult::decoding_error("expected a string value")
    }

    fn deserialize_newtype_struct<V>(
        self,
        _name: &'static str,
        _visitor: V,
    ) -> Result<V::Value, Self::Error>
    where
        V: Visitor<'de>,
    {
        IonResult::decoding_error("expected a string value")
    }

    fn deserialize_seq<V>(self, _visitor: V) -> Result<V::Value, Self::Error>
    where
        V: Visitor<'de>,
    {
        IonResult::decoding_error("expected a string value")
    }

    fn deserialize_tuple<V>(self, _len: usize, _visitor: V) -> Result<V::Value, Self::Error>
    where
        V: Visitor<'de>,
    {
        IonResult::decoding_error("expected a string value")
    }

    fn deserialize_tuple_struct<V>(
        self,
        _name: &'static str,
        _len: usize,
        _visitor: V,
    ) -> Result<V::Value, Self::Error>
    where
        V: Visitor<'de>,
    {
        IonResult::decoding_error("expected a string value")
    }

    fn deserialize_map<V>(self, _visitor: V) -> Result<V::Value, Self::Error>
    where
        V: Visitor<'de>,
    {
        IonResult::decoding_error("expected a string value")
    }

    fn deserialize_struct<V>(
        self,
        _name: &'static str,
        _fields: &'static [&'static str],
        _visitor: V,
    ) -> Result<V::Value, Self::Error>
    where
        V: Visitor<'de>,
    {
        IonResult::decoding_error("expected a string value")
    }

    fn deserialize_enum<V>(
        self,
        _name: &'static str,
        _variants: &'static [&'static str],
        _visitor: V,
    ) -> Result<V::Value, Self::Error>
    where
        V: Visitor<'de>,
    {
        IonResult::decoding_error("expected a string value")
    }

    fn deserialize_identifier<V>(self, visitor: V) -> Result<V::Value, Self::Error>
    where
        V: Visitor<'de>,
    {
        let result = visitor.visit_string(self.key);
        result
    }

    fn deserialize_ignored_any<V>(self, _visitor: V) -> Result<V::Value, Self::Error>
    where
        V: Visitor<'de>,
    {
        IonResult::decoding_error("expected a string value")
    }
}