prost
prost copied to clipboard
Structs should have option to generate with default values rather than Option
https://developers.google.com/protocol-buffers/docs/proto3#default
Take a simple example
message Coords {
int32 x = 1;
int32 y = 2;
}
message Player {
string uuid = 1;
Coords coords = 2;
}
This will generate with Player.coords
being an Option
. This is reasonable, compared to the has_coords
that most other languages have. However, most other languages would still have the default value in for coords
. If you know that coords is there and valid, you don't need to mess about.
Option
is zero cost in running but can be significant clutter in code if not necessary. I understand that for many people, this is how they want their proto to generate. It would be nice to have the option to remove option and just put the default value if not present.
I agree this would be an awesome usability win instead of having to .context("Field unexpectedly asbent")?
on every field.
Just ran into this and was very confused why a bunch of fields are "optional"
I don't feel like Option
is ever the right choice for default values, if the optimization is wanted it should be another type
Tonic view: I wonder if an option would be to expand on .extern_path()
and similar APIs on the builder in tonic. Something like .use_default("name of type")
to make it use Default::default
rather than wrapping in Option
.