Struct RiFragmentStr

struct RiFragmentStr<S> { ... }

A borrowed slice 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 ifragment is *( ipchar / "/" / "?" ).

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());

Implementations

impl RiFragmentStr<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::{IriFragmentStr, UriFragmentString};

let iri = IriFragmentStr::new("alpha-is-\u{03B1}")?;
// Type annotation here is not necessary.
let uri: UriFragmentString = iri.encode_to_uri().to_dedicated_string();
assert_eq!(uri, "alpha-is-%CE%B1");
# }
# Ok::<_, Error>(())
fn as_uri(self: &Self) -> Option<&UriFragmentStr>

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

This is semantically equivalent to UriFragmentStr::new(self.as_str()).ok().

Examples

# use iri_string::validate::Error;
use iri_string::types::{IriFragmentStr, UriFragmentStr};

let ascii_iri = IriFragmentStr::new("alpha-is-%CE%B1")?;
assert_eq!(
    ascii_iri.as_uri().map(AsRef::as_ref),
    Some("alpha-is-%CE%B1")
);

let nonascii_iri = IriFragmentStr::new("alpha-is-\u{03B1}")?;
assert_eq!(nonascii_iri.as_uri(), None);
# Ok::<_, Error>(())

impl<S: Spec> RiFragmentStr<S>

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

Creates a new &RiFragmentStr from the fragment part prefixed by #.

Examples

# use iri_string::types::IriFragmentStr;
assert!(IriFragmentStr::from_prefixed("#").is_ok());
assert!(IriFragmentStr::from_prefixed("#foo").is_ok());
assert!(IriFragmentStr::from_prefixed("#foo/bar").is_ok());
assert!(IriFragmentStr::from_prefixed("#/foo/bar").is_ok());
assert!(IriFragmentStr::from_prefixed("#//foo/bar").is_ok());
assert!(IriFragmentStr::from_prefixed("#https://user:pass@example.com:8080").is_ok());
assert!(IriFragmentStr::from_prefixed("#https://example.com/").is_ok());

// `<` and `>` cannot directly appear in an IRI.
assert!(IriFragmentStr::from_prefixed("#<not allowed>").is_err());
// Broken percent encoding cannot appear in an IRI.
assert!(IriFragmentStr::new("#%").is_err());
assert!(IriFragmentStr::new("#%GG").is_err());
// `#` prefix is expected.
assert!(IriFragmentStr::from_prefixed("").is_err());
assert!(IriFragmentStr::from_prefixed("foo").is_err());
// Hash sign `#` cannot appear in an IRI fragment.
assert!(IriFragmentStr::from_prefixed("##hash").is_err());

impl<S: crate::spec::Spec> RiFragmentStr<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 RiFragmentStr<S>

impl<S> RefUnwindSafe for RiFragmentStr<S>

impl<S> Send for RiFragmentStr<S>

impl<S> Sized for RiFragmentStr<S>

impl<S> Sync for RiFragmentStr<S>

impl<S> Unpin for RiFragmentStr<S>

impl<S> UnsafeUnpin for RiFragmentStr<S>

impl<S> UnwindSafe for RiFragmentStr<S>

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

impl<T> Any for RiFragmentStr<S>

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for RiFragmentStr<S>

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

impl<T> BorrowMut for RiFragmentStr<S>

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

impl<T> ToString for RiFragmentStr<S>

fn to_string(self: &Self) -> String