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
#![feature(try_trait)]
#![warn(clippy::all,
clippy::restriction,
clippy::pedantic,
clippy::cargo,
clippy::nursery)]
#![allow(clippy::blanket_clippy_restriction_lints,
clippy::enum_glob_use,
clippy::implicit_return,
clippy::cargo_common_metadata,
clippy::multiple_crate_versions,
clippy::wildcard_dependencies,
clippy::integer_arithmetic,
clippy::wildcard_enum_match_arm,
clippy::as_conversions,
clippy::panic_in_result_fn,
clippy::cast_possible_wrap,
clippy::unimplemented )]
use serde::Deserialize;
mod error;
mod serialize;
use error::Error;
#[inline]
pub fn from_str<'d, T>(inp: &'d str) -> Result<T, Error>
where T: Deserialize<'d>,
{
let mut deserializer = serialize::Deserializer::from_str(inp);
let t = T::deserialize(&mut deserializer)?;
Ok(t)
}
#[cfg(test)]
#[allow(clippy::unwrap_used)]
mod tests
{
use serde::Deserialize;
#[derive(Debug, Clone, PartialEq, Deserialize)]
struct Simple
{
string: String,
int: u8,
neg_int: i8,
r#bool: bool,
newline: String,
escapes: String,
multiline: String,
}
#[test]
fn simple()
{
let simple_str = "
string = 'foobar'
int = 1
neg-int = -1
bool = no
newline = 'foo\\nbar'
escapes = 'foo\\\'bar'
multiline = '
foo
bar'
";
assert_eq!(Simple { string: "foobar".to_owned(),
int: 1,
neg_int: -1,
bool: false,
newline: "foo\nbar".to_owned(),
escapes: "foo\\\'bar".to_owned(),
multiline: "foo\nbar".to_owned(), },
super::from_str(simple_str).unwrap(),);
}
}