pub struct RiQueryStr<S> { /* private fields */ }Expand description
A borrowed slice of an IRI query (i.e. after the first ? and before the first #).
This corresponds to iquery rule in RFC 3987 (and query rule in RFC 3986).
The rule for ifragment is *( ipchar / iprivate / "/" / "?" ).
§Valid values
This type can have an IRI fragment.
Note that the IRI foo://bar/baz#qux has the fragment qux, not #qux.
assert!(IriFragmentStr::new("").is_ok());
assert!(IriFragmentStr::new("foo").is_ok());
assert!(IriFragmentStr::new("foo/bar").is_ok());
assert!(IriFragmentStr::new("/foo/bar").is_ok());
assert!(IriFragmentStr::new("//foo/bar").is_ok());
assert!(IriFragmentStr::new("https://user:pass@example.com:8080").is_ok());
assert!(IriFragmentStr::new("https://example.com/").is_ok());Some characters and sequences cannot used in a fragment.
// `<` and `>` cannot directly appear in an IRI reference.
assert!(IriFragmentStr::new("<not allowed>").is_err());
// Broken percent encoding cannot appear in an IRI reference.
assert!(IriFragmentStr::new("%").is_err());
assert!(IriFragmentStr::new("%GG").is_err());
// Hash sign `#` cannot appear in an IRI fragment.
assert!(IriFragmentStr::new("#hash").is_err());use iri_string::types::IriQueryStr;
assert!(IriQueryStr::new("").is_ok());
assert!(IriQueryStr::new("foo").is_ok());
assert!(IriQueryStr::new("foo/bar").is_ok());
assert!(IriQueryStr::new("/foo/bar").is_ok());
assert!(IriQueryStr::new("//foo/bar").is_ok());
assert!(IriQueryStr::new("https://user:pass@example.com:8080").is_ok());
assert!(IriQueryStr::new("https://example.com/").is_ok());
// Question sign `?` can appear in an IRI query.
assert!(IriQueryStr::new("query?again").is_ok());Some characters and sequences cannot used in a query.
use iri_string::types::IriQueryStr;
// `<` and `>` cannot directly appear in an IRI reference.
assert!(IriQueryStr::new("<not allowed>").is_err());
// Broken percent encoding cannot appear in an IRI reference.
assert!(IriQueryStr::new("%").is_err());
assert!(IriQueryStr::new("%GG").is_err());
// Hash sign `#` cannot appear in an IRI query.
assert!(IriQueryStr::new("#hash").is_err());Implementations§
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.
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 RiQueryStr<IriSpec>
Conversion from an IRI into a URI.
impl RiQueryStr<IriSpec>
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);Trait Implementations§
Source§impl AsRef<RiQueryStr<IriSpec>> for UriQueryStr
impl AsRef<RiQueryStr<IriSpec>> for UriQueryStr
Source§fn as_ref(&self) -> &IriQueryStr
fn as_ref(&self) -> &IriQueryStr
Source§impl AsRef<RiQueryStr<IriSpec>> for UriQueryString
Available on crate feature alloc only.
impl AsRef<RiQueryStr<IriSpec>> for UriQueryString
alloc only.Source§fn as_ref(&self) -> &IriQueryStr
fn as_ref(&self) -> &IriQueryStr
Source§impl<S: Spec> AsRef<RiQueryStr<S>> for RiQueryStr<S>
impl<S: Spec> AsRef<RiQueryStr<S>> for RiQueryStr<S>
Source§fn as_ref(&self) -> &RiQueryStr<S>
fn as_ref(&self) -> &RiQueryStr<S>
Source§impl<S: Spec> AsRef<RiQueryStr<S>> for RiQueryString<S>
impl<S: Spec> AsRef<RiQueryStr<S>> for RiQueryString<S>
Source§fn as_ref(&self) -> &RiQueryStr<S>
fn as_ref(&self) -> &RiQueryStr<S>
Source§impl<S: Spec> Borrow<RiQueryStr<S>> for RiQueryString<S>
impl<S: Spec> Borrow<RiQueryStr<S>> for RiQueryString<S>
Source§fn borrow(&self) -> &RiQueryStr<S>
fn borrow(&self) -> &RiQueryStr<S>
Source§impl<S: Spec> Debug for RiQueryStr<S>
impl<S: Spec> Debug for RiQueryStr<S>
Source§impl<'de: 'a, 'a, S: 'de + Spec> Deserialize<'de> for &'a RiQueryStr<S>
Available on crate feature serde only.
impl<'de: 'a, 'a, S: 'de + Spec> Deserialize<'de> for &'a RiQueryStr<S>
serde only.Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl<S: Spec> Display for RiQueryStr<S>
impl<S: Spec> Display for RiQueryStr<S>
Source§impl<'a, S: Spec> From<&'a RiQueryStr<S>> for &'a str
impl<'a, S: Spec> From<&'a RiQueryStr<S>> for &'a str
Source§fn from(s: &'a RiQueryStr<S>) -> &'a str
fn from(s: &'a RiQueryStr<S>) -> &'a str
Source§impl<S: Spec> From<&RiQueryStr<S>> for Arc<RiQueryStr<S>>
Available on crate feature alloc only.
impl<S: Spec> From<&RiQueryStr<S>> for Arc<RiQueryStr<S>>
alloc only.Source§fn from(s: &RiQueryStr<S>) -> Self
fn from(s: &RiQueryStr<S>) -> Self
Source§impl<S: Spec> From<&RiQueryStr<S>> for Box<RiQueryStr<S>>
Available on crate feature alloc only.
impl<S: Spec> From<&RiQueryStr<S>> for Box<RiQueryStr<S>>
alloc only.Source§fn from(s: &RiQueryStr<S>) -> Self
fn from(s: &RiQueryStr<S>) -> Self
Source§impl<'a, S: Spec> From<&'a RiQueryStr<S>> for Cow<'a, RiQueryStr<S>>
Available on crate feature alloc only.
impl<'a, S: Spec> From<&'a RiQueryStr<S>> for Cow<'a, RiQueryStr<S>>
alloc only.Source§fn from(s: &'a RiQueryStr<S>) -> Self
fn from(s: &'a RiQueryStr<S>) -> Self
Source§impl<'a, S: Spec> From<&'a RiQueryStr<S>> for MappedToUri<'a, RiQueryStr<S>>
impl<'a, S: Spec> From<&'a RiQueryStr<S>> for MappedToUri<'a, RiQueryStr<S>>
Source§fn from(iri: &'a RiQueryStr<S>) -> Self
fn from(iri: &'a RiQueryStr<S>) -> Self
Source§impl<S: Spec> From<&RiQueryStr<S>> for Rc<RiQueryStr<S>>
Available on crate feature alloc only.
impl<S: Spec> From<&RiQueryStr<S>> for Rc<RiQueryStr<S>>
alloc only.