Module types
URI and IRI types.
URI and IRI
IRIs (Internationalized Resource Identifiers) are defined in RFC 3987, and URIs (Uniform Resource Identifiers) are defined in RFC 3986.
URI consists of only ASCII characters, and is a subset of IRI.
IRIs are defined as below:
IRI = scheme ":" ihier-part [ "?" iquery ] [ "#" ifragment ]
IRI-reference = IRI / irelative-ref
absolute-IRI = scheme ":" ihier-part [ "?" iquery ]
irelative-ref = irelative-part [ "?" iquery ] [ "#" ifragment ]
(`irelative-part` is roughly same as `ihier-part`.)
Definitions for URIs are almost same, but they cannot have non-ASCII characters.
Types
Types can be categorized by:
- syntax,
- spec, and
- ownership.
Syntax
Since URIs and IRIs have almost same syntax and share algorithms, they are implemented by generic types.
RiStrandRiString- String types for
IRIandURIrules.
- String types for
RiAbsoluteStrandRiAbsoluteString- String types for
absolute-IRIandabsolute-URIrules.
- String types for
RiReferenceStrandRiReferenceString- String types for
IRI-referenceandURI-referencerules.
- String types for
RiRelativeStrandRiRelativeString- String types for
irelative-refandrelative-refrules.
- String types for
RiFragmentStrandRiFragmentString- String types for
ifragmentandfragmentrules. - Note that these types represents a substring of an IRI / URI references. They are not intended to used directly as an IRI / URI references.
- String types for
"Ri" stands for "Resource Identifier".
Spec
These types have a type parameter, which represents RFC specification.
IriSpec represents RFC 3987 spec, and UriSpec represents RFC 3986 spec.
For example, RiAbsoluteStr<IriSpec> can have absolute-IRI string value,
and RiReferenceStr<UriSpec> can have URI-reference string value.
Ownership
String-like types have usually two variations, borrowed and owned.
Borrowed types (such as str, Path, OsStr) are unsized, and used by reference style.
Owned types (such as String, PathBuf, OsString) are sized, and requires heap allocation.
Owned types can be coerced to a borrowed type (for example, &String is automatically coerced
to &str in many context).
IRI / URI types have same variations, RiFooStr and RiFooString
(Foo part represents syntax).
They are very similar to &str and String.
Deref is implemented, RiFooStr::len() is available, &RiFooString can be coerced to
&RiFooStr, Cow<'_, RiFooStr> and Box<RiFooStr> is available, and so on.
Hierarchy and safe conversion
IRI syntaxes have the hierarchy below.
RiReferenceStr
|-- RiStr
| `-- RiAbsoluteStr
`-- RiRelativeStr
Therefore, the conversions below are safe and cheap:
RiStr -> RiReferenceStrRiAbsoluteStr -> RiStrRiAbsoluteStr -> RiReferenceStrRiRelativeStr -> RiReferenceStr
For safely convertible types (consider FooStr -> BarStr is safe), traits
below are implemented:
AsRef<BarStr> for FooStrAsRef<BarStr> for FooStringFrom<FooString> for BarStringPartialEq<FooStr> for BarStr, and lots of impls like thatPartialEqandParitalOrd.- Slice, owned,
Cow, reference, etc...
Fallible conversions
Fallible conversions are implemented from plain string into IRI strings.
TryFrom<&str> for &FooStrTryFrom<&str> for FooStringTryFrom<String> for FooStringFromStr for FooString
Some IRI string types provide more convenient methods to convert between IRI types.
For example, RiReferenceString::into_iri() tries to convert an IRI reference into an IRI,
and returns Result<IriString, IriRelativeString>.
This is because an IRI reference is valid as an IRI or a relative IRI reference.
Such methods are usually more efficient than using TryFrom for plain strings, because they
prevents you from losing ownership of a string, and does a conversion without extra memory
allocation.
Aliases
This module contains type aliases for RFC 3986 URI types and RFC 3987 IRI types.
IriFooStr{,ing} are aliases of RiFooStr{,ing}<IriSpec>, and UriFooStr{,ing} are aliases
of RiFooStr{,ing}<UriSpec>.
Wrapped string types
Similar to string types in std (such as str, std::path::Path, and std::ffi::OsStr),
IRI string types in this crate provides convenient conversions to:
std::box::Box,std::borrow::Cow,std::rc::Rc, andstd::sync::Arc.
# use Error;
#
# Ok::
Structs
- CreationError Error on conversion into an IRI type.
- RiAbsoluteStr A borrowed slice of an absolute IRI without fragment part.
- RiAbsoluteString An owned string of an absolute IRI without fragment part.
-
RiFragmentStr
A borrowed slice of an IRI fragment (i.e. after the first
#character). -
RiFragmentString
An owned string of an IRI fragment (i.e. after the first
#character). -
RiQueryStr
A borrowed slice of an IRI query (i.e. after the first
?and before the first#). -
RiQueryString
An owned string of an IRI fragment (i.e. after the first
#character). - RiReferenceStr A borrowed string of an absolute IRI possibly with fragment part.
- RiReferenceString An owned string of an absolute IRI possibly with fragment part.
- RiRelativeStr A borrowed slice of a relative IRI reference.
- RiRelativeString An owned string of a relative IRI reference.
- RiStr A borrowed string of an absolute IRI possibly with fragment part.
- RiString An owned string of an absolute IRI possibly with fragment part.
Type Aliases
-
IriAbsoluteStr
A type alias for
RiAbsoluteStr<IriSpec>. -
IriAbsoluteString
A type alias for
RiAbsoluteString<IriSpec>. -
IriFragmentStr
A type alias for
RiFragmentStr<IriSpec>. -
IriFragmentString
A type alias for
RiFragmentString<IriSpec>. -
IriQueryStr
A type alias for
RiQueryStr<IriSpec>. -
IriQueryString
A type alias for
RiQueryString<IriSpec>. -
IriReferenceStr
A type alias for
RiReferenceStr<IriSpec>. -
IriReferenceString
A type alias for
RiReferenceString<IriSpec>. -
IriRelativeStr
A type alias for
RiRelativeStr<IriSpec>. -
IriRelativeString
A type alias for
RiRelativeString<IriSpec>. -
IriStr
A type alias for
RiStr<IriSpec>. -
IriString
A type alias for
RiString<IriSpec>. -
UriAbsoluteStr
A type alias for
RiAbsoluteStr<UriSpec>. -
UriAbsoluteString
A type alias for
RiAbsoluteString<UriSpec>. -
UriFragmentStr
A type alias for
RiFragmentStr<UriSpec>. -
UriFragmentString
A type alias for
RiFragmentString<UriSpec>. -
UriQueryStr
A type alias for
RiQueryStr<UriSpec>. -
UriQueryString
A type alias for
RiQueryString<UriSpec>. -
UriReferenceStr
A type alias for
RiReferenceStr<UriSpec>. -
UriReferenceString
A type alias for
RiReferenceString<UriSpec>. -
UriRelativeStr
A type alias for
RiRelativeStr<UriSpec>. -
UriRelativeString
A type alias for
RiRelativeString<UriSpec>. -
UriStr
A type alias for
RiStr<UriSpec>. -
UriString
A type alias for
RiString<UriSpec>.