File tree Expand file tree Collapse file tree 1 file changed +9
-1
lines changed Expand file tree Collapse file tree 1 file changed +9
-1
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,14 @@ pub struct Foo {
13
13
bar : String ,
14
14
}
15
15
16
+ impl Foo {
17
+ // This method will help users to discover the builder
18
+ pub fn builder () -> FooBuilder {
19
+ FooBuilder :: default ()
20
+ }
21
+ }
22
+
23
+ #[derive(Default )]
16
24
pub struct FooBuilder {
17
25
// Probably lots of optional fields.
18
26
bar : String ,
@@ -103,6 +111,6 @@ as well as the `FooBuilder::new().a().b().build()` style.
103
111
- [ Description in the style guide] ( https://web.archive.org/web/20210104103100/https://doc.rust-lang.org/1.12.0/style/ownership/builders.html )
104
112
- [ derive_builder] ( https://crates.io/crates/derive_builder ) , a crate for automatically
105
113
implementing this pattern while avoiding the boilerplate.
106
- - [ Constructor pattern] ( ../idioms/ctor.md ) for when construction is simpler.
114
+ - [ Constructor pattern] ( ../../ idioms/ctor.md ) for when construction is simpler.
107
115
- [ Builder pattern (wikipedia)] ( https://en.wikipedia.org/wiki/Builder_pattern )
108
116
- [ Construction of complex values] ( https://web.archive.org/web/20210104103000/https://rust-lang.github.io/api-guidelines/type-safety.html#c-builder )
You can’t perform that action at this time.
0 commit comments