Allow specifying a default via Default
in a field within Properties
#1761
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Given a struct like
you currently have to specify the default value as part of the param spec builder, e.g.
With this PR, we allow for that to change to
as discussed in #930. This started with what @ranfdev wrote though it changed a little bit.
It's still a bit messier than I was hoping as you still have a few different ways of setting the default value, you can have
which is fine for compat and because not every enum has a built-in default, but you could also do things like
though you shouldn't and probably wouldn't because why would you. It comes out of the generic nature of this and it's probably not worth catching this and erroring out, but it doesn't make the whole thing easier to understand.
The main thing here are
Enum
s but I also added it forchar
s because they do have a default value in Rust. This might however not make as much sense in glib? I'm not sure if there's an actually-correct answer there.As I mentioned in #930 (comment) I don't think you can make this an actual blanket implementation because you need to know a lot about the types and the builder function, which is arbitrary. But covering enums sounds like it's 90% of the use-case, and other libraries can still implement it themselves.