hachyderm.io is one of the many independent Mastodon servers you can use to participate in the fediverse.
Hachyderm is a safe space, LGBTQIA+ and BLM, primarily comprised of tech industry professionals world wide. Note that many non-user account types have restrictions - please see our About page.

Administered by:

Server stats:

9.6K
active users

I can't wait to see how people use default field values in !
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.

Esteban Küber :rust:

Default fields values are now live on nightly ! Go wild and report bugs 😃

@ekuber is this just a syntactic sugar for implementing Default?

@piggo You can't use traits to encode "some of these fields are mandatory". Default is all are optional. The normal state is all are mandatory. This feature sits in the middle.

@ekuber Really appreciating this, it's basically eliminated all my manual Default implementations

@ekuber looks nice but isn't this just less boilerplate?

@psyhackological isn't it all? Who needs for when you have while? Who needs if let when you have match?

@ekuber So good. :) Combined with #[non_exhaustive], the ".." syntax is a now very convenient way to maintain API compatibility. Typing "..Default::default()" was driving me nuts. :)