[][src]Struct uriparse::uri_reference::URIReferenceBuilder

pub struct URIReferenceBuilder<'uri> { /* fields omitted */ }

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.

Methods

impl<'uri> URIReferenceBuilder<'uri>[src]

pub fn authority<AuthorityType, AuthorityError>(
    &mut self,
    authority: Option<AuthorityType>
) -> &mut Self where
    Authority<'uri>: TryFrom<AuthorityType, Error = AuthorityError>,
    InvalidAuthority: From<AuthorityError>, 
[src]

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 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::URIReferenceBuilder;

let mut builder = URIReferenceBuilder::new();
builder.authority(Some("example.com")).path("/my/path");
let reference = builder.build().unwrap();
assert_eq!(reference.to_string(), "//example.com/my/path");

pub fn build(self) -> Result<URIReference<'uri>, InvalidURIReference>[src]

Consumes the builder and tries to build a URIReference.

This function will error in one of three situations:

  • One of the components specified in the builder is invalid.
  • 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 (invalid path):

use uriparse::URIReferenceBuilder;

let mut builder = URIReferenceBuilder::new();
builder.path("this is an invalid path %%%");
assert!(builder.build().is_err());

Second error type (path not specified):

use uriparse::URIReferenceBuilder;

let builder = URIReferenceBuilder::new();
assert!(builder.build().is_err());

Third error type (first segment in schemeless path cannot contain a ':'):

use uriparse::URIReferenceBuilder;

let mut builder = URIReferenceBuilder::new();
builder.path("my:/path");
assert!(builder.build().is_err());

pub fn fragment<FragmentType, FragmentError>(
    &mut self,
    fragment: Option<FragmentType>
) -> &mut Self where
    Fragment<'uri>: TryFrom<FragmentType, Error = FragmentError>,
    InvalidFragment: From<FragmentError>, 
[src]

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 stored internally and checked during the URIReferenceBuilder::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::URIReferenceBuilder;

let mut builder = URIReferenceBuilder::new();
builder.path("/my/path").fragment(Some("fragment"));
let reference = builder.build().unwrap();
assert_eq!(reference.to_string(), "/my/path#fragment");

pub fn new() -> Self[src]

Constructs a new builder with nothing set.

pub fn path<PathType, PathError>(&mut self, path: PathType) -> &mut Self where
    Path<'uri>: TryFrom<PathType, Error = PathError>,
    InvalidPath: From<PathError>, 
[src]

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 stored internally and checked during the URIReferenceBuilder::build function. The error state will be rewritten for any following calls to this function.

It is required to specify an path. Not doing so will result in an error during the URIReferenceBuilder::build function.

Examples

use uriparse::URIReferenceBuilder;

let mut builder = URIReferenceBuilder::new();
builder.path("/my/path");
let reference = builder.build().unwrap();
assert_eq!(reference.to_string(), "/my/path");

pub fn query<QueryType, QueryError>(
    &mut self,
    query: Option<QueryType>
) -> &mut Self where
    Query<'uri>: TryFrom<QueryType, Error = QueryError>,
    InvalidQuery: From<QueryError>, 
[src]

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 stored internally and checked during the URIReferenceBuilder::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::URIReferenceBuilder;

let mut builder = URIReferenceBuilder::new();
builder.path("/my/path").query(Some("query"));
let reference = builder.build().unwrap();
assert_eq!(reference.to_string(), "/my/path?query");

pub fn scheme<SchemeType, SchemeError>(
    &mut self,
    scheme: Option<SchemeType>
) -> &mut Self where
    Scheme<'uri>: TryFrom<SchemeType, Error = SchemeError>,
    InvalidScheme: From<SchemeError>, 
[src]

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 stored internally and checked during the URIReferenceBuilder::build function. The error state will be rewritten for any following calls to this function.

It is optional to specify a scheme.

Examples

use uriparse::URIReferenceBuilder;

let mut builder = URIReferenceBuilder::new();
builder.scheme(Some("urn")).path("path");
let uri = builder.build().unwrap();
assert_eq!(uri.to_string(), "urn:path");

Trait Implementations

impl<'uri> PartialEq<URIReferenceBuilder<'uri>> for URIReferenceBuilder<'uri>[src]

impl<'uri> Default for URIReferenceBuilder<'uri>[src]

impl<'uri> Clone for URIReferenceBuilder<'uri>[src]

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

impl<'uri> Eq for URIReferenceBuilder<'uri>[src]

impl<'uri> Debug for URIReferenceBuilder<'uri>[src]

Auto Trait Implementations

impl<'uri> Send for URIReferenceBuilder<'uri>

impl<'uri> Sync for URIReferenceBuilder<'uri>

Blanket Implementations

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

impl<T> From for T[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Any for T where
    T: 'static + ?Sized
[src]