You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Url currently has pop_path_segments and push_path_segment methods, but they have a design problem reported by @sfackler. A path is at minimum / which is considered like a single path segment that happens to be empty (like trailing slashes in general), so push_path_segment("foo") make the path be //foo with two slashes.
Fixing this may involve breaking API changes, so instead I’ll make these methods private (effectively removing them) before publishing 1.0.0, in order to unblock it. I’ll add them back (or something else to provide this functionality) in 1.1.0.
I am trying to append a segment to a path which doesn't end with a trailing / and url.join() cannot handle this scenario. Is there a way to do this with url 1.0.0 or I need to do some ugly string concat to make sure a trailing / is always present and then use url.join()?
In 1.0.0 you have to use string concatenation and url.set_path(p). In 1.1.0 I want to add something like url.push_path_segment(s) (but maybe a different API) which would do the right thing in various situations.
The example by @sfackler doens't appear to work, you'd have to create a String out of url.path() first, which is not great.
src/transport.rs:46:40: 46:43 error: cannot borrow `url` as immutable because it is also borrowed as mutable [E0502]
src/transport.rs:46 url.set_path(&format!("{}/{}", url.path(), path));
^~~
<std macros>:2:26: 2:57 note: in this expansion of format_args!
src/transport.rs:46:23: 46:57 note: in this expansion of format! (defined in <std macros>)
src/transport.rs:46:9: 46:12 note: previous borrow of `url` occurs here; the mutable borrow prevents subsequent moves, borrows, or modification of `url` until the borrow ends
src/transport.rs:46 url.set_path(&format!("{}/{}", url.path(), path));
^~~
Activity
Make pop_path_segment and push_path_segment private for now.
sfackler commentedon Apr 21, 2016
In the meantime, what's the right way to add path segments? Something like
?
sfackler commentedon Apr 21, 2016
I guess it would actually need to check if
url.path() == "/"to avoid the empty path problem.SimonSapin commentedon Apr 22, 2016
Yes, something like that.
mhristache commentedon Apr 24, 2016
I guess the current issue is related so I am posting here. Let me know if I should open a new issue.
I am trying to switch to
url 1.0.0but I cannot find the equivalent of theurl 0.5code below:I am trying to append a segment to a path which doesn't end with a trailing
/andurl.join()cannot handle this scenario. Is there a way to do this withurl 1.0.0or I need to do some ugly string concat to make sure a trailing/is always present and then useurl.join()?Thanks
SimonSapin commentedon Apr 24, 2016
In 1.0.0 you have to use string concatenation and
url.set_path(p). In 1.1.0 I want to add something likeurl.push_path_segment(s)(but maybe a different API) which would do the right thing in various situations.jgillich commentedon Apr 27, 2016
The example by @sfackler doens't appear to work, you'd have to create a
Stringout ofurl.path()first, which is not great.SimonSapin commentedon Apr 27, 2016
Yeah, for now you have to move the
format!(…)expression into a separate variable.The API I have in mind would be something like this:
Add Url::path_segments_mut, fix #188
Auto merge of #194 - servo:path-segments, r=nox
Make pop_path_segment and push_path_segment private for now.