pub type IriAbsoluteString = RiAbsoluteString<IriSpec>;
alloc
only.Expand description
A type alias for RiAbsoluteString
<
IriSpec
>
.
Aliased Type§
struct IriAbsoluteString { /* private fields */ }
Implementations§
source§impl IriAbsoluteString
impl IriAbsoluteString
Conversion from an IRI into a URI.
sourcepub fn encode_to_uri_inline(&mut self)
pub fn encode_to_uri_inline(&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, or if you need more precise control over memory
allocation and buffer handling, use
encode_to_uri
method.
§Panics
Panics if the memory allocation failed.
§Examples
#[cfg(feature = "alloc")] {
use iri_string::types::IriAbsoluteString;
let mut iri = IriAbsoluteString::try_from("http://example.com/?alpha=\u{03B1}")?;
iri.encode_to_uri_inline();
assert_eq!(iri, "http://example.com/?alpha=%CE%B1");
sourcepub fn try_encode_to_uri_inline(&mut self) -> Result<(), TryReserveError>
pub fn try_encode_to_uri_inline(&mut self) -> Result<(), TryReserveError>
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, or if you need more precise control over memory
allocation and buffer handling, use
encode_to_uri
method.
§Examples
#[cfg(feature = "alloc")] {
use iri_string::types::IriAbsoluteString;
let mut iri = IriAbsoluteString::try_from("http://example.com/?alpha=\u{03B1}")?;
iri.try_encode_to_uri_inline()
.expect("failed to allocate memory");
assert_eq!(iri, "http://example.com/?alpha=%CE%B1");
sourcepub fn encode_into_uri(self) -> UriAbsoluteString
pub fn encode_into_uri(self) -> UriAbsoluteString
Percent-encodes the IRI into a valid URI that identifies the equivalent resource.
If you want a new URI string rather than modifying the IRI
string, or if you need more precise control over memory
allocation and buffer handling, use
encode_to_uri
method.
§Examples
#[cfg(feature = "alloc")] {
use iri_string::types::{IriAbsoluteString, UriAbsoluteString};
let iri = IriAbsoluteString::try_from("http://example.com/?alpha=\u{03B1}")?;
// Type annotation here is not necessary.
let uri: UriAbsoluteString = iri.encode_into_uri();
assert_eq!(uri, "http://example.com/?alpha=%CE%B1");
sourcepub fn try_encode_into_uri(self) -> Result<UriAbsoluteString, TryReserveError>
pub fn try_encode_into_uri(self) -> Result<UriAbsoluteString, TryReserveError>
Percent-encodes the IRI into a valid URI that identifies the equivalent resource.
If you want a new URI string rather than modifying the IRI
string, or if you need more precise control over memory
allocation and buffer handling, use
encode_to_uri
method.
§Examples
#[cfg(feature = "alloc")] {
use iri_string::types::{IriAbsoluteString, UriAbsoluteString};
let iri = IriAbsoluteString::try_from("http://example.com/?alpha=\u{03B1}")?;
// Type annotation here is not necessary.
let uri: UriAbsoluteString = iri.try_encode_into_uri()
.expect("failed to allocate memory");
assert_eq!(uri, "http://example.com/?alpha=%CE%B1");
sourcepub fn try_into_uri(self) -> Result<UriAbsoluteString, IriAbsoluteString>
pub fn try_into_uri(self) -> Result<UriAbsoluteString, IriAbsoluteString>
Converts an IRI into a URI without modification, if possible.
§Examples
use iri_string::types::{IriAbsoluteString, UriAbsoluteString};
let ascii_iri = IriAbsoluteString::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 = IriAbsoluteString::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())
);