summaryrefslogtreecommitdiffstats
path: root/vendor/derive_builder/tests/generic_with_default.rs
blob: 81a5eaa23138e35c5846bbb99b9122172f0e9e79 (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
36
37
38
#[macro_use]
extern crate derive_builder;
#[macro_use]
extern crate pretty_assertions;

/// Struct taken from `@shockham/caper` to make sure we emit the correct
/// code for struct-level defaults in tandem with generics.
#[derive(Builder, Clone, PartialEq)]
#[builder(default)]
pub struct RenderItem<T: Default> {
    /// The vertices representing this items mesh
    pub vertices: Vec<()>,
    /// Whether the item is active/should be rendered
    pub active: bool,
    /// The name of the RenderItem for lookup
    pub name: String,
    /// Tag Type for grouping similar items
    pub tag: T,
}

impl<T: Default> Default for RenderItem<T> {
    fn default() -> Self {
        RenderItem {
            vertices: Default::default(),
            active: true,
            name: "ri".into(),
            tag: Default::default(),
        }
    }
}

#[test]
fn create_with_string() {
    let ri: RenderItem<String> = RenderItemBuilder::default().build().unwrap();
    assert_eq!(ri.tag, "");
    assert_eq!(ri.name, "ri");
    assert!(ri.active);
}