1
use std::collections::HashMap;
2

            
3
use serde::{Deserialize, Serialize};
4

            
5
32
#[derive(Debug, PartialEq, Deserialize, Serialize)]
6
struct UnitStruct;
7

            
8
12
#[derive(Debug, PartialEq, Deserialize, Serialize)]
9
struct NewType(f32);
10

            
11
12
#[derive(Debug, PartialEq, Deserialize, Serialize)]
12
struct TupleStruct(UnitStruct, i8);
13

            
14
48
#[derive(Debug, PartialEq, Eq, Hash, Deserialize, Serialize)]
15
struct Key(u32);
16

            
17
108
#[derive(Debug, PartialEq, Eq, Hash, Deserialize, Serialize)]
18
enum Enum {
19
    Unit,
20
    Bool(bool),
21
    Chars(char, String),
22
}
23

            
24
48
#[derive(Debug, PartialEq, Deserialize, Serialize)]
25
struct Struct {
26
    tuple: ((), NewType, TupleStruct),
27
    vec: Vec<Option<UnitStruct>>,
28
    map: HashMap<Key, Enum>,
29
}
30

            
31
const CONFIG_U_NT: &str = "
32
#![enable(unwrap_newtypes)]
33

            
34
(
35
    tuple: ((), 0.5, ((), -5)),
36
    vec: [
37
        None,
38
        Some(()),
39
    ],
40
    map: {
41
        7: Bool(true),
42
        9: Chars('x', \"\"),
43
        6: Bool(false),
44
        5: Unit,
45
    },
46
)
47
";
48

            
49
#[test]
50
4
fn unwrap_newtypes() {
51
4
    let d: Struct = ron::de::from_str(CONFIG_U_NT).expect("Failed to deserialize");
52
4

            
53
4
    println!("unwrap_newtypes: {:#?}", d);
54
4

            
55
4
    let s = ron::ser::to_string_pretty(
56
4
        &d,
57
4
        ron::ser::PrettyConfig::default().extensions(ron::extensions::Extensions::UNWRAP_NEWTYPES),
58
4
    )
59
4
    .expect("Failed to serialize");
60
4

            
61
4
    let d2: Struct = ron::de::from_str(&s).expect("Failed to deserialize");
62
4

            
63
4
    assert_eq!(d, d2);
64
4
}
65

            
66
const CONFIG_I_S: &str = "
67
#![enable(implicit_some)]
68

            
69
(
70
    tuple: ((), (0.5), ((), -5)),
71
    vec: [
72
        None,
73
        (),
74
        UnitStruct,
75
        None,
76
        (),
77
    ],
78
    map: {
79
        (7): Bool(true),
80
        (9): Chars('x', \"\"),
81
        (6): Bool(false),
82
        (5): Unit,
83
    },
84
)
85
";
86

            
87
#[test]
88
4
fn implicit_some() {
89
4
    let d: Struct = ron::de::from_str(CONFIG_I_S).expect("Failed to deserialize");
90
4

            
91
4
    println!("implicit_some: {:#?}", d);
92
4
}