Struct uriparse::uri::URIBuilder [−][src]
pub struct URIBuilder<'uri> { /* fields omitted */ }
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.
Methods
impl<'uri> URIBuilder<'uri>
[src]
impl<'uri> URIBuilder<'uri>
ⓘImportant traits for &'a mut R
Sets the authority part of the URI.
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.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 build(self) -> Result<URI<'uri>, InvalidURI>
[src]
pub fn build(self) -> Result<URI<'uri>, InvalidURI>
Consumes the builder and tries to build a URI
.
This function will error in one of three situations:
- One of the components specified in the builder is invalid.
- 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 (invalid path):
use uriparse::URIBuilder; let mut builder = URIBuilder::new(); builder.scheme("urn").path("this is an invalid path %%%"); assert!(builder.build().is_err());
Second error type (scheme and/or path were not specified):
use uriparse::URIBuilder; let mut builder = URIBuilder::new(); builder.path("/my/path"); assert!(builder.build().is_err());
Third error type (URI with no authority cannot have path starting with "//"
):
use uriparse::URIBuilder; let mut builder = URIBuilder::new(); builder.scheme("urn").path("//path"); assert!(builder.build().is_err());
ⓘImportant traits for &'a mut Rpub fn fragment<FragmentType, FragmentError>(
&mut self,
fragment: Option<FragmentType>
) -> &mut Self where
Fragment<'uri>: TryFrom<FragmentType, Error = FragmentError>,
InvalidFragment: From<FragmentError>,
[src]
pub fn fragment<FragmentType, FragmentError>(
&mut self,
fragment: Option<FragmentType>
) -> &mut Self where
Fragment<'uri>: TryFrom<FragmentType, Error = FragmentError>,
InvalidFragment: From<FragmentError>,
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.scheme("urn").path("path").fragment(Some("fragment")); let uri = builder.build().unwrap(); assert_eq!(uri.to_string(), "urn:path#fragment");
pub fn new() -> Self
[src]
pub fn new() -> Self
Constructs a new builder with nothing set.
ⓘImportant traits for &'a mut Rpub fn path<PathType, PathError>(&mut self, path: PathType) -> &mut Self where
Path<'uri>: TryFrom<PathType, Error = PathError>,
InvalidPath: From<PathError>,
[src]
pub fn path<PathType, PathError>(&mut self, path: PathType) -> &mut Self where
Path<'uri>: TryFrom<PathType, Error = PathError>,
InvalidPath: From<PathError>,
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.scheme("urn").path("path"); let uri = builder.build().unwrap(); assert_eq!(uri.to_string(), "urn:path");
ⓘImportant traits for &'a mut Rpub fn query<QueryType, QueryError>(
&mut self,
query: Option<QueryType>
) -> &mut Self where
Query<'uri>: TryFrom<QueryType, Error = QueryError>,
InvalidQuery: From<QueryError>,
[src]
pub fn query<QueryType, QueryError>(
&mut self,
query: Option<QueryType>
) -> &mut Self where
Query<'uri>: TryFrom<QueryType, Error = QueryError>,
InvalidQuery: From<QueryError>,
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.scheme("urn").path("path").query(Some("query")); let uri = builder.build().unwrap(); assert_eq!(uri.to_string(), "urn:path?query");
ⓘImportant traits for &'a mut Rpub fn scheme<SchemeType, SchemeError>(
&mut self,
scheme: SchemeType
) -> &mut Self where
Scheme<'uri>: TryFrom<SchemeType, Error = SchemeError>,
InvalidScheme: From<SchemeError>,
[src]
pub fn scheme<SchemeType, SchemeError>(
&mut self,
scheme: SchemeType
) -> &mut Self where
Scheme<'uri>: TryFrom<SchemeType, Error = SchemeError>,
InvalidScheme: From<SchemeError>,
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.
Examples
use uriparse::URIBuilder; let mut builder = URIBuilder::new(); builder.scheme("urn").path("path"); let uri = builder.build().unwrap(); assert_eq!(uri.to_string(), "urn:path");
Trait Implementations
impl<'uri> Clone for URIBuilder<'uri>
[src]
impl<'uri> Clone for URIBuilder<'uri>
fn clone(&self) -> URIBuilder<'uri>
[src]
fn clone(&self) -> URIBuilder<'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 URIBuilder<'uri>
[src]
impl<'uri> Debug for URIBuilder<'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> Default for URIBuilder<'uri>
[src]
impl<'uri> Default for URIBuilder<'uri>
fn default() -> URIBuilder<'uri>
[src]
fn default() -> URIBuilder<'uri>
Returns the "default value" for a type. Read more
impl<'uri> Eq for URIBuilder<'uri>
[src]
impl<'uri> Eq for URIBuilder<'uri>
impl<'uri> PartialEq for URIBuilder<'uri>
[src]
impl<'uri> PartialEq for URIBuilder<'uri>
fn eq(&self, other: &URIBuilder<'uri>) -> bool
[src]
fn eq(&self, other: &URIBuilder<'uri>) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &URIBuilder<'uri>) -> bool
[src]
fn ne(&self, other: &URIBuilder<'uri>) -> bool
This method tests for !=
.
Auto Trait Implementations
impl<'uri> Send for URIBuilder<'uri>
impl<'uri> Send for URIBuilder<'uri>
impl<'uri> Sync for URIBuilder<'uri>
impl<'uri> Sync for URIBuilder<'uri>