pub type IriReferenceString = RiReferenceString<IriSpec>;
Expand description

An owned string type for an IRI reference.

Implementations

Conversion from an IRI into a URI.

Percent-encodes the IRI into a valid URI that identifies the equivalent resource.

After the encode, the IRI is also a valid URI.

If you want a new URI string rather than modifying the IRI string, use encode_into_uri method.

If you need more precise control over memory allocation and buffer handling, use MappedToUri type.

Examples
#[cfg(feature = "alloc")] {
use iri_string::types::IriReferenceString;

let mut iri = IriReferenceString::try_from("http://example.com/?alpha=\u{03B1}")?;
iri.encode_to_uri();
assert_eq!(iri, "http://example.com/?alpha=%CE%B1");

Percent-encodes the IRI into a valid URI that identifies the equivalent resource.

If you want to modify the value rather than creating a new URI string, use encode_to_uri method.

If you need more precise control over memory allocation and buffer handling, use MappedToUri type.

Examples
#[cfg(feature = "alloc")] {
use iri_string::types::{IriReferenceString, UriReferenceString};

let iri = IriReferenceString::try_from("http://example.com/?alpha=\u{03B1}")?;
// Type annotation here is not necessary.
let uri: UriReferenceString = iri.encode_into_uri();
assert_eq!(uri, "http://example.com/?alpha=%CE%B1");

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

Examples
use iri_string::types::{IriReferenceString, UriReferenceString};

let ascii_iri = IriReferenceString::try_from("http://example.com/?alpha=%CE%B1")?;
assert_eq!(
    ascii_iri.try_into_uri().map(|uri| uri.to_string()),
    Ok("http://example.com/?alpha=%CE%B1".to_string())
);

let nonascii_iri = IriReferenceString::try_from("http://example.com/?alpha=\u{03B1}")?;
assert_eq!(
    nonascii_iri.try_into_uri().map_err(|iri| iri.to_string()),
    Err("http://example.com/?alpha=\u{03B1}".to_string())
);

Trait Implementations

Converts to this type from the input type.