summaryrefslogtreecommitdiffstats
path: root/vendor/derive_builder/tests/setter_into.rs
blob: b73852d88103dbc595a3eb2d5011975e801f5d45 (plain)
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
#[macro_use]
extern crate pretty_assertions;
#[macro_use]
extern crate derive_builder;

#[derive(Debug, PartialEq, Default, Builder, Clone)]
struct Lorem {
    #[builder(setter(into))]
    foo: String,
}

#[derive(Debug, PartialEq, Default, Builder, Clone)]
#[builder(setter(into))]
struct Ipsum {
    foo: u32,
}

#[test]
fn generic_field() {
    let x = LoremBuilder::default().foo("foo").build().unwrap();

    assert_eq!(
        x,
        Lorem {
            foo: "foo".to_string()
        }
    );
}

#[test]
fn generic_struct() {
    let x = IpsumBuilder::default().foo(42u8).build().unwrap();

    assert_eq!(x, Ipsum { foo: 42u32 });
}