Struct RiStr
struct RiStr<S> { ... }
A borrowed string of an absolute IRI possibly with fragment part.
This corresponds to IRI rule in RFC 3987 (and URI rule in RFC 3986).
The rule for IRI is scheme ":" ihier-part [ "?" iquery ] [ "#" ifragment ].
In other words, this is RiAbsoluteStr with fragment part allowed.
Valid values
This type can have an IRI (which is absolute, and may have fragment part).
# use IriStr;
assert!;
assert!;
assert!;
assert!;
assert!;
assert!;
// `foo://.../` below are all allowed. See the crate documentation for detail.
assert!;
assert!;
assert!;
assert!;
assert!;
Relative IRI reference is not allowed.
# use IriStr;
// This is relative path.
assert!;
// `/foo/bar` is an absolute path, but it is authority-relative.
assert!;
// `//foo/bar` is termed "network-path reference",
// or usually called "protocol-relative reference".
assert!;
// Same-document reference is relative.
assert!;
// Empty string is not a valid absolute IRI.
assert!;
Some characters and sequences cannot used in an IRI.
# use IriStr;
// `<` and `>` cannot directly appear in an IRI.
assert!;
// Broken percent encoding cannot appear in an IRI.
assert!;
assert!;
Implementations
impl RiStr<IriSpec>
fn encode_to_uri(self: &Self) -> MappedToUri<'_, Self>Percent-encodes the IRI into a valid URI that identifies the equivalent resource.
If you need more precise control over memory allocation and buffer handling, use [
MappedToUri]crate::convert::MappedToUritype.Examples
# use Error; # # Ok::fn as_uri(self: &Self) -> Option<&UriStr>Converts an IRI into a URI without modification, if possible.
This is semantically equivalent to
UriStr::new(self.as_str()).ok().Examples
# use Error; use ; let ascii_iri = new?; assert_eq!; let nonascii_iri = new?; assert_eq!; # Ok::
impl<S: Spec> RiStr<S>
fn scheme_str(self: &Self) -> &strReturns the scheme.
The following colon is truncated.
Examples
# use Error; use IriStr; let iri = new?; assert_eq!; # Ok::Returns the authority.
The leading
//is truncated.Examples
# use Error; use IriStr; let iri = new?; assert_eq!; # Ok::# use Error; use IriStr; let iri = new?; assert_eq!; # Ok::fn path_str(self: &Self) -> &strReturns the path.
Examples
# use Error; use IriStr; let iri = new?; assert_eq!; # Ok::# use Error; use IriStr; let iri = new?; assert_eq!; # Ok::fn query(self: &Self) -> Option<&RiQueryStr<S>>Returns the query.
The leading question mark (
?) is truncated.Examples
# use Error; use ; let iri = new?; let query = new?; assert_eq!; # Ok::# use Error; use IriStr; let iri = new?; assert_eq!; # Ok::fn query_str(self: &Self) -> Option<&str>Returns the query in a raw string slice.
The leading question mark (
?) is truncated.Examples
# use Error; use IriStr; let iri = new?; assert_eq!; # Ok::# use Error; use IriStr; let iri = new?; assert_eq!; # Ok::fn fragment(self: &Self) -> Option<&RiFragmentStr<S>>Returns the fragment part if exists.
A leading
#character is truncated if the fragment part exists.Examples
# use ; let iri = new?; let fragment = new?; assert_eq!; # Ok::# use ; let iri = new?; let fragment = new?; assert_eq!; # Ok::# use ; let iri = new?; assert_eq!; # Ok::fn fragment_str(self: &Self) -> Option<&str>Returns the fragment part as a raw string slice if exists.
A leading
#character is truncated if the fragment part exists.Examples
# use ; let iri = new?; assert_eq!; # Ok::# use ; let iri = new?; assert_eq!; # Ok::# use ; let iri = new?; assert_eq!; # Ok::Returns the authority components.
Examples
# use Error; use IriStr; let iri = new?; let authority = iri.authority_components .expect; assert_eq!; assert_eq!; assert_eq!; # Ok::# use Error; use IriStr; let iri = new?; assert_eq!; # Ok::
impl<S: Spec> RiStr<S>
fn to_absolute_and_fragment(self: &Self) -> (&RiAbsoluteStr<S>, Option<&RiFragmentStr<S>>)Splits the IRI into an absolute IRI part and a fragment part.
A leading
#character is truncated if the fragment part exists.Examples
If the IRI has a fragment part,
Some(_)is returned.# use ; let iri = new?; let = iri.to_absolute_and_fragment; let fragment_expected = new?; assert_eq!; assert_eq!; # Ok::When the fragment part exists but is empty string,
Some(_)is returned.# use ; let iri = new?; let = iri.to_absolute_and_fragment; let fragment_expected = new?; assert_eq!; assert_eq!; # Ok::If the IRI has no fragment,
Noneis returned.# use ; let iri = new?; let = iri.to_absolute_and_fragment; assert_eq!; assert_eq!; # Ok::fn to_absolute(self: &Self) -> &RiAbsoluteStr<S>Strips the fragment part if exists, and returns
&RiAbsoluteStr.Examples
# use ; let iri = new?; assert_eq!; # Ok::# use ; let iri = new?; assert_eq!; # Ok::fn ensure_rfc3986_normalizable(self: &Self) -> Result<(), Error>Returns Ok
(())if the IRI is normalizable by the RFC 3986 algorithm.Examples
# use Error; use IriStr; let iri = new?; assert!; let iri2 = new?; // The normalization result would be `scheme://bar` according to RFC // 3986, but it is unintended and should be treated as a failure. // This crate automatically handles this case so that `.normalize()` won't fail. assert!; # Ok::fn is_normalized(self: &Self) -> boolReturns
trueif the IRI is already normalized.This returns the same result as
self.normalize().to_string() == self, but does this more efficiently without heap allocation.Examples
# use Error; # # Ok::# use Error; # # Ok::# use Error; # # Ok::fn is_normalized_rfc3986(self: &Self) -> boolReturns
trueif the IRI is already normalized in the sense of RFC 3986.This returns the same result as
self.ensure_rfc3986_normalizable() && (self.normalize().to_string() == self), but does this more efficiently without heap allocation.Examples
# use Error; # # Ok::# use Error; # # Ok::# use Error; # # Ok::Returns
trueif the IRI is already normalized in the sense ofnormalize_but_preserve_authorityless_relative_pathmethod.This returns the same result as
self.normalize_but_preserve_authorityless_relative_path().to_string() == self, but does this more efficiently without heap allocation.Examples
# use Error; # # Ok::# use Error; # # Ok::# use Error; # # Ok::fn normalize(self: &Self) -> Normalized<'_, Self>Returns the normalized IRI.
Notes
For some abnormal IRIs, the normalization can produce semantically incorrect string that looks syntactically valid. To avoid security issues by this trap, the normalization algorithm by this crate automatically applies the workaround.
If you worry about this, test by
RiStr::ensure_rfc3986_normalizablemethod orNormalized::ensure_rfc3986_normalizablebefore using the result string.Examples
# use Error; # # Ok::Returns the normalized IRI, but preserving dot segments in relative path if the authority component is absent.
This normalization would be similar to that of WHATWG URL Standard while this implementation is not guaranteed to stricly follow the spec.
Note that this normalization algorithm is not compatible with RFC 3986 algorithm for some inputs.
Note that case normalization and percent-encoding normalization will still be applied to any path.
Examples
# use Error; # # Ok::# use Error; # # Ok::fn mask_password(self: &Self) -> PasswordMasked<'_, Self>Returns the proxy to the IRI with password masking feature.
Examples
# use Error; # # Ok::
impl<S: crate::spec::Spec> RiStr<S>
fn new(s: &str) -> Result<&Self, Error>Creates a new string.
unsafe fn new_unchecked(s: &str) -> &SelfCreates a new string without validation.
This does not validate the given string, so it is caller's responsibility to ensure the given string is valid.
Safety
The given string must be syntactically valid as
Selftype. If not, any use of the returned value or the call of this function itself may result in undefined behavior.fn as_str(self: &Self) -> &strReturns
&str.fn len(self: &Self) -> usizeReturns the string length.
fn is_empty(self: &Self) -> boolReturns whether the string is empty.
impl<S> Freeze for RiStr<S>
impl<S> RefUnwindSafe for RiStr<S>
impl<S> Send for RiStr<S>
impl<S> Sized for RiStr<S>
impl<S> Sync for RiStr<S>
impl<S> Unpin for RiStr<S>
impl<S> UnsafeUnpin for RiStr<S>
impl<S> UnwindSafe for RiStr<S>
impl<S: Spec> Buildable for RiStr<S>
impl<S: crate::spec::Spec> AsRef for RiStr<S>
fn as_ref(self: &Self) -> &str
impl<S: crate::spec::Spec> AsRef for RiStr<S>
fn as_ref(self: &Self) -> &RiStr<S>
impl<S: crate::spec::Spec> AsRef for RiStr<S>
fn as_ref(self: &Self) -> &RiReferenceStr<S>
impl<S: crate::spec::Spec> Debug for RiStr<S>
fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result
impl<S: crate::spec::Spec> Display for RiStr<S>
fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result
impl<S: crate::spec::Spec> Eq for RiStr<S>
impl<S: crate::spec::Spec> Hash for RiStr<S>
fn hash<H: core::hash::Hasher>(self: &Self, state: &mut H)
impl<S: crate::spec::Spec> Ord for RiStr<S>
fn cmp(self: &Self, other: &Self) -> Ordering
impl<S: crate::spec::Spec> PartialEq for RiStr<S>
fn eq(self: &Self, o: &Cow<'_, str>) -> bool
impl<S: crate::spec::Spec> PartialEq for RiStr<S>
fn eq(self: &Self, o: &&str) -> bool
impl<S: crate::spec::Spec> PartialEq for RiStr<S>
fn eq(self: &Self, o: &str) -> bool
impl<S: crate::spec::Spec> PartialEq for RiStr<S>
fn eq(self: &Self, other: &Self) -> bool
impl<S: crate::spec::Spec> PartialOrd for RiStr<S>
fn partial_cmp(self: &Self, o: &Cow<'_, str>) -> Option<Ordering>
impl<S: crate::spec::Spec> PartialOrd for RiStr<S>
fn partial_cmp(self: &Self, o: &&str) -> Option<Ordering>
impl<S: crate::spec::Spec> PartialOrd for RiStr<S>
fn partial_cmp(self: &Self, o: &str) -> Option<Ordering>
impl<S: crate::spec::Spec> PartialOrd for RiStr<S>
fn partial_cmp(self: &Self, other: &Self) -> Option<Ordering>
impl<S: crate::spec::Spec> ToOwned for RiStr<S>
fn to_owned(self: &Self) -> <Self as >::Owned
impl<S: crate::spec::Spec, T: crate::spec::Spec> PartialEq for RiStr<S>
fn eq(self: &Self, o: &RiReferenceString<T>) -> bool
impl<S: crate::spec::Spec, T: crate::spec::Spec> PartialEq for RiStr<S>
fn eq(self: &Self, o: &Cow<'_, RiReferenceStr<T>>) -> bool
impl<S: crate::spec::Spec, T: crate::spec::Spec> PartialEq for RiStr<S>
fn eq(self: &Self, o: &&RiReferenceStr<T>) -> bool
impl<S: crate::spec::Spec, T: crate::spec::Spec> PartialEq for RiStr<S>
fn eq(self: &Self, o: &RiReferenceStr<T>) -> bool
impl<S: crate::spec::Spec, T: crate::spec::Spec> PartialEq for RiStr<S>
fn eq(self: &Self, o: &RiString<T>) -> bool
impl<S: crate::spec::Spec, T: crate::spec::Spec> PartialEq for RiStr<T>
fn eq(self: &Self, o: &&RiStr<S>) -> bool
impl<S: crate::spec::Spec, T: crate::spec::Spec> PartialEq for RiStr<T>
fn eq(self: &Self, o: &RiAbsoluteString<S>) -> bool
impl<S: crate::spec::Spec, T: crate::spec::Spec> PartialEq for RiStr<T>
fn eq(self: &Self, o: &Cow<'_, RiAbsoluteStr<S>>) -> bool
impl<S: crate::spec::Spec, T: crate::spec::Spec> PartialEq for RiStr<T>
fn eq(self: &Self, o: &&RiAbsoluteStr<S>) -> bool
impl<S: crate::spec::Spec, T: crate::spec::Spec> PartialEq for RiStr<T>
fn eq(self: &Self, o: &RiAbsoluteStr<S>) -> bool
impl<S: crate::spec::Spec, T: crate::spec::Spec> PartialOrd for RiStr<S>
fn partial_cmp(self: &Self, o: &RiString<T>) -> Option<Ordering>
impl<S: crate::spec::Spec, T: crate::spec::Spec> PartialOrd for RiStr<S>
fn partial_cmp(self: &Self, o: &RiReferenceString<T>) -> Option<Ordering>
impl<S: crate::spec::Spec, T: crate::spec::Spec> PartialOrd for RiStr<S>
fn partial_cmp(self: &Self, o: &Cow<'_, RiReferenceStr<T>>) -> Option<Ordering>
impl<S: crate::spec::Spec, T: crate::spec::Spec> PartialOrd for RiStr<S>
fn partial_cmp(self: &Self, o: &&RiReferenceStr<T>) -> Option<Ordering>
impl<S: crate::spec::Spec, T: crate::spec::Spec> PartialOrd for RiStr<S>
fn partial_cmp(self: &Self, o: &RiReferenceStr<T>) -> Option<Ordering>
impl<S: crate::spec::Spec, T: crate::spec::Spec> PartialOrd for RiStr<T>
fn partial_cmp(self: &Self, o: &RiAbsoluteString<S>) -> Option<Ordering>
impl<S: crate::spec::Spec, T: crate::spec::Spec> PartialOrd for RiStr<T>
fn partial_cmp(self: &Self, o: &Cow<'_, RiAbsoluteStr<S>>) -> Option<Ordering>
impl<S: crate::spec::Spec, T: crate::spec::Spec> PartialOrd for RiStr<T>
fn partial_cmp(self: &Self, o: &&RiAbsoluteStr<S>) -> Option<Ordering>
impl<S: crate::spec::Spec, T: crate::spec::Spec> PartialOrd for RiStr<T>
fn partial_cmp(self: &Self, o: &RiAbsoluteStr<S>) -> Option<Ordering>
impl<S: crate::spec::Spec, T: crate::spec::Spec> PartialOrd for RiStr<T>
fn partial_cmp(self: &Self, o: &&RiStr<S>) -> Option<Ordering>
impl<T> Any for RiStr<S>
fn type_id(self: &Self) -> TypeId
impl<T> Borrow for RiStr<S>
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for RiStr<S>
fn borrow_mut(self: &mut Self) -> &mut T
impl<T> ToString for RiStr<S>
fn to_string(self: &Self) -> String