Struct RelativeReferenceBuilder

Source
pub struct RelativeReferenceBuilder<'uri> { /* private fields */ }
Expand description

A builder type for [RelativeReference].

You must use the RelativeReferenceBuilder::path function before building as relative references always have a path. Everything else is optional.

Implementations§

Source§

impl<'uri> RelativeReferenceBuilder<'uri>

Source

pub fn authority(&mut self, authority: Option<Authority<'uri>>) -> &mut Self

Sets the authority part of the relative reference.

It is optional to specify a authority.

§Examples
use std::convert::TryFrom;

use uriparse::{Authority, Path, RelativeReferenceBuilder};

let mut builder = RelativeReferenceBuilder::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");
Source

pub fn build(self) -> Result<RelativeReference<'uri>, RelativeReferenceError>

Consumes the builder and tries to build a RelativeReference.

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 relative reference was invalid.
§Examples

First error type (path not specified):

use uriparse::RelativeReferenceBuilder;

let result = RelativeReferenceBuilder::new().build();
assert!(result.is_err());

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

use std::convert::TryFrom;

use uriparse::{Path, RelativeReferenceBuilder};

let result = RelativeReferenceBuilder::new()
    .with_path(Path::try_from("my:/path").unwrap())
    .build();
assert!(result.is_err());
Source

pub fn fragment(&mut self, fragment: Option<Fragment<'uri>>) -> &mut Self

Sets the fragment part of the relative reference.

It is optional to specify a fragment.

§Examples
use std::convert::TryFrom;

use uriparse::{Fragment, Path, RelativeReferenceBuilder};

let mut builder = RelativeReferenceBuilder::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");
Source

pub fn new() -> Self

Constructs a new builder with nothing set.

Source

pub fn path(&mut self, path: Path<'uri>) -> &mut Self

Sets the path part of the relative reference.

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

§Examples
use std::convert::TryFrom;

use uriparse::{Path, RelativeReferenceBuilder};

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

pub fn query(&mut self, query: Option<Query<'uri>>) -> &mut Self

Sets the query part of the relative reference.

It is optional to specify a query.

§Examples
use std::convert::TryFrom;

use uriparse::{Path, Query, RelativeReferenceBuilder};

let mut builder = RelativeReferenceBuilder::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");
Source

pub fn try_authority<TAuthority, TAuthorityError>( &mut self, authority: Option<TAuthority>, ) -> Result<&mut Self, TAuthorityError>
where Authority<'uri>: TryFrom<TAuthority, Error = TAuthorityError>, AuthorityError: From<TAuthorityError>,

Sets the authority part of the relative reference.

If the given authority is not a valid authority (i.e. the conversion fails), an error is stored internally and checked during the RelativeReferenceBuilder::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::RelativeReferenceBuilder;

let mut builder = RelativeReferenceBuilder::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");
Source

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 relative reference.

If the given fragment is not a valid fragment (i.e. the conversion fails), an error is stored internally and checked during the RelativeReferenceBuilder::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::RelativeReferenceBuilder;

let mut builder = RelativeReferenceBuilder::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");
Source

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 relative reference.

If the given path is not a valid path (i.e. the conversion fails), an error is stored internally and checked during the RelativeReferenceBuilder::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 RelativeReferenceBuilder::build function.

§Examples
use uriparse::RelativeReferenceBuilder;

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

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 relative reference.

If the given query is not a valid query (i.e. the conversion fails), an error is stored internally and checked during the RelativeReferenceBuilder::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::RelativeReferenceBuilder;

let mut builder = RelativeReferenceBuilder::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");
Source

pub fn with_authority(self, authority: Option<Authority<'uri>>) -> Self

Consumes the builder and sets the authority part of the relative reference.

It is optional to specify an authority.

§Examples
use std::convert::TryFrom;

use uriparse::{Authority, Path, RelativeReferenceBuilder};

let reference = RelativeReferenceBuilder::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/")
Source

pub fn with_fragment(self, fragment: Option<Fragment<'uri>>) -> Self

Consumes the builder and sets the fragment part of the relative reference.

It is optional to specify a fragment.

§Examples
use std::convert::TryFrom;

use uriparse::{Fragment, Path, RelativeReferenceBuilder};

let reference = RelativeReferenceBuilder::new()
    .with_path(Path::try_from("/").unwrap())
    .with_fragment(Some(Fragment::try_from("fragment").unwrap()))
    .build()
    .unwrap();
assert_eq!(reference.to_string(), "/#fragment")
Source

pub fn with_path(self, path: Path<'uri>) -> Self

Consumes the builder and sets the path part of the relative reference.

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

§Examples
use std::convert::TryFrom;

use uriparse::{Path, RelativeReferenceBuilder};

let reference = RelativeReferenceBuilder::new()
    .with_path(Path::try_from("/").unwrap())
    .build()
    .unwrap();
assert_eq!(reference.to_string(), "/")
Source

pub fn with_query(self, query: Option<Query<'uri>>) -> Self

Consumes the builder and sets the query part of the relative reference.

It is optional to specify a query.

§Examples
use std::convert::TryFrom;

use uriparse::{Path, Query, RelativeReferenceBuilder};

let reference = RelativeReferenceBuilder::new()
    .with_path(Path::try_from("/").unwrap())
    .with_query(Some(Query::try_from("query").unwrap()))
    .build()
    .unwrap();
assert_eq!(reference.to_string(), "/?query")

Trait Implementations§

Source§

impl<'uri> Clone for RelativeReferenceBuilder<'uri>

Source§

fn clone(&self) -> RelativeReferenceBuilder<'uri>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'uri> Debug for RelativeReferenceBuilder<'uri>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'uri> Default for RelativeReferenceBuilder<'uri>

Source§

fn default() -> RelativeReferenceBuilder<'uri>

Returns the “default value” for a type. Read more
Source§

impl<'uri> PartialEq for RelativeReferenceBuilder<'uri>

Source§

fn eq(&self, other: &RelativeReferenceBuilder<'uri>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'uri> Eq for RelativeReferenceBuilder<'uri>

Source§

impl<'uri> StructuralPartialEq for RelativeReferenceBuilder<'uri>

Auto Trait Implementations§

§

impl<'uri> Freeze for RelativeReferenceBuilder<'uri>

§

impl<'uri> RefUnwindSafe for RelativeReferenceBuilder<'uri>

§

impl<'uri> Send for RelativeReferenceBuilder<'uri>

§

impl<'uri> Sync for RelativeReferenceBuilder<'uri>

§

impl<'uri> Unpin for RelativeReferenceBuilder<'uri>

§

impl<'uri> UnwindSafe for RelativeReferenceBuilder<'uri>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.