Struct uriparse::uri::RelativeReference [−][src]
pub struct RelativeReference<'uri> { /* fields omitted */ }
A relative reference as defined in [RFC3986, Section 4.1].
Specifically, a relative reference is a URI reference without a scheme.
Methods
impl<'uri> RelativeReference<'uri>
[src]
impl<'uri> RelativeReference<'uri>
Returns the authority, if present, of the relative reference.
Examples
use std::convert::TryFrom; use uriparse::RelativeReference; let reference = RelativeReference::try_from("//example.com/my/path").unwrap(); assert_eq!(reference.authority().unwrap().to_string(), "example.com");
pub fn builder<'new_uri>() -> RelativeReferenceBuilder<'new_uri>
[src]
pub fn builder<'new_uri>() -> RelativeReferenceBuilder<'new_uri>
Constructs a default builder for a relative reference.
This provides an alternative means of constructing a relative reference besides parsing and
RelativeReference::from_parts
.
Examples
use uriparse::RelativeReference; let mut builder = RelativeReference::builder(); builder.path("/my/path").fragment(Some("fragment")); let reference = builder.build().unwrap(); assert_eq!(reference.to_string(), "/my/path#fragment");
pub fn from_parts<'new_uri, AuthorityType, PathType, QueryType, FragmentType, AuthorityError, PathError, QueryError, FragmentError>(
authority: Option<AuthorityType>,
path: PathType,
query: Option<QueryType>,
fragment: Option<FragmentType>
) -> Result<RelativeReference<'new_uri>, InvalidRelativeReference> where
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<AuthorityError> + From<PathError> + From<QueryError> + From<FragmentError>,
[src]
pub fn from_parts<'new_uri, AuthorityType, PathType, QueryType, FragmentType, AuthorityError, PathError, QueryError, FragmentError>(
authority: Option<AuthorityType>,
path: PathType,
query: Option<QueryType>,
fragment: Option<FragmentType>
) -> Result<RelativeReference<'new_uri>, InvalidRelativeReference> where
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<AuthorityError> + From<PathError> + From<QueryError> + From<FragmentError>,
Constructs a new RelativeReference
from the individual parts: 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, RelativeReference}; let reference = RelativeReference::from_parts( Some("example.com"), "/my/path", Some("query"), Some("fragment") ).unwrap(); assert_eq!(reference.to_string(), "//example.com/my/path?query#fragment");
pub fn fragment(&self) -> Option<&Fragment<'uri>>
[src]
pub fn fragment(&self) -> Option<&Fragment<'uri>>
Returns the fragment, if present, of the relative reference.
Examples
use std::convert::TryFrom; use uriparse::RelativeReference; let reference = RelativeReference::try_from("//example.com#fragment").unwrap(); assert_eq!(reference.fragment().unwrap(), "fragment");
Returns whether or not the relative reference has an authority component.
Examples
use std::convert::TryFrom; use uriparse::RelativeReference; let reference = RelativeReference::try_from("//example.com").unwrap(); assert!(reference.has_authority()); let reference = RelativeReference::try_from("").unwrap(); assert!(!reference.has_authority());
pub fn has_fragment(&self) -> bool
[src]
pub fn has_fragment(&self) -> bool
Returns whether or not the relative reference has a fragment component.
Examples
use std::convert::TryFrom; use uriparse::RelativeReference; let reference = RelativeReference::try_from("#test").unwrap(); assert!(reference.has_fragment()); let reference = RelativeReference::try_from("/").unwrap(); assert!(!reference.has_fragment());
pub fn has_password(&self) -> bool
[src]
pub fn has_password(&self) -> bool
Returns whether or not the relative reference has a password component.
Examples
use std::convert::TryFrom; use uriparse::RelativeReference; let reference = RelativeReference::try_from("//user:pass@127.0.0.1").unwrap(); assert!(reference.has_password()); let reference = RelativeReference::try_from("//user@127.0.0.1").unwrap(); assert!(!reference.has_password());
pub fn has_query(&self) -> bool
[src]
pub fn has_query(&self) -> bool
Returns whether or not the relative reference has a query component.
Examples
use std::convert::TryFrom; use uriparse::RelativeReference; let reference = RelativeReference::try_from("/?my=query").unwrap(); assert!(reference.has_query()); let reference = RelativeReference::try_from("/my/path").unwrap(); assert!(!reference.has_query());
pub fn has_username(&self) -> bool
[src]
pub fn has_username(&self) -> bool
Returns whether or not the relative reference has a username component.
Examples
use std::convert::TryFrom; use uriparse::RelativeReference; let reference = RelativeReference::try_from("//username@example.com").unwrap(); assert!(reference.has_username()); let reference = RelativeReference::try_from("").unwrap(); assert!(!reference.has_username());
pub fn host(&self) -> Option<&Host<'uri>>
[src]
pub fn host(&self) -> Option<&Host<'uri>>
Returns the host, if present, of the relative reference.
Examples
use std::convert::TryFrom; use uriparse::RelativeReference; let reference = RelativeReference::try_from("//username@example.com").unwrap(); assert_eq!(reference.host().unwrap().to_string(), "example.com");
pub fn into_builder(self) -> RelativeReferenceBuilder<'uri>
[src]
pub fn into_builder(self) -> RelativeReferenceBuilder<'uri>
Consumes the relative reference and converts it into a builder with the same values.
Examples
use std::convert::TryFrom; use uriparse::{Fragment, Query, RelativeReference}; let reference = RelativeReference::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");
pub fn into_owned(self) -> RelativeReference<'static>
[src]
pub fn into_owned(self) -> RelativeReference<'static>
Converts the RelativeReference
into an owned copy.
If you construct the relative 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 relative reference will just copy the references, and thus the lifetime will remain the same.
pub fn into_parts(
self
) -> (Option<Authority<'uri>>, Path<'uri>, Option<Query<'uri>>, Option<Fragment<'uri>>)
[src]
pub fn into_parts(
self
) -> (Option<Authority<'uri>>, Path<'uri>, Option<Query<'uri>>, Option<Fragment<'uri>>)
Consumes the RelativeReference
and returns its parts: authority, path, query, and
fragment.
Examples
use std::convert::TryFrom; use uriparse::RelativeReference; let reference = RelativeReference::try_from( "/my/path?my=query#fragment", ).unwrap(); let (authority, path, query, fragment) = reference.into_parts(); assert_eq!(authority, None); assert_eq!(path, "/my/path"); assert_eq!(query.unwrap(), "my=query"); assert_eq!(fragment.unwrap(), "fragment");
pub fn is_absolute_path_reference(&self) -> bool
[src]
pub fn is_absolute_path_reference(&self) -> bool
Returns whether or not the relative 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::RelativeReference; let reference = RelativeReference::try_from("/my/path").unwrap(); assert!(reference.is_absolute_path_reference());
pub fn is_network_path_reference(&self) -> bool
[src]
pub fn is_network_path_reference(&self) -> bool
Returns whether or not the relative reference is a network path reference.
A relative reference is a network path reference if it is a relative reference that begins
with two '/'
.
Examples
use std::convert::TryFrom; use uriparse::RelativeReference; let reference = RelativeReference::try_from("//example.com").unwrap(); assert!(reference.is_network_path_reference());
pub fn is_relative_path_reference(&self) -> bool
[src]
pub fn is_relative_path_reference(&self) -> bool
Returns whether or not the relative reference is a relative path reference.
A relative 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::RelativeReference; let reference = RelativeReference::try_from("my/path").unwrap(); assert!(reference.is_relative_path_reference());
pub fn path(&self) -> &Path<'uri>
[src]
pub fn path(&self) -> &Path<'uri>
Returns the path of the relative reference.
Examples
use std::convert::TryFrom; use uriparse::RelativeReference; let reference = RelativeReference::try_from("/my/path").unwrap(); assert_eq!(reference.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 relative reference.
Usage of a password in URI and URI references is deprecated.
Examples
use std::convert::TryFrom; use uriparse::RelativeReference; let reference = RelativeReference::try_from("//user:pass@example.com").unwrap(); assert_eq!(reference.password().unwrap(), "pass");
pub fn port(&self) -> Option<u16>
[src]
pub fn port(&self) -> Option<u16>
Returns the port, if present, of the relative reference.
Examples
use std::convert::TryFrom; use uriparse::RelativeReference; let reference = RelativeReference::try_from("//example.com:8080/").unwrap(); assert_eq!(reference.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 relative reference.
Examples
use std::convert::TryFrom; use uriparse::RelativeReference; let reference = RelativeReference::try_from("?my=query").unwrap(); assert_eq!(reference.query().unwrap(), "my=query");
pub fn username(&self) -> Option<&Username>
[src]
pub fn username(&self) -> Option<&Username>
Returns the username, if present, of the relative reference.
Examples
use std::convert::TryFrom; use uriparse::RelativeReference; let reference = RelativeReference::try_from("//username@example.com").unwrap(); assert_eq!(reference.username().unwrap(), "username");
Trait Implementations
impl<'uri> Clone for RelativeReference<'uri>
[src]
impl<'uri> Clone for RelativeReference<'uri>
fn clone(&self) -> RelativeReference<'uri>
[src]
fn clone(&self) -> RelativeReference<'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 RelativeReference<'uri>
[src]
impl<'uri> Debug for RelativeReference<'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 RelativeReference<'uri>
[src]
impl<'uri> Eq for RelativeReference<'uri>
impl<'uri> Hash for RelativeReference<'uri>
[src]
impl<'uri> Hash for RelativeReference<'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 RelativeReference<'uri>
[src]
impl<'uri> PartialEq for RelativeReference<'uri>
fn eq(&self, other: &RelativeReference<'uri>) -> bool
[src]
fn eq(&self, other: &RelativeReference<'uri>) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &RelativeReference<'uri>) -> bool
[src]
fn ne(&self, other: &RelativeReference<'uri>) -> bool
This method tests for !=
.
impl<'uri> Display for RelativeReference<'uri>
[src]
impl<'uri> Display for RelativeReference<'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<RelativeReference<'uri>> for String
[src]
impl<'uri> From<RelativeReference<'uri>> for String
fn from(value: RelativeReference<'uri>) -> String
[src]
fn from(value: RelativeReference<'uri>) -> String
Performs the conversion.
impl<'uri> TryFrom<&'uri [u8]> for RelativeReference<'uri>
[src]
impl<'uri> TryFrom<&'uri [u8]> for RelativeReference<'uri>
type Error = InvalidRelativeReference
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 RelativeReference<'uri>
[src]
impl<'uri> TryFrom<&'uri str> for RelativeReference<'uri>
type Error = InvalidRelativeReference
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 RelativeReference<'uri>
[src]
impl<'uri> TryFrom<URIReference<'uri>> for RelativeReference<'uri>
type Error = InvalidRelativeReference
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.
Auto Trait Implementations
impl<'uri> Send for RelativeReference<'uri>
impl<'uri> Send for RelativeReference<'uri>
impl<'uri> Sync for RelativeReference<'uri>
impl<'uri> Sync for RelativeReference<'uri>