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

More doc examples. #245

Merged
merged 6 commits into from Dec 9, 2016

Add doc examples for `Url::host_str`.

  • Loading branch information
frewsxcv committed Dec 9, 2016
commit fcc3a3174ce6f8d1ed1c53335ab4fc156ca1d382
@@ -623,6 +623,24 @@ impl Url {
/// don’t have a host.
///
/// See also the `host` method.
///
/// # Examples
///
/// ```
/// use url::Url;
///
/// let url = Url::parse("https://127.0.0.1/index.html").unwrap();
/// assert_eq!(url.host_str(), Some("127.0.0.1"));
///
/// let url = Url::parse("ftp://rms@example.com").unwrap();
/// assert_eq!(url.host_str(), Some("example.com"));
///
/// let url = Url::parse("unix:/run/foo.socket").unwrap();
/// assert_eq!(url.host_str(), None);
///
/// let url = Url::parse("data:text/plain,Stuff").unwrap();
/// assert_eq!(url.host_str(), None);
/// ```
pub fn host_str(&self) -> Option<&str> {
if self.has_host() {
Some(self.slice(self.host_start..self.host_end))
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.