unstable book: default_free_fn · rust-lang/rust@ebb8722 (original) (raw)

File tree

1 file changed

lines changed

1 file changed

lines changed

Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
1 +# `default_free_fn`
2 +
3 +The tracking issue for this feature is: [#73014]
4 +
5 +[#73014]: https://github.com/rust-lang/rust/issues/73014
6 +
7 +------------------------
8 +
9 +Adds a free `default()` function to the `std::default` module. This function
10 +just forwards to [`Default::default()`], but may remove repetition of the word
11 +"default" from the call site.
12 +
13 +Here is an example:
14 +
15 +```rust
16 +#![feature(default_free_fn)]
17 +use std::default::default;
18 +
19 +#[derive(Default)]
20 +struct AppConfig {
21 +foo: FooConfig,
22 +bar: BarConfig,
23 +}
24 +
25 +#[derive(Default)]
26 +struct FooConfig {
27 +foo: i32,
28 +}
29 +
30 +#[derive(Default)]
31 +struct BarConfig {
32 +bar: f32,
33 +baz: u8,
34 +}
35 +
36 +fn main() {
37 +let options = AppConfig {
38 +foo: default(),
39 +bar: BarConfig {
40 +bar: 10.1,
41 +..default()
42 + },
43 + };
44 +}
45 +```