I can't wait to see how people use default field values in #Rust!
It felt like an eternity to land this (specially if we count the years of discussion before the, I believe, 3rd RFC was accepted), but as of next nightly you will be able to write
struct Foo {
bar: Type = Type::const_method(),
}
Foo { .. } // implicit `bar: Type::const_method()` call
The main difference between github.com/rust-lang/rust/pull… and derive(Default) is that the latter doesn't support having mandatory fields.
#RustLang
Introduce `default_field_values` feature by estebank · Pull Request #129514 · rust-lang/rust
Initial implementation of #[feature(default_field_values], proposed in rust-lang/rfcs#3681. We now parse const expressions after a = in a field definition, to specify a struct field default value. ...GitHub
modulux reshared this.
Matt Campbell
in reply to Esteban Küber • • •