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 {
1313 bar : String ,
1414}
1515
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 )]
1624pub struct FooBuilder {
1725 // Probably lots of optional fields.
1826 bar : String ,
@@ -103,6 +111,6 @@ as well as the `FooBuilder::new().a().b().build()` style.
103111- [ Description in the style guide] ( https://web.archive.org/web/20210104103100/https://doc.rust-lang.org/1.12.0/style/ownership/builders.html )
104112- [ derive_builder] ( https://crates.io/crates/derive_builder ) , a crate for automatically
105113 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.
107115- [ Builder pattern (wikipedia)] ( https://en.wikipedia.org/wiki/Builder_pattern )
108116- [ 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