Open
Conversation
Author
|
In case it's not obvious, this would be nice anywhere something could go wrong after reqwest's part is done, and the url is then wanted for the error: let response = reqwest::get(&url).await?.error_for_status()?.json().await?;
if response.action == "jump" && response.how_high.is_none() {
return Err(MyApiError::new(url, "missing how_high field in response"));
} |
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.
This was previously discussed in #412. Feel free to just close this, and accept my apology for wasting your time in that case. I just think maybe the reasoning there should be reconsidered.
In the general case, I agree: functions that need e.g. an owned
Stringshould just take aStringargument. What makes this case special is that there's already a tacit admission that convenience matters here, i.e.IntoUrlexisting and already accepting multiple types that require copying strings and parsing.It's true that supporting
&Urlmakes it possible for user code to do an extraneous clone unwittingly, but that's common in Rust. On the other hand, rejecting&Urlmakes it less convenient to use the more appropriate type, encouragingformat!andStrings instead. On the whole I imagine this makes the world's code a little worse? Who can say.On the third hand, we are most likely about to do a network request. Presumably that swamps the overhead of copying a single string. Maybe it's best to optimize for convenience here. Thanks for hearing me out and thanks for reqwest.