-
Notifications
You must be signed in to change notification settings - Fork 533
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
Allow ignoring fields #174
Comments
I really need this |
I also found myself needing this. I have a existing very large struct and I don't want to clone it only to drop a field... |
I don't understand what you are trying to do. Can you provide an reproducible example? |
I do not think this applies to types that use Example: #[derive(Message)]
struct Event {
#[prost(uint32)]
id: u32,
#[prost(skip)]
version: u32,
/// ... other fields
} I have no interest in storing It doesn't really matter what it's called. |
What do you expect the value to be when such a struct is deserialized? Having a |
I'm open to possibilities, but I'd imagine rules similar to
Revising the setup, it might be something more contrived like: fn get_answer() -> u32 {
42
}
#[derive(Message)]
struct Event {
#[prost(uint32)]
id: u32,
#[prost(skip)]
version: u32,
#[prost(skip, default_value = "get_answer")]
answer_to_the_universe: u32,
#[prost(skip)]
answer: Option<String>,
/// ... other fields
} The implementation macro would expand struct initialization to something like: let mut message = Event {
id: Default::default(),
version: Default::default(),
answer_to_the_universe: get_answer(),
answer: Default::default()
} At this point, things can resume down the |
If one has a structure which carries data and temporary state. One might want to encode only the data and ignore the rest.
It seems to me that the simplest way to implement this would be to simply ignore fields which are not annotated.
As part of this I'd also stop generating
impl Default
since a user may very well want to implement it himself to initialize the ignored fields correctly.For generated code a simple
#[derive(Default
should do the trick IIUC.Either way this would be a breaking change.
Suggestions?
I'd be happy to implement.
The text was updated successfully, but these errors were encountered: