Tracking issue for RFC 3681: Default field values · Issue #132162 · rust-lang/rust (github.com)
from Apoplexy@lemmy.world to rust@programming.dev on 08 Dec 01:06
https://lemmy.world/post/22890671

#rust

threaded - newest

SorteKanin@feddit.dk on 08 Dec 01:33 next collapse

Hmmm… I guess I don’t see why not?

robinm@programming.dev on 08 Dec 03:14 next collapse

It’s really nice to see this RFC progress

snaggen@programming.dev on 08 Dec 09:32 next collapse

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

d_k_bo@feddit.org on 08 Dec 10:50 collapse

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 on 10 Dec 13:40 collapse

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

d_k_bo@feddit.org on 10 Dec 15:48 collapse

Thanks, that was an oversight on my part.