Skip to content
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

feature: impl TryFrom<&str> for Url #568

Closed
yoshuawuyts opened this issue Dec 5, 2019 · 3 comments · Fixed by #569
Closed

feature: impl TryFrom<&str> for Url #568

yoshuawuyts opened this issue Dec 5, 2019 · 3 comments · Fixed by #569

Comments

@yoshuawuyts
Copy link
Contributor

Having impl TryFrom<&str> for Url would be fantastic because it would allow passing both Url and &str to the same API through an impl TryInto<Url> bound.

Example

fn make_request(impl TryInto<Url>) -> Result<(), ParseError>;
// Pass a literal directly.
let mut req = make_request("https://example.com")?;

// Create a url, manipulate it, then pass it.
let url = Url::parse("https://example.com")?;
validate_url(&url)?;
let mut req = make_request(url)?;

Caveats

The only caveat here is that TryFrom and TryInto were stabilized in Rust 1.34, and the minimum guaranteed Rust version for url is 1.33, which means this would likely would require a major version bump.


Thanks!

@tmccombs
Copy link
Contributor

tmccombs commented Dec 5, 2019

which means this would likely would require a major version bump

Or add a feature to enable this (and possibly other features that require a more recent version of rust)

@yoshuawuyts
Copy link
Contributor Author

yoshuawuyts commented Dec 5, 2019

@tmccombs oh brilliant; didn't think of that. Issued #569 with an implementation. Hope it's good!

edit: Oops, misclicked and accidentally closed this issue. Reopened!

@yoshuawuyts
Copy link
Contributor Author

Ah since #566 landed the minimum supported Rust version is now 1.36, which means the flag would no longer serve any purpose.

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 a pull request may close this issue.

2 participants