Skip to content
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

Matching fields of builtin types? (string/int/etc) #145

Open
leeola opened this issue Jan 14, 2019 · 4 comments
Open

Matching fields of builtin types? (string/int/etc) #145

leeola opened this issue Jan 14, 2019 · 4 comments

Comments

@leeola
Copy link

leeola commented Jan 14, 2019

I'm trying to add default support for the Twirp JSON spec / Protobuf compatibility. As far as I am aware, this means adding a default value to every scalar type in Protobuf. In theory this should be simple to do with Serde, but I'm having trouble applying an attribute to all fields of X type. Eg:

  conf.field_attribute("match strings", "#[serde(default_value = \"\")]");

The goal being that match strings would match Foo.bar and Foo.baz, if they're of proto type string. How can this be done? I'm having trouble making sense of the documentation for this use case.

@danburkert
Copy link
Collaborator

danburkert commented Jan 14, 2019 via email

@leeola
Copy link
Author

leeola commented Jan 14, 2019

Hi, my trouble is in understanding Prost's ability to a Rust attribute to all Proto fields of a specific type. Eg, if I want to apply an Attribute to all string fields with Prost, how would I do that?

@danburkert
Copy link
Collaborator

danburkert commented Jan 14, 2019 via email

@leeola
Copy link
Author

leeola commented Jan 14, 2019

Gotcha, appreciate the answer.

Would you be opposed to PRs for that feature, if possible? The goal would be to apply attributes on fields based on the type; in this example that seems to be required to ensure that fields have default values when Serde serializes. Currently, without this feature, Serde is failing to serialize.

As you mentioned, Proto specifies default values but serializing JSON to a Prost data structure will fail.

It's worth noting that when I'm mentioning JSON, I'm referring to the Twirp JSON spec, which is a bit different than Protobuf encoded JSON, I believe. This is sort of irrelevant to the discussion, I just didn't want to confuse anyone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants