Add impl From<Uri> for Location + accessor#104
Add impl From<Uri> for Location + accessor#104fasterthanlime wants to merge 2 commits intohyperium:masterfrom
impl From<Uri> for Location + accessor#104Conversation
As far as I know, all URI characters should be valid Header value characters, so we can have an infallible constructor for Location from an `Uri`. This doesn't cover all uses of the Location header, since it allows URI-references like `/People.html#tim`, but it's an ergonomic win already, as mentioned in hyperium#48
src/common/location.rs
Outdated
| let uri = uri.to_string(); | ||
| // cf. https://www.rfc-editor.org/rfc/rfc3986#section-2 | ||
| Self( | ||
| HeaderValue::from_str(&uri) |
There was a problem hiding this comment.
You can use try_from and it won't need to copy to a new buffer.
src/common/location.rs
Outdated
|
|
||
| impl Location { | ||
| /// Creates a `Location` header from a uri | ||
| pub fn uri(uri: Uri) -> Self { |
There was a problem hiding this comment.
I kinda wonder if we would want this function name as an accessor at some point... Not sure.
A From impl would work too.
Location::uri constructorimpl From<Uri> for Location + accessor
|
I addressed both comments, thanks for the feedback! |
|
Can someone review this? I needed it today and had to use a workaround. |
|
Another gentle and friendly nudge - I've run up against this one too, and I'm trying to avoid a temporary fork! Absolutely understand pressures of time etc. on maintainers, I've been there! If there's something that others could help with, some of us might be able to step up? |
|
@seanmonstar |
As far as I know, all URI characters should be valid Header value
characters, so we can have an infallible constructor for Location
from an
Uri.This doesn't cover all uses of the Location header, since it allows
URI-references like
/People.html#tim, but it's an ergonomic winalready, as mentioned in #48