-
Notifications
You must be signed in to change notification settings - Fork 2
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
AppendUrlQueryPairs
& QueryPairsExtension
traits
#266
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
bd01532
Introduce url_query module to help with adding url query parameters
oguzkocer 0dd1576
Implement AppendUrlQueryPairs for PostListParams
oguzkocer eed0627
Add helper macros that implement AsQueryValue for given type
oguzkocer 6a36bca
Implement AsQueryValue for post param types
oguzkocer 252d932
Implement unit tests for QueryPairsExtension
oguzkocer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,9 @@ | ||
use crate::url_query::AppendUrlQueryPairs; | ||
use url::Url; | ||
|
||
#[cfg(test)] | ||
pub fn assert_expected_query_pairs<'a>( | ||
query_pairs: impl IntoIterator<Item = (&'a str, String)>, | ||
expected_pairs: &[(&'a str, &str)], | ||
) { | ||
let mut query_pairs = query_pairs.into_iter().collect::<Vec<_>>(); | ||
let mut expected_pairs: Vec<(&str, String)> = expected_pairs | ||
.iter() | ||
.map(|(k, v)| (*k, v.to_string())) | ||
.collect(); | ||
// The order of query pairs doesn't matter | ||
query_pairs.sort(); | ||
expected_pairs.sort(); | ||
assert_eq!(query_pairs, expected_pairs); | ||
pub fn assert_expected_query_pairs(params: impl AppendUrlQueryPairs, expected_query: &str) { | ||
let mut url = Url::parse("https://example.com").unwrap(); | ||
params.append_query_pairs(&mut url.query_pairs_mut()); | ||
assert_eq!(url.query(), Some(expected_query)); | ||
} |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to implement a
#[derive(AsQueryValue)]
to do the same? This is not a request for changes though.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's, but the implementation would be more complicated because if we are going to have a single derive such as
AsQueryValue
, then we'd need to have options for it, such asfrom=as_str
,from=to_string
etc. Handling that is more complicated, so it add maintenance burden. We could add different derives such asAsQueryValueFromAsStr
,AsQueryValueFromToString
, but that's not any better unfortunately.We are trying to implement derive macros when there is significant benefit to them compared to other solutions. This is not such a case, because the simple
macro_rules!
does a good job and it is easier to understand.Fwiw, for a personal project I'd probably go with the derive macro as I am used to working with them. However, I don't think it's the right choice for this project - at least not at this time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the explanation!