Skip to content

Implement IntoUrl for &Url#2962

Open
jorendorff wants to merge 1 commit intoseanmonstar:masterfrom
jorendorff:impl-intourl-for-ref-url
Open

Implement IntoUrl for &Url#2962
jorendorff wants to merge 1 commit intoseanmonstar:masterfrom
jorendorff:impl-intourl-for-ref-url

Conversation

@jorendorff
Copy link

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 String should just take a String argument. What makes this case special is that there's already a tacit admission that convenience matters here, i.e. IntoUrl existing and already accepting multiple types that require copying strings and parsing.

It's true that supporting &Url makes it possible for user code to do an extraneous clone unwittingly, but that's common in Rust. On the other hand, rejecting &Url makes it less convenient to use the more appropriate type, encouraging format! and Strings 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.

@jorendorff
Copy link
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"));
}

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.

1 participant