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
#[cfg(feature = "std")]
mod std_support {
use crate::{
std::{
string::String,
vec::Vec,
},
value::{
owned::Kind,
OwnedValue,
Value,
},
};
#[derive(Debug, Clone, PartialEq)]
pub enum Token {
MapBegin(Option<usize>),
MapEnd,
SeqBegin(Option<usize>),
SeqEnd,
Signed(i64),
Unsigned(u64),
Float(f64),
BigSigned(i128),
BigUnsigned(u128),
Bool(bool),
Str(String),
Char(char),
None,
}
pub fn tokens(v: impl Value) -> Vec<Token> {
OwnedValue::collect(v)
.tokens()
.unwrap()
.iter()
.filter_map(|token| match token.kind {
Kind::MapBegin(len) => Some(Token::MapBegin(len)),
Kind::MapEnd => Some(Token::MapEnd),
Kind::SeqBegin(len) => Some(Token::SeqBegin(len)),
Kind::SeqEnd => Some(Token::SeqEnd),
Kind::Signed(v) => Some(Token::Signed(v)),
Kind::Unsigned(v) => Some(Token::Unsigned(v)),
Kind::BigSigned(v) => Some(Token::BigSigned(v)),
Kind::BigUnsigned(v) => Some(Token::BigUnsigned(v)),
Kind::Float(v) => Some(Token::Float(v)),
Kind::Bool(v) => Some(Token::Bool(v)),
Kind::Char(v) => Some(Token::Char(v)),
Kind::Str(ref v) => Some(Token::Str((*v).clone())),
Kind::None => Some(Token::None),
_ => None,
})
.collect()
}
}
#[cfg(feature = "std")]
pub use self::std_support::*;