Skip to content

Commit 6152213

Browse files
authored
Merge branch 'master' into state_pattern
2 parents 6a272c2 + a22d81d commit 6152213

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

patterns/creational/builder.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff 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)]
1624
pub 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)

0 commit comments

Comments
 (0)