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 https://github.com/rust-lang/rust/pull/129514 and derive(Default) is that the latter doesn't support having mandatory fields.
[#]RustLang
=> More informations about this toot | More toots from ekuber@hachyderm.io
Default fields values are now live on nightly #Rust! Go wild and report bugs 😃
[#]RustLang
=> View attached media | View attached media
=> More informations about this toot | More toots from ekuber@hachyderm.io
@ekuber Ooh, this might convince me to raise my project's MSRV while the project is still pre-1.0.
=> More informations about this toot | More toots from matt@toot.cafe
@ekuber nailed it. Very exciting.
=> More informations about this toot | More toots from onelson@mastodon.social
@ekuber #[non_exhaustive] compatibility when? 😛
=> More informations about this toot | More toots from jplatte@social.tchncs.de
@jplatte Coming. Didn't want to try and land the whole thing in one go. That would be a nightmare to rebase and unfair for the reviewers.
=> More informations about this toot | More toots from ekuber@hachyderm.io
@ekuber oh yeah, of course. I was 100% joking, did not expect it to be something you're already working on! :blobcataww:
=> More informations about this toot | More toots from jplatte@social.tchncs.de
@ekuber that is a really nice ergonomics win
=> More informations about this toot | More toots from swiftcoder@mastodon.social
@ekuber
That's so great ! 💪
What a great gift for the new year 🎉
=> More informations about this toot | More toots from Aedius@lavraievie.social
@ekuber actually WOW really nice! How does it play with default ?
Edit: just had to click the link 😅 very nice!
=> More informations about this toot | More toots from shavounet@piaille.fr
@ekuber Tracking clap support for default field values in https://github.com/clap-rs/clap/issues/5839
=> More informations about this toot | More toots from epage@hachyderm.io
@ekuber Definitely hyped for that. We have a crate for a driver with structures defined for around 50 commands, and most have a lot of optional fields.
Right now we use typed-builder to make that usable, but being able to use rust syntax would be amazing!!
https://docs.rs/se05x/latest/se05x/se05x/commands/index.html
=> More informations about this toot | More toots from sgued@pouet.chapril.org
@ekuber I'm new to Rust and I thought I just mustn't have worked out how to set default values yet. So this will be rather welcome.
=> More informations about this toot | More toots from carbsrule_en@polyglot.city
@carbsrule_en in the meantime, look for typed builder crates, which aren't as ergonomic but are better than nothing.
=> More informations about this toot | More toots from ekuber@hachyderm.io
@ekuber
@carbsrule_en
Builders do support the incremental use case where different parts of the code do building, and cloning a builder to form a template, and such.
Maybe I haven't done enough reading but I don't think default field values can replace all builder use cases, right?
Not that they have to. I'm intrigued by the possibilities of default field values, so thinking it through.This looks like a better way to support the default parameter use case for instance.
=> More informations about this toot | More toots from faassen@fosstodon.org
@faassen indeed. If you have a situation where you want to pass a "partially constructed" value around, then you still need the builder pattern.
=> More informations about this toot | More toots from ekuber@hachyderm.io
@ekuber is this just a syntactic sugar for implementing Default?
=> More informations about this toot | More toots from piggo@piggo.space
@piggo @ekuber I believe it's more of a language feature than an extension for Default
. Check out the RFC: https://rust-lang.github.io/rfcs/3681-default-field-values.html
=> More informations about this toot | More toots from bd103@hachyderm.io
@bd103 @ekuber oh, that's a bit confusing
=> More informations about this toot | More toots from piggo@piggo.space
@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.
=> More informations about this toot | More toots from ekuber@hachyderm.io
@ekuber Really appreciating this, it's basically eliminated all my manual Default implementations
=> More informations about this toot | More toots from khionu@hachyderm.io
@ekuber yay!
=> More informations about this toot | More toots from ubik@fedi.turbofish.cc
@ekuber looks nice but isn't this just less boilerplate?
=> More informations about this toot | More toots from psyhackological@fosstodon.org
@psyhackological isn't it all? Who needs for when you have while? Who needs if let when you have match?
=> More informations about this toot | More toots from ekuber@hachyderm.io
@ekuber hmm true...
=> More informations about this toot | More toots from psyhackological@fosstodon.org
@ekuber Prefer issues be opened as usual, DM, or something else?
=> More informations about this toot | More toots from jhpratt@mastodon.social
@jhpratt tickets on the issue tracker referencing the tracking issue and tagged as F-default_field_values would be best
=> More informations about this toot | More toots from ekuber@hachyderm.io
@ekuber Took maybe an hour to figure out how to minimize it, but the first bug for the feature is now open :)
https://github.com/rust-lang/rust/issues/134298
=> More informations about this toot | More toots from jhpratt@mastodon.social
@jhpratt it looks like I need to extend what the Well formed check does for structs with defaults. You would think that they stretch without a default would also error.
This is a nice milestone!
=> More informations about this toot | More toots from ekuber@hachyderm.io
@ekuber it's heavily minimized from real-world code in the time crate (with the addition of default values). Inference is a wonderful thing!
=> More informations about this toot | More toots from jhpratt@mastodon.social
@ekuber i don't even use bevy, but i'm most excited for them (they've been exporting default in their prelude)
=> More informations about this toot | More toots from mehbark@critter.cafe
@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. :)
=> More informations about this toot | More toots from aedm@mastodon.gamedev.place This content has been proxied by September (3851b).Proxy Information
text/gemini