Struct iri_string::types::RiFragmentString
source · pub struct RiFragmentString<S> { /* private fields */ }
Expand description
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§
source§impl<S: Spec> RiFragmentString<S>
impl<S: Spec> RiFragmentString<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) -> &RiFragmentStr<S>
pub fn as_slice(&self) -> &RiFragmentStr<S>
Returns the borrowed IRI string slice.
This is equivalent to &*self
.
source§impl RiFragmentString<IriSpec>
impl RiFragmentString<IriSpec>
Conversion from an IRI into a URI.
sourcepub fn encode_to_uri_inline(&mut self)
Available on crate feature alloc
only.
pub fn encode_to_uri_inline(&mut self)
alloc
only.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::IriFragmentString;
let mut iri = IriFragmentString::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>
Available on crate feature alloc
only.
pub fn try_encode_to_uri_inline(&mut self) -> Result<(), TryReserveError>
alloc
only.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::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");
sourcepub fn encode_into_uri(self) -> UriFragmentString
Available on crate feature alloc
only.
pub fn encode_into_uri(self) -> UriFragmentString
alloc
only.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::{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");
sourcepub fn try_encode_into_uri(self) -> Result<UriFragmentString, TryReserveError>
Available on crate feature alloc
only.
pub fn try_encode_into_uri(self) -> Result<UriFragmentString, TryReserveError>
alloc
only.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::{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");
sourcepub fn try_into_uri(self) -> Result<UriFragmentString, IriFragmentString>
Available on crate feature alloc
only.
pub fn try_into_uri(self) -> Result<UriFragmentString, IriFragmentString>
alloc
only.Converts an IRI into a URI without modification, if possible.
§Examples
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())
);
Methods from Deref<Target = RiFragmentStr<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::{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");
sourcepub fn as_uri(&self) -> Option<&UriFragmentStr>
pub fn as_uri(&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::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);
Trait Implementations§
source§impl<S: Spec> AsRef<RiFragmentStr<S>> for RiFragmentString<S>
impl<S: Spec> AsRef<RiFragmentStr<S>> for RiFragmentString<S>
source§fn as_ref(&self) -> &RiFragmentStr<S>
fn as_ref(&self) -> &RiFragmentStr<S>
source§impl<S: Spec> Borrow<RiFragmentStr<S>> for RiFragmentString<S>
impl<S: Spec> Borrow<RiFragmentStr<S>> for RiFragmentString<S>
source§fn borrow(&self) -> &RiFragmentStr<S>
fn borrow(&self) -> &RiFragmentStr<S>
source§impl<S: Spec> Clone for RiFragmentString<S>
impl<S: Spec> Clone for RiFragmentString<S>
source§impl<S: Spec> Debug for RiFragmentString<S>
impl<S: Spec> Debug for RiFragmentString<S>
source§impl<S: Spec> Deref for RiFragmentString<S>
impl<S: Spec> Deref for RiFragmentString<S>
§type Target = RiFragmentStr<S>
type Target = RiFragmentStr<S>
source§fn deref(&self) -> &RiFragmentStr<S>
fn deref(&self) -> &RiFragmentStr<S>
source§impl<'de, S: Spec> Deserialize<'de> for RiFragmentString<S>
Available on crate feature serde
only.
impl<'de, S: Spec> Deserialize<'de> for RiFragmentString<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 RiFragmentString<S>
impl<S: Spec> Display for RiFragmentString<S>
source§impl<S: Spec> From<&RiFragmentStr<S>> for RiFragmentString<S>
impl<S: Spec> From<&RiFragmentStr<S>> for RiFragmentString<S>
source§fn from(s: &RiFragmentStr<S>) -> Self
fn from(s: &RiFragmentStr<S>) -> Self
source§impl<'a, S: Spec> From<&'a RiFragmentString<S>> for MappedToUri<'a, RiFragmentStr<S>>
impl<'a, S: Spec> From<&'a RiFragmentString<S>> for MappedToUri<'a, RiFragmentStr<S>>
source§fn from(iri: &'a RiFragmentString<S>) -> Self
fn from(iri: &'a RiFragmentString<S>) -> Self
source§impl<S: Spec> From<RiFragmentString<S>> for Box<RiFragmentStr<S>>
impl<S: Spec> From<RiFragmentString<S>> for Box<RiFragmentStr<S>>
source§fn from(s: RiFragmentString<S>) -> Box<RiFragmentStr<S>>
fn from(s: RiFragmentString<S>) -> Box<RiFragmentStr<S>>
source§impl<'a, S: Spec> From<RiFragmentString<S>> for Cow<'a, RiFragmentStr<S>>
impl<'a, S: Spec> From<RiFragmentString<S>> for Cow<'a, RiFragmentStr<S>>
source§fn from(s: RiFragmentString<S>) -> Cow<'a, RiFragmentStr<S>>
fn from(s: RiFragmentString<S>) -> Cow<'a, RiFragmentStr<S>>
source§impl<S: Spec> From<RiFragmentString<S>> for String
impl<S: Spec> From<RiFragmentString<S>> for String
source§fn from(s: RiFragmentString<S>) -> Self
fn from(s: RiFragmentString<S>) -> Self
source§impl From<RiFragmentString<UriSpec>> for IriFragmentString
impl From<RiFragmentString<UriSpec>> for IriFragmentString
source§fn from(uri: UriFragmentString) -> Self
fn from(uri: UriFragmentString) -> Self
source§impl<S: Spec> FromStr for RiFragmentString<S>
impl<S: Spec> FromStr for RiFragmentString<S>
source§impl<S: Spec> Hash for RiFragmentString<S>
impl<S: Spec> Hash for RiFragmentString<S>
source§impl<S: Spec> Ord for RiFragmentString<S>
impl<S: Spec> Ord for RiFragmentString<S>
source§impl<S: Spec, T: Spec> PartialEq<&RiFragmentStr<S>> for RiFragmentString<T>
impl<S: Spec, T: Spec> PartialEq<&RiFragmentStr<S>> for RiFragmentString<T>
source§fn eq(&self, o: &&RiFragmentStr<S>) -> bool
fn eq(&self, o: &&RiFragmentStr<S>) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl<S: Spec, T: Spec> PartialEq<Cow<'_, RiFragmentStr<S>>> for RiFragmentString<T>
impl<S: Spec, T: Spec> PartialEq<Cow<'_, RiFragmentStr<S>>> for RiFragmentString<T>
source§impl<S: Spec> PartialEq<Cow<'_, str>> for RiFragmentString<S>
impl<S: Spec> PartialEq<Cow<'_, str>> for RiFragmentString<S>
source§impl<S: Spec, T: Spec> PartialEq<RiFragmentStr<S>> for RiFragmentString<T>
impl<S: Spec, T: Spec> PartialEq<RiFragmentStr<S>> for RiFragmentString<T>
source§fn eq(&self, o: &RiFragmentStr<S>) -> bool
fn eq(&self, o: &RiFragmentStr<S>) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl<S: Spec> PartialEq<RiFragmentString<S>> for &str
impl<S: Spec> PartialEq<RiFragmentString<S>> for &str
source§fn eq(&self, o: &RiFragmentString<S>) -> bool
fn eq(&self, o: &RiFragmentString<S>) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl<S: Spec> PartialEq<RiFragmentString<S>> for Cow<'_, str>
impl<S: Spec> PartialEq<RiFragmentString<S>> for Cow<'_, str>
source§fn eq(&self, o: &RiFragmentString<S>) -> bool
fn eq(&self, o: &RiFragmentString<S>) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl<S: Spec> PartialEq<RiFragmentString<S>> for String
impl<S: Spec> PartialEq<RiFragmentString<S>> for String
source§fn eq(&self, o: &RiFragmentString<S>) -> bool
fn eq(&self, o: &RiFragmentString<S>) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl<S: Spec> PartialEq<RiFragmentString<S>> for str
impl<S: Spec> PartialEq<RiFragmentString<S>> for str
source§fn eq(&self, o: &RiFragmentString<S>) -> bool
fn eq(&self, o: &RiFragmentString<S>) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl<S: Spec, T: Spec> PartialEq<RiFragmentString<T>> for &RiFragmentStr<S>
impl<S: Spec, T: Spec> PartialEq<RiFragmentString<T>> for &RiFragmentStr<S>
source§fn eq(&self, o: &RiFragmentString<T>) -> bool
fn eq(&self, o: &RiFragmentString<T>) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl<S: Spec, T: Spec> PartialEq<RiFragmentString<T>> for Cow<'_, RiFragmentStr<S>>
impl<S: Spec, T: Spec> PartialEq<RiFragmentString<T>> for Cow<'_, RiFragmentStr<S>>
source§fn eq(&self, o: &RiFragmentString<T>) -> bool
fn eq(&self, o: &RiFragmentString<T>) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl<S: Spec, T: Spec> PartialEq<RiFragmentString<T>> for RiFragmentStr<S>
impl<S: Spec, T: Spec> PartialEq<RiFragmentString<T>> for RiFragmentStr<S>
source§fn eq(&self, o: &RiFragmentString<T>) -> bool
fn eq(&self, o: &RiFragmentString<T>) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl<S: Spec, T: Spec> PartialEq<RiFragmentString<T>> for RiFragmentString<S>
impl<S: Spec, T: Spec> PartialEq<RiFragmentString<T>> for RiFragmentString<S>
source§fn eq(&self, other: &RiFragmentString<T>) -> bool
fn eq(&self, other: &RiFragmentString<T>) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl<S: Spec, T: Spec> PartialOrd<&RiFragmentStr<S>> for RiFragmentString<T>
impl<S: Spec, T: Spec> PartialOrd<&RiFragmentStr<S>> for RiFragmentString<T>
source§fn partial_cmp(&self, o: &&RiFragmentStr<S>) -> Option<Ordering>
fn partial_cmp(&self, o: &&RiFragmentStr<S>) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl<S: Spec> PartialOrd<&str> for RiFragmentString<S>
impl<S: Spec> PartialOrd<&str> for RiFragmentString<S>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl<S: Spec, T: Spec> PartialOrd<Cow<'_, RiFragmentStr<S>>> for RiFragmentString<T>
impl<S: Spec, T: Spec> PartialOrd<Cow<'_, RiFragmentStr<S>>> for RiFragmentString<T>
source§fn partial_cmp(&self, o: &Cow<'_, RiFragmentStr<S>>) -> Option<Ordering>
fn partial_cmp(&self, o: &Cow<'_, RiFragmentStr<S>>) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl<S: Spec> PartialOrd<Cow<'_, str>> for RiFragmentString<S>
impl<S: Spec> PartialOrd<Cow<'_, str>> for RiFragmentString<S>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl<S: Spec, T: Spec> PartialOrd<RiFragmentStr<S>> for RiFragmentString<T>
impl<S: Spec, T: Spec> PartialOrd<RiFragmentStr<S>> for RiFragmentString<T>
source§fn partial_cmp(&self, o: &RiFragmentStr<S>) -> Option<Ordering>
fn partial_cmp(&self, o: &RiFragmentStr<S>) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl<S: Spec> PartialOrd<RiFragmentString<S>> for &str
impl<S: Spec> PartialOrd<RiFragmentString<S>> for &str
source§fn partial_cmp(&self, o: &RiFragmentString<S>) -> Option<Ordering>
fn partial_cmp(&self, o: &RiFragmentString<S>) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl<S: Spec> PartialOrd<RiFragmentString<S>> for Cow<'_, str>
impl<S: Spec> PartialOrd<RiFragmentString<S>> for Cow<'_, str>
source§fn partial_cmp(&self, o: &RiFragmentString<S>) -> Option<Ordering>
fn partial_cmp(&self, o: &RiFragmentString<S>) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl<S: Spec> PartialOrd<RiFragmentString<S>> for String
impl<S: Spec> PartialOrd<RiFragmentString<S>> for String
source§fn partial_cmp(&self, o: &RiFragmentString<S>) -> Option<Ordering>
fn partial_cmp(&self, o: &RiFragmentString<S>) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl<S: Spec> PartialOrd<RiFragmentString<S>> for str
impl<S: Spec> PartialOrd<RiFragmentString<S>> for str
source§fn partial_cmp(&self, o: &RiFragmentString<S>) -> Option<Ordering>
fn partial_cmp(&self, o: &RiFragmentString<S>) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl<S: Spec, T: Spec> PartialOrd<RiFragmentString<T>> for &RiFragmentStr<S>
impl<S: Spec, T: Spec> PartialOrd<RiFragmentString<T>> for &RiFragmentStr<S>
source§fn partial_cmp(&self, o: &RiFragmentString<T>) -> Option<Ordering>
fn partial_cmp(&self, o: &RiFragmentString<T>) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl<S: Spec, T: Spec> PartialOrd<RiFragmentString<T>> for Cow<'_, RiFragmentStr<S>>
impl<S: Spec, T: Spec> PartialOrd<RiFragmentString<T>> for Cow<'_, RiFragmentStr<S>>
source§fn partial_cmp(&self, o: &RiFragmentString<T>) -> Option<Ordering>
fn partial_cmp(&self, o: &RiFragmentString<T>) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl<S: Spec, T: Spec> PartialOrd<RiFragmentString<T>> for RiFragmentStr<S>
impl<S: Spec, T: Spec> PartialOrd<RiFragmentString<T>> for RiFragmentStr<S>
source§fn partial_cmp(&self, o: &RiFragmentString<T>) -> Option<Ordering>
fn partial_cmp(&self, o: &RiFragmentString<T>) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl<S: Spec, T: Spec> PartialOrd<RiFragmentString<T>> for RiFragmentString<S>
impl<S: Spec, T: Spec> PartialOrd<RiFragmentString<T>> for RiFragmentString<S>
source§fn partial_cmp(&self, other: &RiFragmentString<T>) -> Option<Ordering>
fn partial_cmp(&self, other: &RiFragmentString<T>) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl<S: Spec> PartialOrd<String> for RiFragmentString<S>
impl<S: Spec> PartialOrd<String> for RiFragmentString<S>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl<S: Spec> PartialOrd<str> for RiFragmentString<S>
impl<S: Spec> PartialOrd<str> for RiFragmentString<S>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl<S> Serialize for RiFragmentString<S>where
S: Spec,
impl<S> Serialize for RiFragmentString<S>where
S: Spec,
impl<S: Spec> Eq for RiFragmentString<S>
Auto Trait Implementations§
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> UnwindSafe for RiFragmentString<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> 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.