-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Properties 2.0 - Required unless annotated with default value #928
Comments
It's supposed to be |
@jplatte I believe either is supported by Rust now. I thought |
Yeah, either should be possible. I've just never seen the colon syntax used in attributes. AFAIK all builtin attributes use |
@jplatte @mdtusz @AlephAlpha @hgzimmerman I just updated this issue to be a new proposal for how we handle props and would like input. This builds upon the work that @AlephAlpha already did in #881 |
I like the new proposal :) We could maaaybe have |
Good call, that would probably be more in line with expected behavior. It'd be closer to |
No comments from me. Looks like a great improvement for usability and grok-ability! |
I'm trying to implement this. Should we support the old syntax for backward compatibility? |
No need, would complicate things too much |
Properties 2.0
Problem
Properties without
#[props(required)]
or#[props(default = "fn_name")]
are implicitly set to their default value.Proposal
Properties should be treated as required unless indicated otherwise
New syntax:
Old syntax:
Explanation
Now that we have a default attribute for properties, I think it makes sense to require it for indicating when properties are optional. So this means we would drop support for
#[props(required)]
You may ask, why not follow the precedent that
serde
set for default values? LinkSerde was designed before arbitrary token streams were allowed for helper attributes in Rust 1.34.0: https://blog.rust-lang.org/2019/04/11/Rust-1.34.0.html#custom-attributes-accept-arbitrary-token-streams (kudos to @jplatte for pointing this out)
I propose changing the derive props macro attributes from
props
toprop_or_else, prop_or_default
. Reference: https://doc.rust-lang.org/reference/procedural-macros.html#derive-macro-helper-attributes I feel thator
,or_else
andor_default
naming is more Rust-y and theor_else
helps inform developers that the default expression for a prop will not be run at runtime unless a prop is not present.The text was updated successfully, but these errors were encountered: