Type Definition iri_string::types::IriQueryString
source · [−]pub type IriQueryString = RiQueryString<IriSpec>;
Expand description
A type alias for RiQueryString
<
IriSpec
>
.
Implementations
sourceimpl IriQueryString
impl IriQueryString
Conversion from an IRI into a URI.
sourcepub fn encode_to_uri(&mut self)
pub fn encode_to_uri(&mut self)
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::IriQueryString;
let mut iri = IriQueryString::try_from("alpha-is-\u{03B1}")?;
iri.encode_to_uri();
assert_eq!(iri, "alpha-is-%CE%B1");
sourcepub fn encode_into_uri(self) -> UriQueryString
pub fn encode_into_uri(self) -> UriQueryString
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::{IriQueryString, UriQueryString};
let iri = IriQueryString::try_from("alpha-is-\u{03B1}")?;
// Type annotation here is not necessary.
let uri: UriQueryString = iri.encode_into_uri();
assert_eq!(uri, "alpha-is-%CE%B1");
sourcepub fn try_into_uri(self) -> Result<UriQueryString, IriQueryString>
pub fn try_into_uri(self) -> Result<UriQueryString, IriQueryString>
Converts an IRI into a URI without modification, if possible.
Examples
use iri_string::types::{IriQueryString, UriQueryString};
let ascii_iri = IriQueryString::try_from("alpha-is-%CE%B1")?;
assert_eq!(
ascii_iri.try_into_uri().map(|uri| uri.to_string()),
Ok("alpha-is-%CE%B1".to_string())
);
let nonascii_iri = IriQueryString::try_from("alpha-is-\u{03B1}")?;
assert_eq!(
nonascii_iri.try_into_uri().map_err(|iri| iri.to_string()),
Err("alpha-is-\u{03B1}".to_string())
);
Trait Implementations
sourceimpl From<RiQueryString<UriSpec>> for IriQueryString
impl From<RiQueryString<UriSpec>> for IriQueryString
sourcefn from(uri: UriQueryString) -> Self
fn from(uri: UriQueryString) -> Self
Converts to this type from the input type.