Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upSupport default literals #368
Comments
dtolnay
added
enhancement
derive
labels
Jun 10, 2016
dtolnay
referenced this issue
Jun 10, 2016
Merged
Simplify implementation of #[serde(default=...)] #367
This comment has been minimized.
This comment has been minimized.
|
This needs to be fleshed out a lot more before it can be implemented so please chime in if you have ideas for how this should work. I am glad we implemented
|
dtolnay
self-assigned this
Jun 13, 2016
This comment has been minimized.
This comment has been minimized.
|
Seems like an easy route would be |
dtolnay
removed their assignment
Jan 24, 2017
This comment has been minimized.
This comment has been minimized.
rekka
commented
Feb 3, 2017
|
Would it be possible to support closures? Something like: #[serde(default="||{ 0.1 }")]
pub n: f32 |
This comment has been minimized.
This comment has been minimized.
skorokithakis
commented
Jul 28, 2017
|
The closure route would be the most logical for me (and the first thing I tried when exploring how to do what I wanted). However, I think I would have preferred |
dtolnay
referenced this issue
Sep 3, 2017
Closed
#[serde(default="false")] failed to parse path: "false" #1030
This comment has been minimized.
This comment has been minimized.
|
As reported in #1031, unit variants would be nice to support as well. Rust no longer enforces that the value in an attribute is a literal. |
This comment has been minimized.
This comment has been minimized.
Fiedzia
commented
Apr 20, 2018
•
|
Any progress on that? Right now I am forced to write functions like |
This comment has been minimized.
This comment has been minimized.
alexbool
commented
May 20, 2018
|
I agree with @sfackler and think |
scholtzan
referenced this issue
Jul 10, 2018
Merged
Add default serializer for SelectionModifier in FindNext and FindPrevious #741
This comment has been minimized.
This comment has been minimized.
richardwhiuk
commented
Jan 24, 2019
|
Surely In fact, that can replace any of the current usage right? |
This comment has been minimized.
This comment has been minimized.
jhpratt
commented
Jan 30, 2019
|
@dtolnay Would a PR be accepted for this? Using proc macros, it shouldn't be terribly difficult to generate a function (which can have an I can certainly work on this if it's a feature you and the other maintainers are interested in. |
This comment has been minimized.
This comment has been minimized.
norru
commented
Feb 20, 2019
|
Just being bitten by this, currently writing a lot of |
This comment has been minimized.
This comment has been minimized.
jplatte
commented
Feb 20, 2019
|
I don't know how to drive this forward, but I think a very small change to the compiler (or some other trick I have yet to find) could enable the existing attribute to work with values too: https://internals.rust-lang.org/t/implementing-traits-for-function-types/5888 |
This comment has been minimized.
This comment has been minimized.
jhpratt
commented
Feb 20, 2019
|
@dtolnay Would a PR be accepted that resolves this? I asked a few weeks ago and received no answer. I don't think there's any question people want this. |
This comment has been minimized.
This comment has been minimized.
est31
commented
Feb 23, 2019
|
This crate could also give inspiration: https://github.com/idanarye/rust-smart-default It allows specifying literals as well as code for the default value. |
dtolnay commentedJun 10, 2016
There is an ambiguity when the field is of function type so we need to figure that out.