Struct RiFragmentString

struct RiFragmentString<S> { ... }

An owned string of an IRI fragment (i.e. after the first # character).

This corresponds to ifragment rule in RFC 3987 (and fragment rule in RFC 3986). The rule for absolute-IRI is *( ipchar / "/" / "?" ).

For details, see the documentation for RiFragmentStr.

Enabled by alloc or std feature.

Implementations

impl RiFragmentString<IriSpec>

fn encode_to_uri_inline(self: &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]IriFragmentStr::encode_to_uri method.

Panics

Panics if the memory allocation failed.

Examples

# use iri_string::validate::Error;
#[cfg(feature = "alloc")] {
use iri_string::types::IriFragmentString;

let mut iri = IriFragmentString::try_from("alpha-is-\u{03B1}")?;
iri.encode_to_uri_inline();
assert_eq!(iri, "alpha-is-%CE%B1");
# }
# Ok::<_, Error>(())
fn try_encode_to_uri_inline(self: &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]IriFragmentStr::encode_to_uri method.

Examples

# use iri_string::validate::Error;
#[cfg(feature = "alloc")] {
use iri_string::types::IriFragmentString;

let mut iri = IriFragmentString::try_from("alpha-is-\u{03B1}")?;
iri.try_encode_to_uri_inline()
    .expect("failed to allocate memory");
assert_eq!(iri, "alpha-is-%CE%B1");
# }
# Ok::<_, Error>(())
fn encode_into_uri(self: Self) -> UriFragmentString

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]IriFragmentStr::encode_to_uri method.

Examples

# use iri_string::validate::Error;
#[cfg(feature = "alloc")] {
use iri_string::types::{IriFragmentString, UriFragmentString};

let iri = IriFragmentString::try_from("alpha-is-\u{03B1}")?;
// Type annotation here is not necessary.
let uri: UriFragmentString = iri.encode_into_uri();
assert_eq!(uri, "alpha-is-%CE%B1");
# }
# Ok::<_, Error>(())
fn try_encode_into_uri(self: Self) -> Result<UriFragmentString, 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]IriFragmentStr::encode_to_uri method.

Examples

# use iri_string::validate::Error;
#[cfg(feature = "alloc")] {
use iri_string::types::{IriFragmentString, UriFragmentString};

let iri = IriFragmentString::try_from("alpha-is-\u{03B1}")?;
// Type annotation here is not necessary.
let uri: UriFragmentString = iri.try_encode_into_uri()
    .expect("failed to allocate memory");
assert_eq!(uri, "alpha-is-%CE%B1");
# }
# Ok::<_, Error>(())
fn try_into_uri(self: Self) -> Result<UriFragmentString, IriFragmentString>

Converts an IRI into a URI without modification, if possible.

Examples

# use iri_string::validate::Error;
use iri_string::types::{IriFragmentString, UriFragmentString};

let ascii_iri = IriFragmentString::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 = IriFragmentString::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())
);
# Ok::<_, Error>(())

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

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.

fn shrink_to_fit(self: &mut Self)

Shrinks the capacity of the inner buffer to match its length.

fn capacity(self: &Self) -> usize

Returns the internal buffer capacity in bytes.

fn as_slice(self: &Self) -> &RiFragmentStr<S>

Returns the borrowed IRI string slice.

This is equivalent to &*self.

impl<P, T> Receiver for RiFragmentString<S>

impl<S> Freeze for RiFragmentString<S>

impl<S> RefUnwindSafe for RiFragmentString<S>

impl<S> Send for RiFragmentString<S>

impl<S> Sync for RiFragmentString<S>

impl<S> Unpin for RiFragmentString<S>

impl<S> UnsafeUnpin for RiFragmentString<S>

impl<S> UnwindSafe for RiFragmentString<S>

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

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

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

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

impl<S: crate::spec::Spec> Borrow for RiFragmentString<S>

fn borrow(self: &Self) -> &RiFragmentStr<S>

impl<S: crate::spec::Spec> Borrow for RiFragmentString<S>

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

impl<S: crate::spec::Spec> Clone for RiFragmentString<S>

fn clone(self: &Self) -> Self

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

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

impl<S: crate::spec::Spec> Deref for RiFragmentString<S>

fn deref(self: &Self) -> &RiFragmentStr<S>

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

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

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

impl<S: crate::spec::Spec> From for RiFragmentString<S>

fn from(s: &RiFragmentStr<S>) -> Self

impl<S: crate::spec::Spec> FromStr for RiFragmentString<S>

fn from_str(s: &str) -> Result<Self, <Self as >::Err>

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

impl<S: crate::spec::Spec> TryFrom for RiFragmentString<S>

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

impl<S: crate::spec::Spec> TryFrom for RiFragmentString<S>

fn try_from(bytes: &[u8]) -> Result<Self, <Self as >::Error>

impl<S: crate::spec::Spec> TryFrom for RiFragmentString<S>

fn try_from(s: String) -> Result<Self, <Self as >::Error>

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

impl<T> Any for RiFragmentString<S>

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for RiFragmentString<S>

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

impl<T> BorrowMut for RiFragmentString<S>

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

impl<T> CloneToUninit for RiFragmentString<S>

unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)

impl<T> From for RiFragmentString<S>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> ToOwned for RiFragmentString<S>

fn to_owned(self: &Self) -> T
fn clone_into(self: &Self, target: &mut T)

impl<T> ToString for RiFragmentString<S>

fn to_string(self: &Self) -> String

impl<T> ToStringFallible for RiFragmentString<S>

fn try_to_string(self: &Self) -> Result<String, TryReserveError>

[ToString::to_string]alloc::string::ToString::to_string, but without panic on OOM.

impl<T, U> Into for RiFragmentString<S>

fn into(self: Self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom for RiFragmentString<S>

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

impl<T, U> TryInto for RiFragmentString<S>

fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>