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
#![crate_type = "lib"]
#![feature(lang_items)]
#![feature(no_core)]
#![no_core]

#[lang = "sized"]
trait Sized {}
#[lang = "copy"]
trait Copy {}

mod my_type {
    pub struct Field;
    pub struct MyType {
        pub field: Field,
    }

    impl MyType {
        /// Instantiates a [`MyTypeBuilder`].
        ///
        /// Use this function to define optional fields.
        pub fn builder() -> MyTypeBuilder {
            MyTypeBuilder { field: Field }
        }

        pub fn with_builder(_: MyTypeBuilder) {}
    }

    pub struct MyTypeBuilder {
        field: Field,
    }

    impl MyTypeBuilder {
        pub fn field(mut self, val: Field) -> Self {
            self.field = val;

            self
        }

        pub fn build(self) -> MyType {
            MyType { field: self.field }
        }
    }
}

pub use my_type::{MyType, Field};