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
sourceimpl<'uri> RelativeReferenceBuilder<'uri>
impl<'uri> RelativeReferenceBuilder<'uri>
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.authority(Some("example.com")).path("/my/path");
let reference = builder.build().unwrap();
assert_eq!(reference.to_string(), "//example.com/my/path");
sourcepub fn build(self) -> Result<RelativeReference<'uri>, InvalidRelativeReference>
pub fn build(self) -> Result<RelativeReference<'uri>, InvalidRelativeReference>
Consumes the builder and tries to build a RelativeReference
.
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 relative reference was invalid.
Examples
First error type (invalid path):
use uriparse::RelativeReferenceBuilder;
let mut builder = RelativeReferenceBuilder::new();
builder.path("this is an invalid path %%%");
assert!(builder.build().is_err());
Second error type (path not specified):
use uriparse::RelativeReferenceBuilder;
let builder = RelativeReferenceBuilder::new();
assert!(builder.build().is_err());
Third error type (first segment in schemeless path cannot contain a ':'
):
use uriparse::RelativeReferenceBuilder;
let mut builder = RelativeReferenceBuilder::new();
builder.path("my:/path");
assert!(builder.build().is_err());
sourcepub fn fragment<FragmentType, FragmentError>(
&mut self,
fragment: Option<FragmentType>
) -> &mut Selfwhere
Fragment<'uri>: TryFrom<FragmentType, Error = FragmentError>,
InvalidFragment: From<FragmentError>,
pub fn fragment<FragmentType, FragmentError>(
&mut self,
fragment: Option<FragmentType>
) -> &mut Selfwhere
Fragment<'uri>: TryFrom<FragmentType, Error = FragmentError>,
InvalidFragment: From<FragmentError>,
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.path("/my/path").fragment(Some("fragment"));
let reference = builder.build().unwrap();
assert_eq!(reference.to_string(), "/my/path#fragment");
sourcepub fn path<PathType, PathError>(&mut self, path: PathType) -> &mut Selfwhere
Path<'uri>: TryFrom<PathType, Error = PathError>,
InvalidPath: From<PathError>,
pub fn path<PathType, PathError>(&mut self, path: PathType) -> &mut Selfwhere
Path<'uri>: TryFrom<PathType, Error = PathError>,
InvalidPath: From<PathError>,
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.path("/my/path");
let reference = builder.build().unwrap();
assert_eq!(reference.to_string(), "/my/path");
sourcepub fn query<QueryType, QueryError>(
&mut self,
query: Option<QueryType>
) -> &mut Selfwhere
Query<'uri>: TryFrom<QueryType, Error = QueryError>,
InvalidQuery: From<QueryError>,
pub fn query<QueryType, QueryError>(
&mut self,
query: Option<QueryType>
) -> &mut Selfwhere
Query<'uri>: TryFrom<QueryType, Error = QueryError>,
InvalidQuery: From<QueryError>,
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.path("/my/path").query(Some("query"));
let reference = builder.build().unwrap();
assert_eq!(reference.to_string(), "/my/path?query");
Trait Implementations
sourceimpl<'uri> Clone for RelativeReferenceBuilder<'uri>
impl<'uri> Clone for RelativeReferenceBuilder<'uri>
sourcefn clone(&self) -> RelativeReferenceBuilder<'uri>
fn clone(&self) -> RelativeReferenceBuilder<'uri>
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more