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

Make field mask inner public #465

Merged
merged 3 commits into from
Jan 6, 2024
Merged

Conversation

andrewbaxter
Copy link

The inner value was private so it couldn't be constructed directly (without deserializing from a string indirectly). Creating it directly seems safer than deserializing, especially since I'm unfamiliar with the format.

Was it intended for this to be constructed directly or is there another mechanism for setting these up? I thought the api might do it directly but it doesn't atm afaict.

Copy link
Owner

@Byron Byron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably easiest to allow users to just let users create such masks directly, after all they serialize into comma-separated lists like "a,b"

However, it turns out that these must be snake-case, and anything the user passes in should adhere to that.

Thus I recommend adding a constructor instead that converts to snake-case, just like the deserialization (FromStr) does.

@andrewbaxter
Copy link
Author

Okay sounds good. I made the change, and tested it locally although I was already using a non-snake-case string "state".

That said, as you mentioned the specification isn't exactly simple. I think in order to use the field correctly in the first place users will have to read up on its use, and if despite doing that they're passing the wrong values in it might be best to allow the api call to fail to let them know they need to re-read. Magically lowercasing but not checking field existence, etc might be more complex implicit behavior.

@andrewbaxter
Copy link
Author

Or were you thinking it should just be FieldMask(pub String)? I wouldn't mind that, it'd convey to users that they're completely on their own which I think might be good.

Copy link
Owner

@Byron Byron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

The type already exhibits this behaviour and it internally wants to have snake-case - the constructor enforces this invariant and that seems fine to me.
Nothing changes otherwise, the user would always have to know valid strings for field names and there is no type-safety for that (or it isn't implemented).

Or were you thinking it should just be FieldMask(pub String)? I wouldn't mind that, it'd convey to users that they're completely on their own which I think might be good.

No, let's just keep it as it is and not overthink this type.

google-apis-common/src/field_mask.rs Show resolved Hide resolved
Copy link
Owner

@Byron Byron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for your help!

@Byron Byron merged commit 00a3e18 into Byron:main Jan 6, 2024
1 of 2 checks passed
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

Successfully merging this pull request may close these issues.

2 participants