iri_string::types

Type Alias IriFragmentStr

source
pub type IriFragmentStr = RiFragmentStr<IriSpec>;
Expand description

A type alias for RiFragmentStr<IriSpec>.

Aliased Type§

struct IriFragmentStr { /* private fields */ }

Implementations§

source§

impl IriFragmentStr

Conversion from an IRI into a URI.

source

pub fn encode_to_uri(&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 type.

§Examples
use iri_string::format::ToDedicatedString;
use iri_string::types::{IriFragmentStr, UriFragmentString};

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

pub fn as_uri(&self) -> Option<&UriFragmentStr>

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

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

§Examples
use iri_string::types::{IriFragmentStr, UriFragmentStr};

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

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