Type Definition iri_string::types::IriQueryStr

source · []
pub type IriQueryStr = RiQueryStr<IriSpec>;
Expand description

A type alias for RiQueryStr<IriSpec>.

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::{IriQueryStr, UriQueryString};

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

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

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

Examples
use iri_string::types::{IriQueryStr, UriQueryStr};

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

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