[−][src]Struct uriparse::uri::URIBuilder
A builder type for [URI]
.
You must use the URI::scheme
and URI::path
functions before building as URIs always
have a scheme and path. Everything else is optional.
Implementations
impl<'uri> URIBuilder<'uri>
[src]
pub fn authority(&mut self, authority: Option<Authority<'uri>>) -> &mut Self
[src]
Sets the authority part of the URI.
It is optional to specify a authority.
Examples
use std::convert::TryFrom; use uriparse::{Authority, Path, Scheme, URIBuilder}; let mut builder = URIBuilder::new(); builder .scheme(Scheme::HTTP) .authority(Some(Authority::try_from("example.com").unwrap())) .path(Path::try_from("/my/path").unwrap()); let reference = builder.build().unwrap(); assert_eq!(reference.to_string(), "http://example.com/my/path");
pub fn build(self) -> Result<URI<'uri>, URIError>
[src]
Consumes the builder and tries to build a URI
.
This function will error in one of three situations:
- A scheme and path were not specified in the builder.
- While all individual components were valid, their combination as a URI was invalid.
Examples
First error type (scheme and/or path were not specified):
use std::convert::TryFrom; use uriparse::{Authority, Path, URIBuilder}; let result = URIBuilder::new() .with_authority(Some(Authority::try_from("example.com").unwrap())) .with_path(Path::try_from("/my/path").unwrap()) .build(); assert!(result.is_err());
Second error type (URI with no authority cannot have path starting with "//"
):
use std::convert::TryFrom; use uriparse::{Scheme, Path, URIBuilder}; let result = URIBuilder::new() .with_scheme(Scheme::URN) .with_path(Path::try_from("//path").unwrap()) .build(); assert!(result.is_err());
pub fn fragment(&mut self, fragment: Option<Fragment<'uri>>) -> &mut Self
[src]
Sets the fragment part of the URI.
It is optional to specify a fragment.
Examples
use std::convert::TryFrom; use uriparse::{Fragment, Path, Scheme, URIBuilder}; let mut builder = URIBuilder::new(); builder .scheme(Scheme::URN) .path(Path::try_from("path").unwrap()) .fragment(Some(Fragment::try_from("fragment").unwrap())); let uri = builder.build().unwrap(); assert_eq!(uri.to_string(), "urn:path#fragment");
pub fn new() -> Self
[src]
Constructs a new builder with nothing set.
pub fn path(&mut self, path: Path<'uri>) -> &mut Self
[src]
Sets the path part of the URI.
It is required to specify a path. Not doing so will result in an error during the
URIBuilder::build
function.
Examples
use std::convert::TryFrom; use uriparse::{Path, Scheme, URIBuilder}; let mut builder = URIBuilder::new(); builder .scheme(Scheme::URN) .path(Path::try_from("path").unwrap()); let uri = builder.build().unwrap(); assert_eq!(uri.to_string(), "urn:path");
pub fn query(&mut self, query: Option<Query<'uri>>) -> &mut Self
[src]
Sets the query part of the URI reference.
It is optional to specify a query.
Examples
use std::convert::TryFrom; use uriparse::{Path, Query, Scheme, URIBuilder}; let mut builder = URIBuilder::new(); builder .scheme(Scheme::URN) .path(Path::try_from("path").unwrap()) .query(Some(Query::try_from("query").unwrap())); let uri = builder.build().unwrap(); assert_eq!(uri.to_string(), "urn:path?query");
pub fn scheme(&mut self, scheme: Scheme<'uri>) -> &mut Self
[src]
Sets the scheme part of the URI reference.
It is required to specify a scheme. Not doing so will result in an error during the
URIBuilder::build
function.
Examples
use std::convert::TryFrom; use uriparse::{Authority, Path, Scheme, URIBuilder}; let mut builder = URIBuilder::new(); builder .scheme(Scheme::HTTP) .authority(Some(Authority::try_from("example.com").unwrap())) .path(Path::try_from("/my/path").unwrap()); let uri = builder.build().unwrap(); assert_eq!(uri.to_string(), "http://example.com/my/path");
pub fn try_authority<TAuthority, TAuthorityError>(
&mut self,
authority: Option<TAuthority>
) -> Result<&mut Self, AuthorityError> where
Authority<'uri>: TryFrom<TAuthority, Error = TAuthorityError>,
AuthorityError: From<TAuthorityError>,
[src]
&mut self,
authority: Option<TAuthority>
) -> Result<&mut Self, AuthorityError> where
Authority<'uri>: TryFrom<TAuthority, Error = TAuthorityError>,
AuthorityError: From<TAuthorityError>,
Sets the authority part of the URI.1
If the given authority is not a valid authority (i.e. the conversion fails), an error is
stored internally and checked during the URIBuilder::build
function. The error state
will be rewritten for any following calls to this function.
It is optional to specify an authority.
Examples
use uriparse::URIBuilder; let mut builder = URIBuilder::new(); builder .try_scheme("http") .unwrap() .try_authority(Some("example.com")) .unwrap() .try_path("/my/path") .unwrap(); let uri = builder.build().unwrap(); assert_eq!(uri.to_string(), "http://example.com/my/path");
pub fn try_fragment<TFragment, TFragmentError>(
&mut self,
fragment: Option<TFragment>
) -> Result<&mut Self, FragmentError> where
Fragment<'uri>: TryFrom<TFragment, Error = TFragmentError>,
FragmentError: From<TFragmentError>,
[src]
&mut self,
fragment: Option<TFragment>
) -> Result<&mut Self, FragmentError> where
Fragment<'uri>: TryFrom<TFragment, Error = TFragmentError>,
FragmentError: From<TFragmentError>,
Sets the fragment part of the URI.
If the given fragment is not a valid fragment (i.e. the conversion fails), an error is
stored internally and checked during the URIBuilder::build
function. The error state
will be rewritten for any following calls to this function.
It is optional to specify a fragment.
Examples
use uriparse::URIBuilder; let mut builder = URIBuilder::new(); builder .try_scheme("urn") .unwrap() .try_path("path") .unwrap() .try_fragment(Some("fragment")) .unwrap(); let uri = builder.build().unwrap(); assert_eq!(uri.to_string(), "urn:path#fragment");
pub fn try_path<TPath, TPathError>(
&mut self,
path: TPath
) -> Result<&mut Self, PathError> where
Path<'uri>: TryFrom<TPath, Error = TPathError>,
PathError: From<TPathError>,
[src]
&mut self,
path: TPath
) -> Result<&mut Self, PathError> where
Path<'uri>: TryFrom<TPath, Error = TPathError>,
PathError: From<TPathError>,
Sets the path part of the URI.
If the given path is not a valid path (i.e. the conversion fails), an error is stored
internally and checked during the URIBuilder::build
function. The error state will be
rewritten for any following calls to this function.
It is required to specify a path.
Examples
use uriparse::URIBuilder; let mut builder = URIBuilder::new(); builder .try_scheme("urn") .unwrap() .try_path("path") .unwrap(); let uri = builder.build().unwrap(); assert_eq!(uri.to_string(), "urn:path");
pub fn try_query<TQuery, TQueryError>(
&mut self,
query: Option<TQuery>
) -> Result<&mut Self, QueryError> where
Query<'uri>: TryFrom<TQuery, Error = TQueryError>,
QueryError: From<TQueryError>,
[src]
&mut self,
query: Option<TQuery>
) -> Result<&mut Self, QueryError> where
Query<'uri>: TryFrom<TQuery, Error = TQueryError>,
QueryError: From<TQueryError>,
Sets the query part of the URI.
If the given query is not a valid query (i.e. the conversion fails), an error is stored
internally and checked during the URIBuilder::build
function. The error state will be
rewritten for any following calls to this function.
It is optional to specify a query.
Examples
use uriparse::URIBuilder; let mut builder = URIBuilder::new(); builder .try_scheme("urn") .unwrap() .try_path("path") .unwrap() .try_query(Some("query")) .unwrap(); let uri = builder.build().unwrap(); assert_eq!(uri.to_string(), "urn:path?query");
pub fn try_scheme<TScheme, TSchemeError>(
&mut self,
scheme: TScheme
) -> Result<&mut Self, SchemeError> where
Scheme<'uri>: TryFrom<TScheme, Error = TSchemeError>,
SchemeError: From<TSchemeError>,
[src]
&mut self,
scheme: TScheme
) -> Result<&mut Self, SchemeError> where
Scheme<'uri>: TryFrom<TScheme, Error = TSchemeError>,
SchemeError: From<TSchemeError>,
Sets the scheme part of the URI.
If the given scheme is not a valid scheme (i.e. the conversion fails), an error is stored
internally and checked during the URIBuilder::build
function. The error state will be
rewritten for any following calls to this function.
It is required to specify a scheme. Not doing so will result in an error during the
URIBuilder::build
function.
Examples
use std::convert::TryFrom; use uriparse::{Path, Scheme, URIBuilder}; let mut builder = URIBuilder::new(); builder .try_scheme("urn") .unwrap() .try_path("path") .unwrap(); let uri = builder.build().unwrap(); assert_eq!(uri.to_string(), "urn:path");
pub fn with_authority(self, authority: Option<Authority<'uri>>) -> Self
[src]
Consumes the builder and sets the authority part of the URI.
It is optional to specify an authority.
Examples
use std::convert::TryFrom; use uriparse::{Authority, Path, Scheme, URIBuilder}; let uri = URIBuilder::new() .with_scheme(Scheme::HTTP) .with_authority(Some(Authority::try_from("example.com").unwrap())) .with_path(Path::try_from("/").unwrap()) .build() .unwrap(); assert_eq!(uri.to_string(), "http://example.com/")
pub fn with_fragment(self, fragment: Option<Fragment<'uri>>) -> Self
[src]
Consumes the builder and sets the fragment part of the URI.
It is optional to specify a fragment.
Examples
use std::convert::TryFrom; use uriparse::{Fragment, Path, Scheme, URIBuilder}; let uri = URIBuilder::new() .with_scheme(Scheme::URN) .with_path(Path::try_from("").unwrap()) .with_fragment(Some(Fragment::try_from("fragment").unwrap())) .build() .unwrap(); assert_eq!(uri.to_string(), "urn:#fragment")
pub fn with_path(self, path: Path<'uri>) -> Self
[src]
Consumes the builder and sets the path part of the URI.
It is required to specify a path. Not doing so will result in an error during the
URIBuilder::build
function.
Examples
use std::convert::TryFrom; use uriparse::{Authority, Path, Scheme, URIBuilder}; let reference = URIBuilder::new() .with_scheme(Scheme::HTTP) .with_authority(Some(Authority::try_from("example.com").unwrap())) .with_path(Path::try_from("/").unwrap()) .build() .unwrap(); assert_eq!(reference.to_string(), "http://example.com/")
pub fn with_query(self, query: Option<Query<'uri>>) -> Self
[src]
Consumes the builder and sets the query part of the URI.
It is optional to specify a query.
Examples
use std::convert::TryFrom; use uriparse::{Path, Query, Scheme, URIBuilder}; let uri = URIBuilder::new() .with_scheme(Scheme::URN) .with_path(Path::try_from("").unwrap()) .with_query(Some(Query::try_from("query").unwrap())) .build() .unwrap(); assert_eq!(uri.to_string(), "urn:?query")
pub fn with_scheme(self, scheme: Scheme<'uri>) -> Self
[src]
Consumes the builder and sets the scheme part of the URI.
It is required to specify a scheme. Not doing so will result in an error during the
URIBuilder::build
function.
Examples
use std::convert::TryFrom; use uriparse::{Authority, Path, Scheme, URIBuilder}; let reference = URIBuilder::new() .with_scheme(Scheme::HTTP) .with_authority(Some(Authority::try_from("example.com").unwrap())) .with_path(Path::try_from("/").unwrap()) .build() .unwrap(); assert_eq!(reference.to_string(), "http://example.com/")
Trait Implementations
impl<'uri> Clone for URIBuilder<'uri>
[src]
fn clone(&self) -> URIBuilder<'uri>
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<'uri> Debug for URIBuilder<'uri>
[src]
impl<'uri> Default for URIBuilder<'uri>
[src]
fn default() -> URIBuilder<'uri>
[src]
impl<'uri> Eq for URIBuilder<'uri>
[src]
impl<'uri> PartialEq<URIBuilder<'uri>> for URIBuilder<'uri>
[src]
fn eq(&self, other: &URIBuilder<'uri>) -> bool
[src]
fn ne(&self, other: &URIBuilder<'uri>) -> bool
[src]
impl<'uri> StructuralEq for URIBuilder<'uri>
[src]
impl<'uri> StructuralPartialEq for URIBuilder<'uri>
[src]
Auto Trait Implementations
impl<'uri> RefUnwindSafe for URIBuilder<'uri>
impl<'uri> Send for URIBuilder<'uri>
impl<'uri> Sync for URIBuilder<'uri>
impl<'uri> Unpin for URIBuilder<'uri>
impl<'uri> UnwindSafe for URIBuilder<'uri>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,