Struct uriparse::uri::URIReference[][src]

pub struct URIReference<'uri> { /* fields omitted */ }

A URI reference as defined in [RFC3986, Section 4.1].

Specifically, a URI reference is either a URI or a relative reference (a schemeless URI).

Methods

impl<'uri> URIReference<'uri>
[src]

Returns the authority, if present, of the URI reference.

Examples

use std::convert::TryFrom;

use uriparse::URIReference;

let reference = URIReference::try_from("//example.com/my/path").unwrap();
assert_eq!(reference.authority().unwrap().to_string(), "example.com");

Constructs a default builder for a URI reference.

This provides an alternative means of constructing a URI reference besides parsing and URIReference::from_parts.

Examples

use uriparse::URIReference;

let mut builder = URIReference::builder();
builder.scheme(Some("http")).authority(Some("example.com")).path("/my/path");
let reference = builder.build().unwrap();
assert_eq!(reference.to_string(), "http://example.com/my/path");

Returns whether or not the URI reference can act as a base URI.

A URI can be a base if it is absolute (i.e. it has no fragment component).

Examples

use std::convert::TryFrom;

use uriparse::URIReference;

let reference = URIReference::try_from("http://example.com/my/path").unwrap();
assert!(reference.can_be_a_base());

let reference = URIReference::try_from("ftp://127.0.0.1#fragment").unwrap();
assert!(!reference.can_be_a_base());

Constructs a new URIReference from the individual parts: scheme, authority, path, query, and fragment.

The lifetime used by the resulting value will be the lifetime of the part that is most restricted in scope.

Examples

use std::convert::TryFrom;

use uriparse::{Scheme, URIReference};

let reference = URIReference::from_parts(
    None::<Scheme>,
    Some("example.com"),
    "/my/path",
    Some("query"),
    Some("fragment")
).unwrap();
assert_eq!(reference.to_string(), "//example.com/my/path?query#fragment");

Returns the fragment, if present, of the URI reference.

Examples

use std::convert::TryFrom;

use uriparse::URIReference;

let reference = URIReference::try_from("http://example.com#fragment").unwrap();
assert_eq!(reference.fragment().unwrap(), "fragment");

Returns whether or not the URI reference has an authority component.

Examples

use std::convert::TryFrom;

use uriparse::URIReference;

let reference = URIReference::try_from("http://example.com").unwrap();
assert!(reference.has_authority());

let reference = URIReference::try_from("").unwrap();
assert!(!reference.has_authority());

Returns whether or not the URI reference has a fragment component.

Examples

use std::convert::TryFrom;

use uriparse::URIReference;

let reference = URIReference::try_from("#test").unwrap();
assert!(reference.has_fragment());

let reference = URIReference::try_from("http://example.com").unwrap();
assert!(!reference.has_fragment());

Returns whether or not the URI reference has a password component.

Examples

use std::convert::TryFrom;

use uriparse::URIReference;

let reference = URIReference::try_from("http://user:pass@127.0.0.1").unwrap();
assert!(reference.has_password());

let reference = URIReference::try_from("http://user@127.0.0.1").unwrap();
assert!(!reference.has_password());

Returns whether or not the URI reference has a query component.

Examples

use std::convert::TryFrom;

use uriparse::URIReference;

let reference = URIReference::try_from("/?my=query").unwrap();
assert!(reference.has_query());

let reference = URIReference::try_from("http://example.com/my/path").unwrap();
assert!(!reference.has_query());

Returns whether or not the URI reference has a scheme component.

Examples

use std::convert::TryFrom;

use uriparse::URIReference;

let reference = URIReference::try_from("http://example.com?my=query").unwrap();
assert!(reference.has_scheme());

let reference = URIReference::try_from("/my/path").unwrap();
assert!(!reference.has_scheme());

Returns whether or not the URI reference has a username component.

Examples

use std::convert::TryFrom;

use uriparse::URIReference;

let reference = URIReference::try_from("//username@example.com").unwrap();
assert!(reference.has_username());

let reference = URIReference::try_from("http://example.com").unwrap();
assert!(!reference.has_username());

Returns the host, if present, of the URI reference.

Examples

use std::convert::TryFrom;

use uriparse::URIReference;

let reference = URIReference::try_from("http://username@example.com").unwrap();
assert_eq!(reference.host().unwrap().to_string(), "example.com");

Consumes the URI reference and converts it into a builder with the same values.

Examples

use std::convert::TryFrom;

use uriparse::{Fragment, Query, URIReference};

let reference = URIReference::try_from("//example.com/path?query#fragment").unwrap();
let mut builder = reference.into_builder();
builder.query(None::<Query>).fragment(None::<Fragment>);
let reference = builder.build().unwrap();
assert_eq!(reference.to_string(), "//example.com/path");

Converts the URIReference into an owned copy.

If you construct the URI reference from a source with a non-static lifetime, you may run into lifetime problems due to the way the struct is designed. Calling this function will ensure that the returned value has a static lifetime.

This is different from just cloning. Cloning the URI reference will just copy the references, and thus the lifetime will remain the same.

Consumes the URIReference and returns its parts: scheme, authority, path, query, and fragment.

Examples

use std::convert::TryFrom;

use uriparse::URIReference;

let reference = URIReference::try_from(
    "http://username:password@example.com:80/my/path?my=query#fragment",
).unwrap();
let (scheme, authority, path, query, fragment) = reference.into_parts();

assert_eq!(scheme.unwrap(), "http");
assert_eq!(authority.unwrap().to_string(), "username:password@example.com:80");
assert_eq!(path, "/my/path");
assert_eq!(query.unwrap(), "my=query");
assert_eq!(fragment.unwrap(), "fragment");

Returns whether or not the URI reference is an absolute path reference.

A URI reference is an absolute path reference if it is a relative reference that begins with a single '/'.

Examples

use std::convert::TryFrom;

use uriparse::URIReference;

let reference = URIReference::try_from("/my/path").unwrap();
assert!(reference.is_absolute_path_reference());

Returns whether or not the URI reference is a network path reference.

A URI reference is a network path reference if it is a relative reference that begins with two '/'.

Examples

use std::convert::TryFrom;

use uriparse::URIReference;

let reference = URIReference::try_from("//example.com").unwrap();
assert!(reference.is_network_path_reference());

Returns whether or not the URI reference is a relative path reference.

A URI reference is a relative path reference if it is a relative reference that does not begin with a '/'.

Examples

use std::convert::TryFrom;

use uriparse::URIReference;

let reference = URIReference::try_from("my/path").unwrap();
assert!(reference.is_relative_path_reference());

Returns whether or not the URI reference is a relative reference.

A URI reference is a relative reference if it has no scheme.

Examples

use std::convert::TryFrom;

use uriparse::URIReference;

let reference = URIReference::try_from("/my/path").unwrap();
assert!(reference.is_relative_reference());

Returns whether or not the URI reference is a URI.

A URI reference is a URI if it has a scheme.

Examples

use std::convert::TryFrom;

use uriparse::URIReference;

let reference = URIReference::try_from("http://example.com").unwrap();
assert!(reference.is_uri());

Returns the path of the URI reference.

Examples

use std::convert::TryFrom;

use uriparse::URIReference;

let reference = URIReference::try_from("http://127.0.0.1/my/path").unwrap();
assert_eq!(reference.path(), "/my/path");

Returns the password, if present, of the URI reference.

Usage of a password in URI and URI references is deprecated.

Examples

use std::convert::TryFrom;

use uriparse::URIReference;

let reference = URIReference::try_from("http://user:pass@example.com").unwrap();
assert_eq!(reference.password().unwrap(), "pass");

Returns the port, if present, of the URI reference.

Examples

use std::convert::TryFrom;

use uriparse::URIReference;

let reference = URIReference::try_from("http://example.com:8080/").unwrap();
assert_eq!(reference.port().unwrap(), 8080);

Returns the query, if present, of the URI reference.

Examples

use std::convert::TryFrom;

use uriparse::URIReference;

let reference = URIReference::try_from("http://127.0.0.1?my=query").unwrap();
assert_eq!(reference.query().unwrap(), "my=query");

Returns the scheme, if present, of the URI reference.

Examples

use std::convert::TryFrom;

use uriparse::URIReference;

let reference = URIReference::try_from("http://127.0.0.1/").unwrap();
assert_eq!(reference.scheme().unwrap(), "http");

Returns the username, if present, of the URI reference.

Examples

use std::convert::TryFrom;

use uriparse::URIReference;

let reference = URIReference::try_from("http://username@example.com").unwrap();
assert_eq!(reference.username().unwrap(), "username");

Trait Implementations

impl<'uri> TryFrom<URIReference<'uri>> for RelativeReference<'uri>
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

🔬 This is a nightly-only experimental API. (try_from)

Performs the conversion.

impl<'uri> TryFrom<URIReference<'uri>> for URI<'uri>
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

🔬 This is a nightly-only experimental API. (try_from)

Performs the conversion.

impl<'uri> Clone for URIReference<'uri>
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl<'uri> Debug for URIReference<'uri>
[src]

Formats the value using the given formatter. Read more

impl<'uri> Eq for URIReference<'uri>
[src]

impl<'uri> Hash for URIReference<'uri>
[src]

Feeds this value into the given [Hasher]. Read more

Feeds a slice of this type into the given [Hasher]. Read more

impl<'uri> PartialEq for URIReference<'uri>
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<'uri> Display for URIReference<'uri>
[src]

Formats the value using the given formatter. Read more

impl<'uri> From<RelativeReference<'uri>> for URIReference<'uri>
[src]

Performs the conversion.

impl<'uri> From<URI<'uri>> for URIReference<'uri>
[src]

Performs the conversion.

impl<'uri> From<URIReference<'uri>> for String
[src]

Performs the conversion.

impl<'uri> TryFrom<&'uri [u8]> for URIReference<'uri>
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

🔬 This is a nightly-only experimental API. (try_from)

Performs the conversion.

impl<'uri> TryFrom<&'uri str> for URIReference<'uri>
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

🔬 This is a nightly-only experimental API. (try_from)

Performs the conversion.

Auto Trait Implementations

impl<'uri> Send for URIReference<'uri>

impl<'uri> Sync for URIReference<'uri>