Tracking issue for RFC 3681: Default field values · Issue #132162 · rust-lang/rust

https://github.com/rust-lang/rust/issues/132162

29 points · 6 comments · view on lemmy.world

6 Comments

robinm@programming.dev · 5 pts · 1y

It's really nice to see this RFC progress

snaggen@programming.dev · 5 pts · 1y

I think this would be a nice improvement to reduce boiler plate.

SorteKanin@feddit.dk · 4 pts · 1y

Hmmm... I guess I don't see why not?

d_k_bo@feddit.org · 4 pts · 1y (2 replies)

This is really great and would solve the problem that led me to create constructor-lite.

With this RFC, its usage could be replaced with

#[derive(Debug, PartialEq)]
struct Movie {
    title: String,
    year: Option<u16> = None,
}

assert_eq!(
    Movie { title: "Star Wars".to_owned(), .. },
    Movie { title: "Star Wars".to_owned(), year: None },
)

SorteKanin@feddit.dk · 2 pts · 1y (1 reply)

Think you would need Movie { title: "Star Wars".to_owned(), .. }, the .. is mandatory.

d_k_bo@feddit.org · 2 pts · 1y

Thanks, that was an oversight on my part.