pub struct RiQueryString<S> { /* private fields */ }
alloc
only.Expand description
An owned string of an IRI fragment (i.e. after the first #
character).
This corresponds to iquery
rule in RFC 3987 (and query
rule in RFC 3986).
The rule for absolute-IRI
is *( ipchar / iprivate / "/" / "?" )
.
For details, see the documentation for RiQueryStr
.
Enabled by alloc
or std
feature.
Implementations§
source§impl<S: Spec> RiQueryString<S>
impl<S: Spec> RiQueryString<S>
sourcepub unsafe fn new_unchecked(s: String) -> Self
pub unsafe fn new_unchecked(s: String) -> 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.
sourcepub fn shrink_to_fit(&mut self)
pub fn shrink_to_fit(&mut self)
Shrinks the capacity of the inner buffer to match its length.
sourcepub fn as_slice(&self) -> &RiQueryStr<S>
pub fn as_slice(&self) -> &RiQueryStr<S>
Returns the borrowed IRI string slice.
This is equivalent to &*self
.
source§impl RiQueryString<IriSpec>
impl RiQueryString<IriSpec>
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::IriQueryString;
let mut iri = IriQueryString::try_from("alpha-is-\u{03B1}")?;
iri.encode_to_uri_inline();
assert_eq!(iri, "alpha-is-%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::IriQueryString;
let mut iri = IriQueryString::try_from("alpha-is-\u{03B1}")?;
iri.try_encode_to_uri_inline()
.expect("failed to allocate memory");
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 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::{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_encode_into_uri(self) -> Result<UriQueryString, TryReserveError>
pub fn try_encode_into_uri(self) -> Result<UriQueryString, 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::{IriQueryString, UriQueryString};
let iri = IriQueryString::try_from("alpha-is-\u{03B1}")?;
// Type annotation here is not necessary.
let uri: UriQueryString = iri.try_encode_into_uri()
.expect("failed to allocate memory");
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())
);
Methods from Deref<Target = RiQueryStr<S>>§
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<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> Clone for RiQueryString<S>
impl<S: Spec> Clone for RiQueryString<S>
source§impl<S: Spec> Debug for RiQueryString<S>
impl<S: Spec> Debug for RiQueryString<S>
source§impl<S: Spec> Deref for RiQueryString<S>
impl<S: Spec> Deref for RiQueryString<S>
source§type Target = RiQueryStr<S>
type Target = RiQueryStr<S>
source§fn deref(&self) -> &RiQueryStr<S>
fn deref(&self) -> &RiQueryStr<S>
source§impl<'de, S: Spec> Deserialize<'de> for RiQueryString<S>
Available on crate feature serde
only.
impl<'de, S: Spec> Deserialize<'de> for RiQueryString<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 RiQueryString<S>
impl<S: Spec> Display for RiQueryString<S>
source§impl<S: Spec> From<&RiQueryStr<S>> for RiQueryString<S>
impl<S: Spec> From<&RiQueryStr<S>> for RiQueryString<S>
source§fn from(s: &RiQueryStr<S>) -> Self
fn from(s: &RiQueryStr<S>) -> Self
source§impl<'a, S: Spec> From<&'a RiQueryString<S>> for MappedToUri<'a, RiQueryStr<S>>
impl<'a, S: Spec> From<&'a RiQueryString<S>> for MappedToUri<'a, RiQueryStr<S>>
source§fn from(iri: &'a RiQueryString<S>) -> Self
fn from(iri: &'a RiQueryString<S>) -> Self
source§impl<S: Spec> From<RiQueryString<S>> for Box<RiQueryStr<S>>
impl<S: Spec> From<RiQueryString<S>> for Box<RiQueryStr<S>>
source§fn from(s: RiQueryString<S>) -> Box<RiQueryStr<S>>
fn from(s: RiQueryString<S>) -> Box<RiQueryStr<S>>
source§impl<'a, S: Spec> From<RiQueryString<S>> for Cow<'a, RiQueryStr<S>>
impl<'a, S: Spec> From<RiQueryString<S>> for Cow<'a, RiQueryStr<S>>
source§fn from(s: RiQueryString<S>) -> Cow<'a, RiQueryStr<S>>
fn from(s: RiQueryString<S>) -> Cow<'a, RiQueryStr<S>>
source§impl<S: Spec> From<RiQueryString<S>> for String
impl<S: Spec> From<RiQueryString<S>> for String
source§fn from(s: RiQueryString<S>) -> Self
fn from(s: RiQueryString<S>) -> Self
source§impl From<RiQueryString<UriSpec>> for IriQueryString
impl From<RiQueryString<UriSpec>> for IriQueryString
source§fn from(uri: UriQueryString) -> Self
fn from(uri: UriQueryString) -> Self
source§impl<S: Spec> FromStr for RiQueryString<S>
impl<S: Spec> FromStr for RiQueryString<S>
source§impl<S: Spec> Hash for RiQueryString<S>
impl<S: Spec> Hash for RiQueryString<S>
source§impl<S: Spec> Ord for RiQueryString<S>
impl<S: Spec> Ord for RiQueryString<S>
source§impl<S: Spec, T: Spec> PartialEq<&RiQueryStr<S>> for RiQueryString<T>
impl<S: Spec, T: Spec> PartialEq<&RiQueryStr<S>> for RiQueryString<T>
source§impl<S: Spec, T: Spec> PartialEq<Cow<'_, RiQueryStr<S>>> for RiQueryString<T>
impl<S: Spec, T: Spec> PartialEq<Cow<'_, RiQueryStr<S>>> for RiQueryString<T>
source§impl<S: Spec, T: Spec> PartialEq<RiQueryStr<S>> for RiQueryString<T>
impl<S: Spec, T: Spec> PartialEq<RiQueryStr<S>> for RiQueryString<T>
source§impl<S: Spec, T: Spec> PartialEq<RiQueryString<T>> for &RiQueryStr<S>
impl<S: Spec, T: Spec> PartialEq<RiQueryString<T>> for &RiQueryStr<S>
source§impl<S: Spec, T: Spec> PartialEq<RiQueryString<T>> for Cow<'_, RiQueryStr<S>>
impl<S: Spec, T: Spec> PartialEq<RiQueryString<T>> for Cow<'_, RiQueryStr<S>>
source§impl<S: Spec, T: Spec> PartialEq<RiQueryString<T>> for RiQueryStr<S>
impl<S: Spec, T: Spec> PartialEq<RiQueryString<T>> for RiQueryStr<S>
source§impl<S: Spec, T: Spec> PartialEq<RiQueryString<T>> for RiQueryString<S>
impl<S: Spec, T: Spec> PartialEq<RiQueryString<T>> for RiQueryString<S>
source§impl<S: Spec, T: Spec> PartialOrd<&RiQueryStr<S>> for RiQueryString<T>
impl<S: Spec, T: Spec> PartialOrd<&RiQueryStr<S>> for RiQueryString<T>
source§impl<S: Spec> PartialOrd<&str> for RiQueryString<S>
impl<S: Spec> PartialOrd<&str> for RiQueryString<S>
source§impl<S: Spec, T: Spec> PartialOrd<Cow<'_, RiQueryStr<S>>> for RiQueryString<T>
impl<S: Spec, T: Spec> PartialOrd<Cow<'_, RiQueryStr<S>>> for RiQueryString<T>
source§impl<S: Spec> PartialOrd<Cow<'_, str>> for RiQueryString<S>
impl<S: Spec> PartialOrd<Cow<'_, str>> for RiQueryString<S>
source§impl<S: Spec, T: Spec> PartialOrd<RiQueryStr<S>> for RiQueryString<T>
impl<S: Spec, T: Spec> PartialOrd<RiQueryStr<S>> for RiQueryString<T>
source§impl<S: Spec> PartialOrd<RiQueryString<S>> for &str
impl<S: Spec> PartialOrd<RiQueryString<S>> for &str
source§impl<S: Spec> PartialOrd<RiQueryString<S>> for Cow<'_, str>
impl<S: Spec> PartialOrd<RiQueryString<S>> for Cow<'_, str>
source§impl<S: Spec> PartialOrd<RiQueryString<S>> for String
impl<S: Spec> PartialOrd<RiQueryString<S>> for String
source§impl<S: Spec> PartialOrd<RiQueryString<S>> for str
impl<S: Spec> PartialOrd<RiQueryString<S>> for str
source§impl<S: Spec, T: Spec> PartialOrd<RiQueryString<T>> for &RiQueryStr<S>
impl<S: Spec, T: Spec> PartialOrd<RiQueryString<T>> for &RiQueryStr<S>
source§impl<S: Spec, T: Spec> PartialOrd<RiQueryString<T>> for Cow<'_, RiQueryStr<S>>
impl<S: Spec, T: Spec> PartialOrd<RiQueryString<T>> for Cow<'_, RiQueryStr<S>>
source§impl<S: Spec, T: Spec> PartialOrd<RiQueryString<T>> for RiQueryStr<S>
impl<S: Spec, T: Spec> PartialOrd<RiQueryString<T>> for RiQueryStr<S>
source§impl<S: Spec, T: Spec> PartialOrd<RiQueryString<T>> for RiQueryString<S>
impl<S: Spec, T: Spec> PartialOrd<RiQueryString<T>> for RiQueryString<S>
source§impl<S: Spec> PartialOrd<String> for RiQueryString<S>
impl<S: Spec> PartialOrd<String> for RiQueryString<S>
source§impl<S: Spec> PartialOrd<str> for RiQueryString<S>
impl<S: Spec> PartialOrd<str> for RiQueryString<S>
source§impl<S> Serialize for RiQueryString<S>where
S: Spec,
impl<S> Serialize for RiQueryString<S>where
S: Spec,
impl<S: Spec> Eq for RiQueryString<S>
Auto Trait Implementations§
impl<S> Freeze for RiQueryString<S>
impl<S> RefUnwindSafe for RiQueryString<S>
impl<S> Send for RiQueryString<S>
impl<S> Sync for RiQueryString<S>
impl<S> Unpin for RiQueryString<S>
impl<S> UnwindSafe for RiQueryString<S>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
source§fn try_to_string(&self) -> Result<String, TryReserveError>
Available on crate feature alloc
only.
fn try_to_string(&self) -> Result<String, TryReserveError>
alloc
only.ToString::to_string
, but without panic on OOM.