Struct RiQueryStr

struct RiQueryStr<S> { ... }

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.

# use iri_string::types::IriFragmentStr;
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.

# use iri_string::types::IriFragmentStr;
// `<` 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

impl RiQueryStr<IriSpec>

fn encode_to_uri(self: &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]crate::convert::MappedToUri type.

Examples

# use iri_string::validate::Error;
# #[cfg(feature = "alloc")] {
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");
# }
# Ok::<_, Error>(())
fn as_uri(self: &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::validate::Error;
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);
# Ok::<_, Error>(())

impl<S: Spec> RiQueryStr<S>

fn from_prefixed(s: &str) -> Result<&Self, Error>

Creates a new &RiQueryStr from the query part prefixed by ?.

Examples

# use iri_string::types::IriQueryStr;
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());

impl<S: crate::spec::Spec> RiQueryStr<S>

fn new(s: &str) -> Result<&Self, Error>

Creates a new string.

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.

fn as_str(self: &Self) -> &str

Returns &str.

fn len(self: &Self) -> usize

Returns the string length.

fn is_empty(self: &Self) -> bool

Returns whether the string is empty.

impl<S> Freeze for RiQueryStr<S>

impl<S> RefUnwindSafe for RiQueryStr<S>

impl<S> Send for RiQueryStr<S>

impl<S> Sized for RiQueryStr<S>

impl<S> Sync for RiQueryStr<S>

impl<S> Unpin for RiQueryStr<S>

impl<S> UnsafeUnpin for RiQueryStr<S>

impl<S> UnwindSafe for RiQueryStr<S>

impl<S: crate::spec::Spec> AsRef for RiQueryStr<S>

fn as_ref(self: &Self) -> &RiQueryStr<S>

impl<S: crate::spec::Spec> AsRef for RiQueryStr<S>

fn as_ref(self: &Self) -> &str

impl<S: crate::spec::Spec> Debug for RiQueryStr<S>

fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result

impl<S: crate::spec::Spec> Display for RiQueryStr<S>

fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result

impl<S: crate::spec::Spec> Eq for RiQueryStr<S>

impl<S: crate::spec::Spec> Hash for RiQueryStr<S>

fn hash<H: core::hash::Hasher>(self: &Self, state: &mut H)

impl<S: crate::spec::Spec> Ord for RiQueryStr<S>

fn cmp(self: &Self, other: &Self) -> Ordering

impl<S: crate::spec::Spec> PartialEq for RiQueryStr<S>

fn eq(self: &Self, other: &Self) -> bool

impl<S: crate::spec::Spec> PartialEq for RiQueryStr<S>

fn eq(self: &Self, o: &Cow<'_, str>) -> bool

impl<S: crate::spec::Spec> PartialEq for RiQueryStr<S>

fn eq(self: &Self, o: &&str) -> bool

impl<S: crate::spec::Spec> PartialEq for RiQueryStr<S>

fn eq(self: &Self, o: &str) -> bool

impl<S: crate::spec::Spec> PartialOrd for RiQueryStr<S>

fn partial_cmp(self: &Self, o: &Cow<'_, str>) -> Option<Ordering>

impl<S: crate::spec::Spec> PartialOrd for RiQueryStr<S>

fn partial_cmp(self: &Self, o: &&str) -> Option<Ordering>

impl<S: crate::spec::Spec> PartialOrd for RiQueryStr<S>

fn partial_cmp(self: &Self, o: &str) -> Option<Ordering>

impl<S: crate::spec::Spec> PartialOrd for RiQueryStr<S>

fn partial_cmp(self: &Self, other: &Self) -> Option<Ordering>

impl<S: crate::spec::Spec> ToOwned for RiQueryStr<S>

fn to_owned(self: &Self) -> <Self as >::Owned

impl<S: crate::spec::Spec, T: crate::spec::Spec> PartialEq for RiQueryStr<S>

fn eq(self: &Self, o: &RiQueryString<T>) -> bool

impl<S: crate::spec::Spec, T: crate::spec::Spec> PartialEq for RiQueryStr<T>

fn eq(self: &Self, o: &&RiQueryStr<S>) -> bool

impl<S: crate::spec::Spec, T: crate::spec::Spec> PartialOrd for RiQueryStr<S>

fn partial_cmp(self: &Self, o: &RiQueryString<T>) -> Option<Ordering>

impl<S: crate::spec::Spec, T: crate::spec::Spec> PartialOrd for RiQueryStr<T>

fn partial_cmp(self: &Self, o: &&RiQueryStr<S>) -> Option<Ordering>

impl<T> Any for RiQueryStr<S>

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for RiQueryStr<S>

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for RiQueryStr<S>

fn borrow_mut(self: &mut Self) -> &mut T

impl<T> ToString for RiQueryStr<S>

fn to_string(self: &Self) -> String