[][src]Struct uriparse::uri::URI

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

A Uniform Resource Identifier (URI) as defined in RFC3986.

A URI is a URI reference, one with a scheme.

Implementations

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

pub fn as_uri_reference(&self) -> &URIReference<'uri>[src]

pub fn authority(&self) -> Option<&Authority<'uri>>[src]

Returns the authority, if present, of the URI.

Examples

use std::convert::TryFrom;

use uriparse::URI;

let uri = URI::try_from("http://example.com:80/my/path").unwrap();
assert_eq!(uri.authority().unwrap().to_string(), "example.com:80");

pub fn builder<'new_uri>() -> URIBuilder<'new_uri>[src]

Constructs a default builder for a URI.

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

Examples

use std::convert::TryFrom;

use uriparse::{Authority, Path, Scheme, URI};

let uri = URI::builder()
    .with_scheme(Scheme::HTTP)
    .with_authority(Some(Authority::try_from("example.com").unwrap()))
    .with_path(Path::try_from("/my/path").unwrap())
    .build()
    .unwrap();
assert_eq!(uri.to_string(), "http://example.com/my/path");

pub fn can_be_a_base(&self) -> bool[src]

Returns whether the URI 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::URI;

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

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

pub fn from_parts<'new_uri, TScheme, TAuthority, TPath, TQuery, TFragment, TSchemeError, TAuthorityError, TPathError, TQueryError, TFragmentError>(
    scheme: TScheme,
    authority: Option<TAuthority>,
    path: TPath,
    query: Option<TQuery>,
    fragment: Option<TFragment>
) -> Result<URI<'new_uri>, URIError> where
    Scheme<'new_uri>: TryFrom<TScheme, Error = TSchemeError>,
    Authority<'new_uri>: TryFrom<TAuthority, Error = TAuthorityError>,
    Path<'new_uri>: TryFrom<TPath, Error = TPathError>,
    Query<'new_uri>: TryFrom<TQuery, Error = TQueryError>,
    Fragment<'new_uri>: TryFrom<TFragment, Error = TFragmentError>,
    URIReferenceError: From<TSchemeError> + From<TAuthorityError> + From<TPathError> + From<TQueryError> + From<TFragmentError>, 
[src]

Constructs a new URI 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::{Fragment, URI};

let uri = URI::from_parts(
    "http",
    Some("example.com"),
    "",
    Some("query"),
    None::<Fragment>
).unwrap();
assert_eq!(uri.to_string(), "http://example.com/?query");

pub fn fragment(&self) -> Option<&Fragment<'uri>>[src]

Returns the fragment, if present, of the URI.

Examples

use std::convert::TryFrom;

use uriparse::URI;

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

pub fn has_authority(&self) -> bool[src]

Returns whether the URI has an authority component.

Examples

use std::convert::TryFrom;

use uriparse::URI;

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

let uri = URI::try_from("urn:test").unwrap();
assert!(!uri.has_authority());

pub fn has_fragment(&self) -> bool[src]

Returns whether the URI has a fragment component.

Examples

use std::convert::TryFrom;

use uriparse::URI;

let uri = URI::try_from("http://example.com#test").unwrap();
assert!(uri.has_fragment());

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

pub fn has_password(&self) -> bool[src]

Returns whether the URI has a password component.

Examples

use std::convert::TryFrom;

use uriparse::URI;

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

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

pub fn has_port(&self) -> bool[src]

Returns whether the URI has a port.

Examples

use std::convert::TryFrom;

use uriparse::URI;

let uri = URI::try_from("http://127.0.0.1:8080").unwrap();
assert!(uri.has_port());

let uri = URI::try_from("http://127.0.0.1").unwrap();
assert!(!uri.has_port());

pub fn has_query(&self) -> bool[src]

Returns whether the URI has a query component.

Examples

use std::convert::TryFrom;

use uriparse::URI;

let uri = URI::try_from("http://example.com/my/path?my=query").unwrap();
assert!(uri.has_query());

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

pub fn has_username(&self) -> bool[src]

Returns whether the URI has a username component.

Examples

use std::convert::TryFrom;

use uriparse::URI;

let uri = URI::try_from("http://username@example.com").unwrap();
assert!(uri.has_username());

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

pub fn host(&self) -> Option<&Host<'uri>>[src]

Returns the host, if present, of the URI.

Examples

use std::convert::TryFrom;

use uriparse::URI;

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

pub fn into_base_uri(self) -> URI<'uri>[src]

Converts the URI into a base URI (i.e. the fragment component is removed).

Examples

use std::convert::TryFrom;

use uriparse::URI;

let uri = URI::try_from("http://example.com#fragment").unwrap();
assert_eq!(uri.to_string(), "http://example.com/#fragment");
let uri = uri.into_base_uri();
assert_eq!(uri.to_string(), "http://example.com/");

pub fn into_builder(self) -> URIBuilder<'uri>[src]

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

Examples

use std::convert::TryFrom;

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

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

pub fn into_owned(self) -> URI<'static>[src]

Converts the URI into an owned copy.

If you construct the URI 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 will just copy the references, and thus the lifetime will remain the same.

pub fn into_parts(
    self
) -> (Scheme<'uri>, Option<Authority<'uri>>, Path<'uri>, Option<Query<'uri>>, Option<Fragment<'uri>>)
[src]

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

Examples

use std::convert::TryFrom;

use uriparse::URI;

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

assert_eq!(scheme, "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");

pub fn is_normalized(&self) -> bool[src]

Returns whether the URI is normalized.

A normalized URI will have all of its components normalized.

Examples

use std::convert::TryFrom;

use uriparse::URI;

let uri = URI::try_from("http://example.com/?a=b").unwrap();
assert!(uri.is_normalized());

let mut uri = URI::try_from("http://EXAMPLE.com/?a=b").unwrap();
assert!(!uri.is_normalized());
uri.normalize();
assert!(uri.is_normalized());

pub fn map_authority<TMapper>(
    &mut self,
    mapper: TMapper
) -> Option<&Authority<'uri>> where
    TMapper: FnOnce(Option<Authority<'uri>>) -> Option<Authority<'uri>>, 
[src]

Maps the authority using the given map function.

This function will panic if, as a result of the authority change, the URI reference becomes invalid.

Examples

use std::convert::TryFrom;

use uriparse::{Authority, URI};

let mut uri = URI::try_from("http://example.com").unwrap();
uri.map_authority(|_| Some(Authority::try_from("127.0.0.1").unwrap()));
assert_eq!(uri.to_string(), "http://127.0.0.1/");

pub fn map_fragment<TMapper>(
    &mut self,
    mapper: TMapper
) -> Option<&Fragment<'uri>> where
    TMapper: FnOnce(Option<Fragment<'uri>>) -> Option<Fragment<'uri>>, 
[src]

Maps the fragment using the given map function.

Examples

use std::convert::TryFrom;

use uriparse::{Fragment, URI};

let mut uri = URI::try_from("http://example.com").unwrap();
uri.map_fragment(|_| Some(Fragment::try_from("fragment").unwrap()));
assert_eq!(uri.to_string(), "http://example.com/#fragment");

pub fn map_path<TMapper>(&mut self, mapper: TMapper) -> &Path<'uri> where
    TMapper: FnOnce(Path<'uri>) -> Path<'uri>, 
[src]

Maps the path using the given map function.

This function will panic if, as a result of the path change, the URI becomes invalid.

Examples

use std::convert::TryFrom;

use uriparse::URI;

let mut uri = URI::try_from("http://example.com").unwrap();
uri.map_path(|mut path| {
    path.push("test").unwrap();
    path.push("path").unwrap();
    path
});
assert_eq!(uri.to_string(), "http://example.com/test/path");

pub fn map_query<TMapper>(&mut self, mapper: TMapper) -> Option<&Query<'uri>> where
    TMapper: FnOnce(Option<Query<'uri>>) -> Option<Query<'uri>>, 
[src]

Maps the query using the given map function.

Examples

use std::convert::TryFrom;

use uriparse::{Query, URI};

let mut uri = URI::try_from("http://example.com").unwrap();
uri.map_query(|_| Some(Query::try_from("query").unwrap()));
assert_eq!(uri.to_string(), "http://example.com/?query");

pub fn map_scheme<TMapper>(&mut self, mapper: TMapper) -> Option<&Scheme<'uri>> where
    TMapper: FnOnce(Scheme<'uri>) -> Scheme<'uri>, 
[src]

Maps the scheme using the given map function.

Examples

use std::convert::TryFrom;

use uriparse::{Scheme, URI};

let mut uri = URI::try_from("http://example.com").unwrap();
uri.map_scheme(|_| Scheme::try_from("https").unwrap());
assert_eq!(uri.to_string(), "https://example.com/");

pub fn normalize(&mut self)[src]

Normalizes the URI.

A normalized URI will have all of its components normalized.

Examples

use std::convert::TryFrom;

use uriparse::URI;

let mut uri = URI::try_from("http://example.com/?a=b").unwrap();
uri.normalize();
assert_eq!(uri.to_string(), "http://example.com/?a=b");

let mut uri = URI::try_from("http://EXAMPLE.com/?a=b").unwrap();
assert_eq!(uri.to_string(), "http://EXAMPLE.com/?a=b");
uri.normalize();
assert_eq!(uri.to_string(), "http://example.com/?a=b");

pub fn path(&self) -> &Path<'uri>[src]

Returns the path of the URI.

Examples

use std::convert::TryFrom;

use uriparse::URI;

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

pub fn password(&self) -> Option<&Password<'uri>>[src]

Returns the password, if present, of the URI.

Usage of a password in URIs is deprecated.

Examples

use std::convert::TryFrom;

use uriparse::URI;

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

pub fn port(&self) -> Option<u16>[src]

Returns the port, if present, of the URI.

Examples

use std::convert::TryFrom;

use uriparse::URI;

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

pub fn query(&self) -> Option<&Query<'uri>>[src]

Returns the query, if present, of the URI.

Examples

use std::convert::TryFrom;

use uriparse::URI;

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

pub fn resolve(&self, reference: &'uri URIReference<'uri>) -> URI<'uri>[src]

Creates a new URI which is created by resolving the given reference against this URI.

The algorithm used for resolving the reference is described in [RFC3986, Section 5.2.2].

pub fn scheme(&self) -> &Scheme<'uri>[src]

Returns the scheme of the URI.

Examples

use std::convert::TryFrom;

use uriparse::URI;

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

pub fn set_authority<TAuthority, TAuthorityError>(
    &mut self,
    authority: Option<TAuthority>
) -> Result<Option<&Authority<'uri>>, URIError> where
    Authority<'uri>: TryFrom<TAuthority, Error = TAuthorityError>,
    URIReferenceError: From<TAuthorityError>, 
[src]

Sets the authority of the URI.

An error will be returned if the conversion to an Authority fails.

The existing path will be set to absolute (i.e. starts with a '/').

Examples

use std::convert::TryFrom;

use uriparse::URI;

let mut uri = URI::try_from("http://example.com").unwrap();
uri.set_authority(Some("user@example.com:80"));
assert_eq!(uri.to_string(), "http://user@example.com:80/");

pub fn set_fragment<TFragment, TFragmentError>(
    &mut self,
    fragment: Option<TFragment>
) -> Result<Option<&Fragment<'uri>>, URIError> where
    Fragment<'uri>: TryFrom<TFragment, Error = TFragmentError>,
    URIReferenceError: From<TFragmentError>, 
[src]

Sets the fragment of the URI.

An error will be returned if the conversion to a Fragment fails.

Examples

use std::convert::TryFrom;

use uriparse::URI;

let mut uri = URI::try_from("http://example.com").unwrap();
uri.set_fragment(Some("fragment"));
assert_eq!(uri.to_string(), "http://example.com/#fragment");

pub fn set_path<TPath, TPathError>(
    &mut self,
    path: TPath
) -> Result<&Path<'uri>, URIError> where
    Path<'uri>: TryFrom<TPath, Error = TPathError>,
    URIReferenceError: From<TPathError>, 
[src]

Sets the path of the URI.

An error will be returned in one of two cases:

  • The conversion to Path failed.
  • The path was set to a value that resulted in an invalid URI.

Regardless of whether the given path was set as absolute or relative, if the URI reference currently has an authority, the path will be forced to be absolute.

Examples

use std::convert::TryFrom;

use uriparse::URI;

let mut uri = URI::try_from("http://example.com").unwrap();
uri.set_path("my/path");
assert_eq!(uri.to_string(), "http://example.com/my/path");

pub fn set_query<TQuery, TQueryError>(
    &mut self,
    query: Option<TQuery>
) -> Result<Option<&Query<'uri>>, URIError> where
    Query<'uri>: TryFrom<TQuery, Error = TQueryError>,
    URIReferenceError: From<TQueryError>, 
[src]

Sets the query of the URI.

An error will be returned if the conversion to a Query fails.

Examples

use std::convert::TryFrom;

use uriparse::URI;

let mut uri = URI::try_from("http://example.com").unwrap();
uri.set_query(Some("myquery"));
assert_eq!(uri.to_string(), "http://example.com/?myquery");

pub fn set_scheme<TScheme, TSchemeError>(
    &mut self,
    scheme: TScheme
) -> Result<&Scheme<'uri>, URIError> where
    Scheme<'uri>: TryFrom<TScheme, Error = TSchemeError>,
    URIReferenceError: From<TSchemeError>, 
[src]

Sets the scheme of the URI.

An error will be returned if the conversion to a Scheme fails.

Examples

use std::convert::TryFrom;

use uriparse::URI;

let mut uri = URI::try_from("http://example.com").unwrap();
uri.set_scheme("https");
assert_eq!(uri.to_string(), "https://example.com/");

pub fn username(&self) -> Option<&Username<'uri>>[src]

Returns the username, if present, of the URI.

Examples

use std::convert::TryFrom;

use uriparse::URI;

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

Trait Implementations

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

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

impl<'_> Display for URI<'_>[src]

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

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

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

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

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

impl<'uri> StructuralEq for URI<'uri>[src]

impl<'uri> StructuralPartialEq for URI<'uri>[src]

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

type Error = URIError

The type returned in the event of a conversion error.

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

type Error = URIError

The type returned in the event of a conversion error.

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

type Error = URIError

The type returned in the event of a conversion error.

Auto Trait Implementations

impl<'uri> RefUnwindSafe for URI<'uri>

impl<'uri> Send for URI<'uri>

impl<'uri> Sync for URI<'uri>

impl<'uri> Unpin for URI<'uri>

impl<'uri> UnwindSafe for URI<'uri>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.