Struct Builder
struct Builder<'a> { ... }
URI/IRI reference builder.
Usage
- Create builder by [
Builder::new()]Self::new. - Set (or unset) components and set normalization mode as you wish.
- Validate by [
Builder::build()]Self::buildand getBuiltvalue. - Use
core::fmt::Displaytrait to serialize the resultingBuilt, or useFrom/Intotraits to convert into an allocated string types.
# use Error;
use Builder;
#
# use IriStr;
#
use ;
// 1. Create builder.
let mut builder = new;
// 2. Set (or unset) component and normalization mode.
builder.scheme;
builder.host;
builder.path;
builder.normalize;
// 3. Validate and create the result.
let built = builder.?;
#
#
# Ok::
Implementations
impl<'a> Builder<'a>
fn new() -> SelfCreates a builder with empty data.
Examples
# use Error; use Builder; use IriReferenceStr; let builder = new; let iri = builder.?; # # Ok::fn build<T>(self: Self) -> Result<Built<'a, T>, Error> where T: ?Sized + Buildable<'a>Builds the proxy object that can be converted to the desired IRI string type.
Examples
# use Error; use Builder; use IriStr; # use IriString; let mut builder = new; builder.scheme; builder.host; builder.path; let built = builder.?; # # Ok::
impl<'a> Builder<'a>
fn scheme(self: &mut Self, v: &'a str)Sets the scheme.
Examples
# use Error; use Builder; use IriReferenceStr; let mut builder = new; builder.scheme; let iri = builder.?; # # Ok::fn unset_scheme(self: &mut Self)Unsets the scheme.
Examples
# use Error; use Builder; use IriReferenceStr; let mut builder = new; builder.scheme; builder.unset_scheme; let iri = builder.?; # # Ok::fn path(self: &mut Self, v: &'a str)Sets the path.
Note that no methods are provided to "unset" path since every IRI references has a path component (although it can be empty). If you want to "unset" the path, just set the empty string.
Examples
# use Error; use Builder; use IriReferenceStr; let mut builder = new; builder.path; let iri = builder.?; # # Ok::Unsets the authority.
Examples
# use Error; use Builder; use IriReferenceStr; let mut builder = new; builder.host; builder.unset_authority; let iri = builder.?; # # Ok::fn userinfo<T: Into<UserinfoBuilder<'a>>>(self: &mut Self, v: T)Sets the userinfo.
userinfocomponent always haveuserpart (but it can be empty).Note that
("", None)is considered as an empty userinfo, rather than unset userinfo. Also note that the user part cannot have colon characters.Examples
# use Error; use Builder; use IriReferenceStr; let mut builder = new; builder.userinfo; let iri = builder.?; # # Ok::You can specify
(user, password)pair.# use Error; use Builder; use IriReferenceStr; let mut builder = new; builder.userinfo; # # Ok::("", None)is considered as an empty userinfo.# use Error; use Builder; use IriReferenceStr; let mut builder = new; builder.userinfo; let iri = builder.?; # # Ok::fn unset_userinfo(self: &mut Self)Unsets the port.
Examples
# use Error; use Builder; use IriReferenceStr; let mut builder = new; builder.userinfo; // Note that this does not unset the entire authority. // Now empty authority is set. builder.unset_userinfo; let iri = builder.?; # # Ok::fn host(self: &mut Self, v: &'a str)Sets the reg-name or IP address (i.e. host) without port.
Note that no methods are provided to "unset" host. Depending on your situation, set empty string as a reg-name, or unset the authority entirely by [
unset_authority]Self::unset_authoritymethod.Examples
# use Error; use Builder; use IriReferenceStr; let mut builder = new; builder.host; let iri = builder.?; # # Ok::fn ip_address<T: Into<std::net::IpAddr>>(self: &mut Self, addr: T)Sets the IP address as a host.
Note that no methods are provided to "unset" host. Depending on your situation, set empty string as a reg-name, or unset the authority entirely by [
unset_authority]Self::unset_authoritymethod.Examples
# use Error; # # Ok::fn port<T: Into<PortBuilder<'a>>>(self: &mut Self, v: T)Sets the port.
Examples
# use Error; use Builder; use IriReferenceStr; let mut builder = new; builder.port; // Accepts other types that implements `Into<PortBuilder<'a>>`. //builder.port(80_u8); //builder.port("80"); let iri = builder.?; # # Ok::fn unset_port(self: &mut Self)Unsets the port.
Examples
# use Error; use Builder; use IriReferenceStr; let mut builder = new; builder.port; // Note that this does not unset the entire authority. // Now empty authority is set. builder.unset_port; let iri = builder.?; # # Ok::fn query(self: &mut Self, v: &'a str)Sets the query.
The string after
?should be specified.Examples
# use Error; use Builder; use IriReferenceStr; let mut builder = new; builder.query; let iri = builder.?; # # Ok::fn unset_query(self: &mut Self)Unsets the query.
Examples
# use Error; use Builder; use IriReferenceStr; let mut builder = new; builder.query; builder.unset_query; let iri = builder.?; # # Ok::fn fragment(self: &mut Self, v: &'a str)Sets the fragment.
The string after
#should be specified.Examples
# use Error; use Builder; use IriReferenceStr; let mut builder = new; builder.fragment; let iri = builder.?; # # Ok::fn unset_fragment(self: &mut Self)Unsets the fragment.
Examples
# use Error; use Builder; use IriReferenceStr; let mut builder = new; builder.fragment; builder.unset_fragment; let iri = builder.?; # # Ok::fn unset_normalize(self: &mut Self)Stop normalizing the result.
Examples
# use Error; use Builder; use IriReferenceStr; let mut builder = new; builder.scheme; // `%75%73%65%72` is "user". builder.userinfo; builder.host; builder.port; builder.path; builder.unset_normalize; let iri = builder.?; # # Ok::fn normalize(self: &mut Self)Normalizes the result using RFC 3986 syntax-based normalization and WHATWG URL Standard algorithm.
Normalization
If
schemeorauthoritycomponent is present or the path is absolute, the build result will fully normalized using full syntax-based normalization:- case normalization ([RFC 3986 6.2.2.1]),
- percent-encoding normalization ([RFC 3986 6.2.2.2]), and
- path segment normalization ([RFC 3986 6.2.2.2]).
However, if both
schemeandauthorityis absent and the path is relative (including empty), i.e. the IRI reference to be built starts with the relativepathcomponent, path segment normalization will be omitted. This is because the path segment normalization depends on presence or absense of theauthoritycomponents, and will remove extra..segments which should not be ignored.Note that
pathmust already be empty or start with a slash before the normalizaiton ifauthorityis present.WHATWG URL Standard
If you need to avoid WHATWG URL Standard serialization, use
Built::ensure_rfc3986_normalizablemethod to test if the result is normalizable without WHATWG spec.Examples
# use Error; use Builder; use IriReferenceStr; let mut builder = new; builder.scheme; // `%75%73%65%72` is "user". builder.userinfo; builder.host; builder.port; builder.path; builder.normalize; let iri = builder.?; # # Ok::
impl<'a> Clone for Builder<'a>
fn clone(self: &Self) -> Builder<'a>
impl<'a> Debug for Builder<'a>
fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result
impl<'a> Default for Builder<'a>
fn default() -> Builder<'a>
impl<'a> Freeze for Builder<'a>
impl<'a> RefUnwindSafe for Builder<'a>
impl<'a> Send for Builder<'a>
impl<'a> Sync for Builder<'a>
impl<'a> Unpin for Builder<'a>
impl<'a> UnsafeUnpin for Builder<'a>
impl<'a> UnwindSafe for Builder<'a>
impl<T> Any for Builder<'a>
fn type_id(self: &Self) -> TypeId
impl<T> Borrow for Builder<'a>
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for Builder<'a>
fn borrow_mut(self: &mut Self) -> &mut T
impl<T> CloneToUninit for Builder<'a>
unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)
impl<T> From for Builder<'a>
fn from(t: T) -> TReturns the argument unchanged.
impl<T> ToOwned for Builder<'a>
fn to_owned(self: &Self) -> Tfn clone_into(self: &Self, target: &mut T)
impl<T, U> Into for Builder<'a>
fn into(self: Self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom for Builder<'a>
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto for Builder<'a>
fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>