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: expose pathname publicly #833

Open
waynevanson opened this issue Apr 19, 2023 · 3 comments
Open

feature: expose pathname publicly #833

waynevanson opened this issue Apr 19, 2023 · 3 comments

Comments

@waynevanson
Copy link

Hi! I enjoy this package, thank you for making it.

I would like to construct a pathname then pass it into the URL.

I see that PathSegmentsMut is available but looks like it's purposefully not exposed.
Was there a reason for that?

Just like we can join paths in the standard PathBuf, I would like to see something similar here for urls.

@valenting
Copy link
Collaborator

I'm not sure I understand.
You can call set_path, or use path_segments_mut to change the path of a URL
https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=41051f540e7ac7828963c10cd8da4c1b

use url;
use url::Url;

fn main() {
    let mut url = Url::parse("http://example.com/path").unwrap();
    // https://docs.rs/url/2.3.1/url/struct.Url.html#method.set_path
    url.set_path("/some/other/path");
    println!("{:?}", url.as_str());
    
    // https://docs.rs/url/2.3.1/url/struct.PathSegmentsMut.html
    url.path_segments_mut().unwrap().pop().push("img");
    println!("{:?}", url.as_str());
}

Could you expand of what else you would need?

@waynevanson
Copy link
Author

@valenting
The API implies that the host must be defined and known ahead of time.

Instead, I would like PathSegmentsMut publicly exposed with pub keyword and exported out the main module.

@lucacasonato
Copy link
Collaborator

@waynevanson I don't understand. Can you create an example of what you'd like to be able to do?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants