Struct uriparse::uri_reference::URIReferenceBuilder
source · [−]pub struct URIReferenceBuilder<'uri> { /* private fields */ }
Expand description
A builder type for [URIReference]
.
You must use the URIReference::path
function before building as URI references always have
have a path. Everything else is optional.
Implementations
sourceimpl<'uri> URIReferenceBuilder<'uri>
impl<'uri> URIReferenceBuilder<'uri>
Sets the authority part of the URI reference.
It is optional to specify a authority.
Examples
use std::convert::TryFrom;
use uriparse::{Authority, Path, URIReferenceBuilder};
let mut builder = URIReferenceBuilder::new();
builder
.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(), "//example.com/my/path");
sourcepub fn build(self) -> Result<URIReference<'uri>, URIReferenceError>
pub fn build(self) -> Result<URIReference<'uri>, URIReferenceError>
Consumes the builder and tries to build a URIReference
.
This function will error in one of two situations:
- A path was not specified in the builder.
- While all individual components were valid, their combination as a URI reference was invalid.
Examples
First error type (path not specified):
use uriparse::URIReferenceBuilder;
let result = URIReferenceBuilder::new().build();
assert!(result.is_err());
Second error type (first segment in schemeless path cannot contain a ':'
):
use std::convert::TryFrom;
use uriparse::{Path, URIReferenceBuilder};
let result = URIReferenceBuilder::new()
.with_path(Path::try_from("my:/path").unwrap())
.build();
assert!(result.is_err());
sourcepub fn fragment(&mut self, fragment: Option<Fragment<'uri>>) -> &mut Self
pub fn fragment(&mut self, fragment: Option<Fragment<'uri>>) -> &mut Self
Sets the fragment part of the URI reference.
It is optional to specify a fragment.
Examples
use std::convert::TryFrom;
use uriparse::{Fragment, Path, URIReferenceBuilder};
let mut builder = URIReferenceBuilder::new();
builder
.path(Path::try_from("/my/path").unwrap())
.fragment(Some(Fragment::try_from("fragment").unwrap()));
let reference = builder.build().unwrap();
assert_eq!(reference.to_string(), "/my/path#fragment");
sourcepub fn path(&mut self, path: Path<'uri>) -> &mut Self
pub fn path(&mut self, path: Path<'uri>) -> &mut Self
Sets the path part of the URI reference.
It is required to specify a path. Not doing so will result in an error during the
URIReferenceBuilder::build
function.
Examples
use std::convert::TryFrom;
use uriparse::{Path, URIReferenceBuilder};
let mut builder = URIReferenceBuilder::new();
builder
.path(Path::try_from("/my/path").unwrap());
let reference = builder.build().unwrap();
assert_eq!(reference.to_string(), "/my/path");
sourcepub fn query(&mut self, query: Option<Query<'uri>>) -> &mut Self
pub fn query(&mut self, query: Option<Query<'uri>>) -> &mut Self
Sets the query part of the URI reference.
It is optional to specify a query.
Examples
use std::convert::TryFrom;
use uriparse::{Path, Query, URIReferenceBuilder};
let mut builder = URIReferenceBuilder::new();
builder
.path(Path::try_from("/my/path").unwrap())
.query(Some(Query::try_from("query").unwrap()));
let reference = builder.build().unwrap();
assert_eq!(reference.to_string(), "/my/path?query");
sourcepub fn scheme(&mut self, scheme: Option<Scheme<'uri>>) -> &mut Self
pub fn scheme(&mut self, scheme: Option<Scheme<'uri>>) -> &mut Self
Sets the scheme part of the URI reference.
It is optional to specify a scheme.
Examples
use std::convert::TryFrom;
use uriparse::{Authority, Path, Scheme, URIReferenceBuilder};
let mut builder = URIReferenceBuilder::new();
builder
.scheme(Some(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");
Sets the authority part of the URI reference.
If the given authority is not a valid authority (i.e. the conversion fails), an error is return.
It is optional to specify an authority.
Examples
use uriparse::URIReferenceBuilder;
let mut builder = URIReferenceBuilder::new();
builder
.try_authority(Some("example.com"))
.unwrap()
.try_path("/my/path")
.unwrap();
let reference = builder.build().unwrap();
assert_eq!(reference.to_string(), "//example.com/my/path");
sourcepub fn try_fragment<TFragment, TFragmentError>(
&mut self,
fragment: Option<TFragment>
) -> Result<&mut Self, FragmentError> where
Fragment<'uri>: TryFrom<TFragment, Error = TFragmentError>,
FragmentError: From<TFragmentError>,
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>,
Sets the fragment part of the URI reference.
If the given fragment is not a valid fragment (i.e. the conversion fails), an error is returned.
It is optional to specify a fragment.
Examples
use uriparse::URIReferenceBuilder;
let mut builder = URIReferenceBuilder::new();
builder
.try_path("/my/path")
.unwrap()
.try_fragment(Some("fragment"))
.unwrap();
let reference = builder.build().unwrap();
assert_eq!(reference.to_string(), "/my/path#fragment");
sourcepub fn try_path<TPath, TPathError>(
&mut self,
path: TPath
) -> Result<&mut Self, PathError> where
Path<'uri>: TryFrom<TPath, Error = TPathError>,
PathError: From<TPathError>,
pub fn try_path<TPath, TPathError>(
&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 reference.
If the given path is not a valid path (i.e. the conversion fails), an error is returned.
It is required to specify a path. Not doing so will result in an error during the
URIReferenceBuilder::build
function.
Examples
use uriparse::URIReferenceBuilder;
let mut builder = URIReferenceBuilder::new();
builder
.try_path("/my/path")
.unwrap();
let reference = builder.build().unwrap();
assert_eq!(reference.to_string(), "/my/path");
sourcepub fn try_query<TQuery, TQueryError>(
&mut self,
query: Option<TQuery>
) -> Result<&mut Self, QueryError> where
Query<'uri>: TryFrom<TQuery, Error = TQueryError>,
QueryError: From<TQueryError>,
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>,
Sets the query part of the URI reference.
If the given query is not a valid query (i.e. the conversion fails), an error is returned.
It is optional to specify a query.
Examples
use uriparse::URIReferenceBuilder;
let mut builder = URIReferenceBuilder::new();
builder
.try_path("/my/path")
.unwrap()
.try_query(Some("query"))
.unwrap();
let reference = builder.build().unwrap();
assert_eq!(reference.to_string(), "/my/path?query");
sourcepub fn try_scheme<TScheme, TSchemeError>(
&mut self,
scheme: Option<TScheme>
) -> Result<&mut Self, SchemeError> where
Scheme<'uri>: TryFrom<TScheme, Error = TSchemeError>,
SchemeError: From<TSchemeError>,
pub fn try_scheme<TScheme, TSchemeError>(
&mut self,
scheme: Option<TScheme>
) -> Result<&mut Self, SchemeError> where
Scheme<'uri>: TryFrom<TScheme, Error = TSchemeError>,
SchemeError: From<TSchemeError>,
Sets the scheme part of the URI reference.
If the given scheme is not a valid scheme (i.e. the conversion fails), an error is returned.
It is optional to specify a scheme.
Examples
use uriparse::URIReferenceBuilder;
let mut builder = URIReferenceBuilder::new();
builder
.try_scheme(Some("urn"))
.unwrap()
.try_path("path")
.unwrap();
let uri = builder.build().unwrap();
assert_eq!(uri.to_string(), "urn:path");
Consumes the builder and sets the authority part of the URI reference.
It is optional to specify an authority.
Examples
use std::convert::TryFrom;
use uriparse::{Authority, Path, URIReferenceBuilder};
let reference = URIReferenceBuilder::new()
.with_authority(Some(Authority::try_from("example.com").unwrap()))
.with_path(Path::try_from("/").unwrap())
.build()
.unwrap();
assert_eq!(reference.to_string(), "//example.com/")
sourcepub fn with_fragment(self, fragment: Option<Fragment<'uri>>) -> Self
pub fn with_fragment(self, fragment: Option<Fragment<'uri>>) -> Self
Consumes the builder and sets the fragment part of the URI reference.
It is optional to specify a fragment.
Examples
use std::convert::TryFrom;
use uriparse::{Fragment, Path, URIReferenceBuilder};
let reference = URIReferenceBuilder::new()
.with_path(Path::try_from("/").unwrap())
.with_fragment(Some(Fragment::try_from("fragment").unwrap()))
.build()
.unwrap();
assert_eq!(reference.to_string(), "/#fragment")
sourcepub fn with_path(self, path: Path<'uri>) -> Self
pub fn with_path(self, path: Path<'uri>) -> Self
Consumes the builder and sets the path part of the URI reference.
It is required to specify a path. Not doing so will result in an error during the
URIReferenceBuilder::build
function.
Examples
use std::convert::TryFrom;
use uriparse::{Path, URIReferenceBuilder};
let reference = URIReferenceBuilder::new()
.with_path(Path::try_from("/").unwrap())
.build()
.unwrap();
assert_eq!(reference.to_string(), "/")
sourcepub fn with_query(self, query: Option<Query<'uri>>) -> Self
pub fn with_query(self, query: Option<Query<'uri>>) -> Self
Consumes the builder and sets the query part of the URI reference.
It is optional to specify a query.
Examples
use std::convert::TryFrom;
use uriparse::{Path, Query, URIReferenceBuilder};
let reference = URIReferenceBuilder::new()
.with_path(Path::try_from("/").unwrap())
.with_query(Some(Query::try_from("query").unwrap()))
.build()
.unwrap();
assert_eq!(reference.to_string(), "/?query")
sourcepub fn with_scheme(self, scheme: Option<Scheme<'uri>>) -> Self
pub fn with_scheme(self, scheme: Option<Scheme<'uri>>) -> Self
Consumes the builder and sets the scheme part of the URI reference.
It is optional to specify a scheme.
Examples
use std::convert::TryFrom;
use uriparse::{Authority, Path, Scheme, URIReferenceBuilder};
let reference = URIReferenceBuilder::new()
.with_scheme(Some(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
sourceimpl<'uri> Clone for URIReferenceBuilder<'uri>
impl<'uri> Clone for URIReferenceBuilder<'uri>
sourcefn clone(&self) -> URIReferenceBuilder<'uri>
fn clone(&self) -> URIReferenceBuilder<'uri>
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl<'uri> Debug for URIReferenceBuilder<'uri>
impl<'uri> Debug for URIReferenceBuilder<'uri>
sourceimpl<'uri> Default for URIReferenceBuilder<'uri>
impl<'uri> Default for URIReferenceBuilder<'uri>
sourcefn default() -> URIReferenceBuilder<'uri>
fn default() -> URIReferenceBuilder<'uri>
Returns the “default value” for a type. Read more
sourceimpl<'uri> PartialEq<URIReferenceBuilder<'uri>> for URIReferenceBuilder<'uri>
impl<'uri> PartialEq<URIReferenceBuilder<'uri>> for URIReferenceBuilder<'uri>
sourcefn eq(&self, other: &URIReferenceBuilder<'uri>) -> bool
fn eq(&self, other: &URIReferenceBuilder<'uri>) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourcefn ne(&self, other: &URIReferenceBuilder<'uri>) -> bool
fn ne(&self, other: &URIReferenceBuilder<'uri>) -> bool
This method tests for !=
.
impl<'uri> Eq for URIReferenceBuilder<'uri>
impl<'uri> StructuralEq for URIReferenceBuilder<'uri>
impl<'uri> StructuralPartialEq for URIReferenceBuilder<'uri>
Auto Trait Implementations
impl<'uri> RefUnwindSafe for URIReferenceBuilder<'uri>
impl<'uri> Send for URIReferenceBuilder<'uri>
impl<'uri> Sync for URIReferenceBuilder<'uri>
impl<'uri> Unpin for URIReferenceBuilder<'uri>
impl<'uri> UnwindSafe for URIReferenceBuilder<'uri>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more