Type Definition iri_string::types::IriStr
source · [−]Expand description
A borrowed string type for an IRI.
Implementations
sourceimpl IriStr
impl IriStr
Conversion from an IRI into a URI.
sourcepub fn encode_to_uri(&self) -> UriString
pub fn encode_to_uri(&self) -> UriString
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::{IriStr, UriString};
let iri = IriStr::new("http://example.com/?alpha=\u{03B1}")?;
// Type annotation here is not necessary.
let uri: UriString = iri.encode_to_uri();
assert_eq!(uri, "http://example.com/?alpha=%CE%B1");
sourcepub fn as_uri(&self) -> Option<&UriStr>
pub fn as_uri(&self) -> Option<&UriStr>
Converts an IRI into a URI without modification, if possible.
This is semantically equivalent to
UriStr::new(self.as_str()).ok()
.
Examples
use iri_string::types::{IriStr, UriStr};
let ascii_iri = IriStr::new("http://example.com/?alpha=%CE%B1")?;
assert_eq!(
ascii_iri.as_uri().map(AsRef::as_ref),
Some("http://example.com/?alpha=%CE%B1")
);
let nonascii_iri = IriStr::new("http://example.com/?alpha=\u{03B1}")?;
assert_eq!(nonascii_iri.as_uri(), None);