Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upAdded a method to serialize a Url to a path with a query string #38
Conversation
…use by HTTP clients.
|
Also, this is my first bit of public/production Rust code, so feel free to suggest changes. I'm still learning. |
| @@ -35,6 +35,26 @@ impl<'a, T: Str + Show> Show for PathFormatter<'a, T> { | |||
| } | |||
| } | |||
|
|
|||
| pub struct PathWithQueryFormatter<'a, T:'a> { | |||
| pub path: &'a [T], | |||
| pub query: &'a Option<String>, | |||
This comment has been minimized.
This comment has been minimized.
|
@Manishearth good suggestion. I updated the PathWithQueryFormatter to take a slice instead of a String, following the same conventions as the password field in UserInfoFormatter. But, I kept the named lifetime as 'a instead of 'b, and realized I don't know enough about Rust named lifetimes to understand how to make it work with 'b instead of 'a. |
should work? I'm not too clear on this either, but if the two lifetimes are the same we may get conflicting lifetime issues while using it (eg if we pass it a static string slice and a non-static array slice) |
|
Aside from the lifetime thing (and perhaps the indentation for I'll wait for @SimonSapin to sign off on this though. |
|
OK, I just tried your change with separate lifetimes and it worked fine, as long as I also change:
Happy to push it, but before I do, I wonder why UserInfoFormatter used the same lifetime for both the username and password fields instead of splitting into 'a and 'b. Also, I'm using emacs rust-mode for indentation, and that's what came out for |
|
Huh, you're right. I tested it with using strings of different lifetimes -- it seems to upcast to the smaller lifetime. |
|
Hmm, alright then. Thanks for testing this! Looking forward to hearing from @SimonSapin. |
|
Is this PR still relevant? Should I create a new PR with updated code for this function? |
|
With #176 this will be |
gtolle commentedOct 12, 2014
Intended for use by HTTP clients. The Hyper client currently calls serialize_path() when constructing its GET requests, but this discards the query string. I'm suggesting this new rust-url method so that Hyper can use it.