pub type IriRelativeStr = RiRelativeStr<IriSpec>;
Expand description

A borrowed string type for a relative IRI reference.

Implementations

Conversion from an IRI into a URI.

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 type.

Examples
use iri_string::types::{IriRelativeStr, UriRelativeString};

let iri = IriRelativeStr::new("../?alpha=\u{03B1}")?;
// Type annotation here is not necessary.
let uri: UriRelativeString = iri.encode_to_uri();
assert_eq!(uri, "../?alpha=%CE%B1");

Converts an IRI into a URI without modification, if possible.

This is semantically equivalent to UriRelativeStr::new(self.as_str()).ok().

Examples
use iri_string::types::{IriRelativeStr, UriRelativeStr};

let ascii_iri = IriRelativeStr::new("../?alpha=%CE%B1")?;
assert_eq!(
    ascii_iri.as_uri().map(AsRef::as_ref),
    Some("../?alpha=%CE%B1")
);

let nonascii_iri = IriRelativeStr::new("../?alpha=\u{03B1}")?;
assert_eq!(nonascii_iri.as_uri(), None);