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
#[derive(Clone, PartialEq, Debug)]
pub enum Token<'a> {
    /// A serialized `bool`.
    Bool(bool),

    /// A serialized `i8`.
    I8(i8),

    /// A serialized `i16`.
    I16(i16),

    /// A serialized `i32`.
    I32(i32),

    /// A serialized `i64`.
    I64(i64),

    /// A serialized `u8`.
    U8(u8),

    /// A serialized `u16`.
    U16(u16),

    /// A serialized `u32`.
    U32(u32),

    /// A serialized `u64`.
    U64(u64),

    /// A serialized `f32`.
    F32(f32),

    /// A serialized `f64`.
    F64(f64),

    /// A serialized `char`.
    Char(char),

    /// A serialized `str`.
    Str(&'a str),

    /// A serialized `String`.
    String(String),

    /// A serialized `[u8]`
    Bytes(&'a [u8]),

    /// A serialized `ByteBuf`
    ByteBuf(Vec<u8>),

    /// The header to a serialized `Option<T>`.
    ///
    /// `None` is serialized as `Option(false)`, while `Some` is serialized as `Option(true)`, then
    /// the value contained in the option.
    Option(bool),

    /// A serialized `()`.
    Unit,

    /// A serialized unit struct of the given name.
    UnitStruct(&'a str),

    /// The header to a serialized newtype struct of the given name.
    ///
    /// Newtype structs are serialized with this header, followed by the value contained in the
    /// newtype struct.
    StructNewType(&'a str),

    /// The header to an enum of the given name.
    ///
    /// This token is only used for deserializers, and ensures that the following tokens are read as
    /// an enum. Because this is never emitted by serializers, calling `assert_ser_tokens` or
    /// `assert_tokens` will fail if this token is used.
    ///
    /// TODO: Trash this.
    EnumStart(&'a str),

    /// A unit variant of an enum of the given name, of the given name.
    ///
    /// The first string represents the name of the enum, and the second represents the name of the
    /// variant.
    EnumUnit(&'a str, &'a str),

    /// The header to a newtype variant of an enum of the given name, of the given name.
    ///
    /// The first string represents the name of the enum, and the second represents the name of the
    /// variant. The value contained within this enum works the same as `StructNewType`.
    EnumNewType(&'a str, &'a str),

    /// The header to a sequence of the given length.
    ///
    /// These are serialized via `serialize_seq`, which takes an optional length. After this
    /// header is a list of elements, followed by `SeqEnd`.
    SeqStart(Option<usize>),

    /// The header to an array of the given length.
    ///
    /// These are serialized via `serialize_seq_fized_size`, which requires a length. After this
    /// header is a list of elements, followed by `SeqEnd`.
    SeqArrayStart(usize),

    /// A separator, which occurs *before* every element in a sequence.
    ///
    /// Elements in sequences are represented by a `SeqSep`, followed by the value of the element.
    SeqSep,

    /// An indicator of the end of a sequence.
    SeqEnd,

    /// The header to a tuple of the given length, similar to `SeqArrayStart`.
    TupleStart(usize),

    /// A separator, similar to `SeqSep`.
    TupleSep,

    /// An indicator of the end of a tuple, similar to `SeqEnd`.
    TupleEnd,

    /// The header to a tuple struct of the given name and length.
    TupleStructStart(&'a str, usize),

    /// A separator, similar to `TupleSep`.
    TupleStructSep,

    /// An indicator of the end of a tuple struct, similar to `TupleEnd`.
    TupleStructEnd,

    /// The header to a map of the given length.
    ///
    /// These are serialized via `serialize_map`, which takes an optional length. After this header
    /// is a list of key-value pairs, followed by `MapEnd`.
    MapStart(Option<usize>),

    /// A separator, which occurs *before* every key-value pair in a map.
    ///
    /// Elements in maps are represented by a `MapSep`, followed by a serialized key, followed
    /// by a serialized value.
    MapSep,

    /// An indicator of the end of a map.
    MapEnd,

    /// The header of a struct of the given name and length, similar to `MapStart`.
    StructStart(&'a str, usize),

    /// A separator, similar to `MapSep`.
    StructSep,

    /// An indicator of the end of a struct, similar to `MapEnd`.
    StructEnd,

    /// The header to a tuple variant of an enum of the given name, of the given name and length.
    EnumSeqStart(&'a str, &'a str, usize),

    /// A separator, similar to `TupleSep`.
    EnumSeqSep,

    /// An indicator of the end of a tuple variant, similar to `TupleEnd`.
    EnumSeqEnd,

    /// The header of a struct variant of an enum of the given name, of the given name and length,
    /// similar to `StructStart`.
    EnumMapStart(&'a str, &'a str, usize),

    /// A separator, similar to `StructSep`.
    EnumMapSep,

    /// An indicator of the end of a struct, similar to `StructEnd`.
    EnumMapEnd,
}