Struct uriparse::uri::URI [−][src]
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.
Methods
impl<'uri> URI<'uri>
[src]
impl<'uri> URI<'uri>
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]
pub fn builder<'new_uri>() -> URIBuilder<'new_uri>
Constructs a default builder for a URI.
This provides an alternative means of constructing a URI besides parsing and
URI::from_parts
.
Examples
use uriparse::URI; let mut builder = URI::builder(); builder.scheme("http").authority(Some("example.com")).path("/my/path"); let uri = builder.build().unwrap(); assert_eq!(uri.to_string(), "http://example.com/my/path");
pub fn can_be_a_base(&self) -> bool
[src]
pub fn can_be_a_base(&self) -> bool
Returns whether or not 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, SchemeType, AuthorityType, PathType, QueryType, FragmentType, SchemeError, AuthorityError, PathError, QueryError, FragmentError>(
scheme: SchemeType,
authority: Option<AuthorityType>,
path: PathType,
query: Option<QueryType>,
fragment: Option<FragmentType>
) -> Result<URI<'new_uri>, InvalidURI> where
Scheme<'new_uri>: TryFrom<SchemeType, Error = SchemeError>,
Authority<'new_uri>: TryFrom<AuthorityType, Error = AuthorityError>,
Path<'new_uri>: TryFrom<PathType, Error = PathError>,
Query<'new_uri>: TryFrom<QueryType, Error = QueryError>,
Fragment<'new_uri>: TryFrom<FragmentType, Error = FragmentError>,
InvalidURIReference: From<SchemeError> + From<AuthorityError> + From<PathError> + From<QueryError> + From<FragmentError>,
[src]
pub fn from_parts<'new_uri, SchemeType, AuthorityType, PathType, QueryType, FragmentType, SchemeError, AuthorityError, PathError, QueryError, FragmentError>(
scheme: SchemeType,
authority: Option<AuthorityType>,
path: PathType,
query: Option<QueryType>,
fragment: Option<FragmentType>
) -> Result<URI<'new_uri>, InvalidURI> where
Scheme<'new_uri>: TryFrom<SchemeType, Error = SchemeError>,
Authority<'new_uri>: TryFrom<AuthorityType, Error = AuthorityError>,
Path<'new_uri>: TryFrom<PathType, Error = PathError>,
Query<'new_uri>: TryFrom<QueryType, Error = QueryError>,
Fragment<'new_uri>: TryFrom<FragmentType, Error = FragmentError>,
InvalidURIReference: From<SchemeError> + From<AuthorityError> + From<PathError> + From<QueryError> + From<FragmentError>,
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]
pub fn fragment(&self) -> Option<&Fragment<'uri>>
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");
Returns whether or not 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]
pub fn has_fragment(&self) -> bool
Returns whether or not 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]
pub fn has_password(&self) -> bool
Returns whether or not 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_query(&self) -> bool
[src]
pub fn has_query(&self) -> bool
Returns whether or not 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]
pub fn has_username(&self) -> bool
Returns whether or not 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]
pub fn host(&self) -> Option<&Host<'uri>>
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]
pub fn into_base_uri(self) -> URI<'uri>
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]
pub fn into_builder(self) -> URIBuilder<'uri>
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]
pub fn into_owned(self) -> URI<'static>
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]
pub fn into_parts(
self
) -> (Scheme<'uri>, Option<Authority<'uri>>, Path<'uri>, Option<Query<'uri>>, Option<Fragment<'uri>>)
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 path(&self) -> &Path<'uri>
[src]
pub fn path(&self) -> &Path<'uri>
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]
pub fn password(&self) -> Option<&Password<'uri>>
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]
pub fn port(&self) -> Option<u16>
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]
pub fn query(&self) -> Option<&Query<'uri>>
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 scheme(&self) -> &Scheme<'uri>
[src]
pub fn scheme(&self) -> &Scheme<'uri>
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 username(&self) -> Option<&Username>
[src]
pub fn username(&self) -> Option<&Username>
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> Clone for URI<'uri>
fn clone(&self) -> URI<'uri>
[src]
fn clone(&self) -> URI<'uri>
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl<'uri> Debug for URI<'uri>
[src]
impl<'uri> Debug for URI<'uri>
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl<'uri> Eq for URI<'uri>
[src]
impl<'uri> Eq for URI<'uri>
impl<'uri> Hash for URI<'uri>
[src]
impl<'uri> Hash for URI<'uri>
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
fn hash<__H: Hasher>(&self, state: &mut __H)
Feeds this value into the given [Hasher
]. Read more
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl<'uri> PartialEq for URI<'uri>
[src]
impl<'uri> PartialEq for URI<'uri>
fn eq(&self, other: &URI<'uri>) -> bool
[src]
fn eq(&self, other: &URI<'uri>) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &URI<'uri>) -> bool
[src]
fn ne(&self, other: &URI<'uri>) -> bool
This method tests for !=
.
impl<'uri> Display for URI<'uri>
[src]
impl<'uri> Display for URI<'uri>
fn fmt(&self, formatter: &mut Formatter) -> Result
[src]
fn fmt(&self, formatter: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl<'uri> From<URI<'uri>> for String
[src]
impl<'uri> From<URI<'uri>> for String
impl<'uri> TryFrom<&'uri [u8]> for URI<'uri>
[src]
impl<'uri> TryFrom<&'uri [u8]> for URI<'uri>
type Error = InvalidURI
try_from
)The type returned in the event of a conversion error.
fn try_from(value: &'uri [u8]) -> Result<Self, Self::Error>
[src]
fn try_from(value: &'uri [u8]) -> Result<Self, Self::Error>
try_from
)Performs the conversion.
impl<'uri> TryFrom<&'uri str> for URI<'uri>
[src]
impl<'uri> TryFrom<&'uri str> for URI<'uri>
type Error = InvalidURI
try_from
)The type returned in the event of a conversion error.
fn try_from(value: &'uri str) -> Result<Self, Self::Error>
[src]
fn try_from(value: &'uri str) -> Result<Self, Self::Error>
try_from
)Performs the conversion.
impl<'uri> TryFrom<URIReference<'uri>> for URI<'uri>
[src]
impl<'uri> TryFrom<URIReference<'uri>> for URI<'uri>
type Error = InvalidURI
try_from
)The type returned in the event of a conversion error.
fn try_from(value: URIReference<'uri>) -> Result<Self, Self::Error>
[src]
fn try_from(value: URIReference<'uri>) -> Result<Self, Self::Error>
try_from
)Performs the conversion.