AppendUrlQueryPairs
& QueryPairsExtension
traits
#266
Merged
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.
This PR implements a more structured way to generate the url query for our
Params
types. This helps avoid duplicating the same logic for these types and makes it less error prone. It's both easier to work with and easier to read.For the
AppendUrlQueryPairs
implementation, I've opted for thefn append_query_pairs(&self, query_pairs_mut: &mut QueryPairs) {}
function signature. In general, I'd prefer us to return data as oppose to mutating given data. However, in this case, that meant that we had to clone some of the fields. That's probably OK for the gained ergonomics, but I don't feel comfortable with just probably. There is also no practical downside in this case and it sort of works like a unit function because we start with a completely empty query. Another option could be to return aform_urlencoded::Serializer
type, then turn that into&str
and pass it intourl::Url::set_query
, but we would still pay an extra cost.It's also possible I might have missed an approach that can return an
IntoIterator
, but I don't think it's worth spending too much time on it when we have an acceptable implementation.