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

Add a few doc examples. #228

Merged
merged 3 commits into from Nov 1, 2016
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -552,6 +552,18 @@ impl Url {
}

/// If this URL has a host and it is a domain name (not an IP address), return it.
///
/// # Examples
///
/// ```
/// use url::Url;
///
/// let url = Url::parse("https://127.0.0.1/").unwrap();
/// assert_eq!(url.domain(), None);
///
/// let url = Url::parse("https://example.com/").unwrap();
/// assert_eq!(url.domain(), Some("example.com"));
/// ```
pub fn domain(&self) -> Option<&str> {
match self.host {
HostInternal::Domain => Some(self.slice(self.host_start..self.host_end)),
@@ -560,6 +572,18 @@ impl Url {
}

/// Return the port number for this URL, if any.
///
/// # Examples
///
/// ```
/// use url::Url;
///
/// let url = Url::parse("https://example.com").unwrap();
/// assert_eq!(url.port(), None);
///
/// let url = Url::parse("ssh://example.com:22").unwrap();
/// assert_eq!(url.port(), Some(22));
/// ```
#[inline]
pub fn port(&self) -> Option<u16> {
self.port
@@ -572,6 +596,21 @@ impl Url {
///
/// For URLs in these schemes, this method always returns `Some(_)`.
/// For other schemes, it is the same as `Url::port()`.
///
/// # Examples
///
/// ```
/// use url::Url;
///
/// let url = Url::parse("foo://example.com").unwrap();
/// assert_eq!(url.port_or_known_default(), None);
///
/// let url = Url::parse("foo://example.com:1456").unwrap();
/// assert_eq!(url.port_or_known_default(), Some(1456));
///
/// let url = Url::parse("https://example.com").unwrap();
/// assert_eq!(url.port_or_known_default(), Some(443));
/// ```
#[inline]
pub fn port_or_known_default(&self) -> Option<u16> {
self.port.or_else(|| parser::default_port(self.scheme()))
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.