Allow different types on with_meta arguments#301
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR removes an unnecessary type constraint in the with_meta method that previously required both key and value parameters to be the same type. The change eliminates redundant string conversions where callers had to convert values to strings just to satisfy the single generic type parameter.
Changes:
- Updated
with_metasignature to accept two differentToStringtypes instead of one - Simplified call sites by removing unnecessary
.to_string()conversions
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| crates/twirp/src/error.rs | Modified with_meta method signature to accept separate generic types for key and value |
| crates/twirp/src/server.rs | Removed redundant .to_string() calls when passing error values to with_meta |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Before this change we constrained both the key and the value on
with_metato be the same type. This resulted in stuff likeblah.with_meta("key", &value.to_string()), which is basically turningvaluefrom aT: ToStringinto aStringinto a&strand then inside the function back to aStringagain. Twice the allocation, twice the fun.This PR ruins that fun by allowing the key and value to be different kinds of
ToString.This could be more idiomatic as a pair of
impl Into<String>since that allows things like an owned string to not have to reallocate, but that would be a breaking change so this will perhaps do for now. ThoughToStringdoes allow anything withDisplayto also be used here which is maybe nice?