File tree Expand file tree Collapse file tree 1 file changed +0
-26
lines changed Expand file tree Collapse file tree 1 file changed +0
-26
lines changed Original file line number Diff line number Diff line change @@ -176,32 +176,6 @@ use example::Example;
176
176
let ex = Example :: new ();
177
177
```
178
178
179
- Constructors for structs with sensible defaults allow clients to concisely
180
- override using the [ struct update syntax] .
181
-
182
- [ struct update syntax ] : https://doc.rust-lang.org/book/first-edition/structs.html#update-syntax
183
-
184
- ``` rust
185
- pub struct Config {
186
- pub color : Color ,
187
- pub size : Size ,
188
- pub shape : Shape ,
189
- }
190
-
191
- impl Config {
192
- pub fn new () -> Config {
193
- Config {
194
- color : Brown ,
195
- size : Medium ,
196
- shape : Square ,
197
- }
198
- }
199
- }
200
-
201
- // In user's code.
202
- let config = Config { color : Red , .. Config :: new () };
203
- ```
204
-
205
179
The name ` new ` should generally be used for the primary method of instantiating
206
180
a type. Sometimes it takes no arguments, as in the examples above. Sometimes it
207
181
does take arguments, like [ ` Box::new ` ] which is passed the value to place in the
You can’t perform that action at this time.
0 commit comments