pub type IriQueryStr = RiQueryStr<IriSpec>;
Expand description
A type alias for RiQueryStr
<
IriSpec
>
.
Aliased Type§
pub struct IriQueryStr { /* private fields */ }
Implementations§
Source§impl IriQueryStr
Conversion from an IRI into a URI.
impl IriQueryStr
Conversion from an IRI into a URI.
Sourcepub fn encode_to_uri(&self) -> MappedToUri<'_, Self>
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::{IriQueryStr, UriQueryString};
let iri = IriQueryStr::new("alpha-is-\u{03B1}")?;
// Type annotation here is not necessary.
let uri: UriQueryString = iri.encode_to_uri().to_dedicated_string();
assert_eq!(uri, "alpha-is-%CE%B1");
Sourcepub fn as_uri(&self) -> Option<&UriQueryStr>
pub fn as_uri(&self) -> Option<&UriQueryStr>
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);
Source§impl<S: Spec> RiQueryStr<S>
impl<S: Spec> RiQueryStr<S>
Sourcepub fn from_prefixed(s: &str) -> Result<&Self, Error>
pub fn from_prefixed(s: &str) -> Result<&Self, Error>
Creates a new &RiQueryStr
from the query part prefixed by ?
.
§Examples
assert!(IriQueryStr::from_prefixed("?").is_ok());
assert!(IriQueryStr::from_prefixed("?foo").is_ok());
assert!(IriQueryStr::from_prefixed("?foo/bar").is_ok());
assert!(IriQueryStr::from_prefixed("?/foo/bar").is_ok());
assert!(IriQueryStr::from_prefixed("?//foo/bar").is_ok());
assert!(IriQueryStr::from_prefixed("?https://user:pass@example.com:8080").is_ok());
assert!(IriQueryStr::from_prefixed("?https://example.com/").is_ok());
// Question sign `?` can appear in an IRI query.
assert!(IriQueryStr::from_prefixed("?query?again").is_ok());
// `<` and `>` cannot directly appear in an IRI.
assert!(IriQueryStr::from_prefixed("?<not allowed>").is_err());
// Broken percent encoding cannot appear in an IRI.
assert!(IriQueryStr::new("?%").is_err());
assert!(IriQueryStr::new("?%GG").is_err());
// `?` prefix is expected.
assert!(IriQueryStr::from_prefixed("").is_err());
assert!(IriQueryStr::from_prefixed("foo").is_err());
// Hash sign `#` cannot appear in an IRI query.
assert!(IriQueryStr::from_prefixed("?#hash").is_err());
Source§impl<S: Spec> RiQueryStr<S>
impl<S: Spec> RiQueryStr<S>
Sourcepub unsafe fn new_unchecked(s: &str) -> &Self
pub unsafe fn new_unchecked(s: &str) -> &Self
Creates a new string without validation.
This does not validate the given string, so it is caller’s responsibility to ensure the given string is valid.
§Safety
The given string must be syntactically valid as Self
type.
If not, any use of the returned value or the call of this
function itself may result in undefined behavior.