Skip to content

liburl: minor api changes #15225

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

Closed
wants to merge 7 commits into from
Closed

liburl: minor api changes #15225

wants to merge 7 commits into from

Conversation

Ryman
Copy link
Contributor

@Ryman Ryman commented Jun 27, 2014

See commits for info, a number of these are 'breaking', although liburl is marked experimental so I'm not sure that matters so much.

First two commits will be impacted if #15138 is adopted, but it's a simple rename.

@huonw
Copy link
Member

huonw commented Jun 28, 2014

The renaming of functions should be accompanied by deprecations, with some guidance about the new version, that is,

#[deprecated="use `Url::parse_str`"]
fn from_str(s: &str) {  Url::parse_str(s) }

/// fragment: Some("quz".to_string()) };
/// // https://username@example.com:8080/foo/bar?baz=qux#quz
/// let raw = "https://username@example.com:8080/foo/bar?baz=qux#quz";
/// let url = Url::parse_str(raw).unwrap();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we not have the .unwrap here? Something like

match Url::parse_str(raw) {
    Ok(u) => println!("Parsed `{}`", u),
    Err(e) => println!("Couldn't parse `{}`: {}", raw, e),
}

(assuming that the error implements Show.)

@Ryman
Copy link
Contributor Author

Ryman commented Jun 28, 2014

@huonw Addressed your feedback

/// let url = encode("https://example.com/Rust (programming language)");
/// println!("{}", url); // https://example.com/Rust%20(programming%20language)
/// ```
pub fn encode<T: BytesContainer>(container: T) -> String {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would personally prefer to halt the proliferation of BytesContainer and friends. It is indeed slightly more ergonomic, but BytesContainer was not intended for this purpose. Could these functions stay as taking &str?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd favor a breaking change to &[u8] if BytesContainer is off the cards. &str can use as_bytes(), Vec<u8> can use as_slice(), etc.

For reference, while actually working on this there was someone on IRC frustrated by having to decode their bytes into utf8 before calling encode once again.

Alternatively, defining a 'local' trait impl'd for &str, String, Vec<u8>, &[u8] might be an option? Although I guess that's similar territory to BytesContainer.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've starting to see more pickup of BytesContainer in #15280 for example, so I think my personal preference may be overruled by ergonomics (this is fine as is)

Ryman added 7 commits July 4, 2014 01:22
url::from_str => url::Url::parse_str

The FromStr trait still works, but its confusing to have a from_str
free function that retuns a Result, while the regular from_str
returns an Option, hence the rename.

[breaking-change]
url::path_from_str => url::Path::parse_str

The FromStr trait still works, but its confusing to have a path_from_str
free function that retuns a Result, while the regular from_str style
functions return an Option, hence the rename to indicate a Result.

[breaking-change]
url.path - Now a Path instead of a String.

To fix old code:
url.path => url.path.path
url.query => url.path.query
url.fragment => url.path.fragment

Not much point having the Path struct if it's not going to be used.

[breaking-change]
Some signatures have changed from String to &str returns.

To fix, call to_string() on the returned value.

[breaking-change]
@Ryman
Copy link
Contributor Author

Ryman commented Jul 4, 2014

@alexcrichton parse_str => parse, vec!() => vec![] in all docstrings, left BytesContainer as is.

bors added a commit that referenced this pull request Jul 5, 2014
See commits for info, a number of these are 'breaking', although liburl is marked experimental so I'm not sure that matters so much.

First two commits will be impacted if #15138 is adopted, but it's a simple rename.
@bors bors closed this Jul 5, 2014
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 this pull request may close these issues.

4 participants