pub type IriRelativeString = RiRelativeString<IriSpec>;
alloc
only.Expand description
A type alias for RiRelativeString
<
IriSpec
>
.
Aliased Type§
pub struct IriRelativeString { /* private fields */ }
Implementations§
Source§impl IriRelativeString
Conversion from an IRI into a URI.
impl IriRelativeString
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::IriRelativeString;
let mut iri = IriRelativeString::try_from("../?alpha=\u{03B1}")?;
iri.encode_to_uri_inline();
assert_eq!(iri, "../?alpha=%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::IriRelativeString;
let mut iri = IriRelativeString::try_from("../?alpha=\u{03B1}")?;
iri.try_encode_to_uri_inline()
.expect("failed to allocate memory");
assert_eq!(iri, "../?alpha=%CE%B1");
Sourcepub fn encode_into_uri(self) -> UriRelativeString
pub fn encode_into_uri(self) -> UriRelativeString
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::{IriRelativeString, UriRelativeString};
let iri = IriRelativeString::try_from("../?alpha=\u{03B1}")?;
// Type annotation here is not necessary.
let uri: UriRelativeString = iri.encode_into_uri();
assert_eq!(uri, "../?alpha=%CE%B1");
Sourcepub fn try_encode_into_uri(self) -> Result<UriRelativeString, TryReserveError>
pub fn try_encode_into_uri(self) -> Result<UriRelativeString, 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::{IriRelativeString, UriRelativeString};
let iri = IriRelativeString::try_from("../?alpha=\u{03B1}")?;
// Type annotation here is not necessary.
let uri: UriRelativeString = iri.try_encode_into_uri()
.expect("failed to allocate memory");
assert_eq!(uri, "../?alpha=%CE%B1");
Sourcepub fn try_into_uri(self) -> Result<UriRelativeString, IriRelativeString>
pub fn try_into_uri(self) -> Result<UriRelativeString, IriRelativeString>
Converts an IRI into a URI without modification, if possible.
§Examples
use iri_string::types::{IriRelativeString, UriRelativeString};
let ascii_iri = IriRelativeString::try_from("../?alpha=%CE%B1")?;
assert_eq!(
ascii_iri.try_into_uri().map(|uri| uri.to_string()),
Ok("../?alpha=%CE%B1".to_string())
);
let nonascii_iri = IriRelativeString::try_from("../?alpha=\u{03B1}")?;
assert_eq!(
nonascii_iri.try_into_uri().map_err(|iri| iri.to_string()),
Err("../?alpha=\u{03B1}".to_string())
);
Source§impl<S: Spec> RiRelativeString<S>
impl<S: Spec> RiRelativeString<S>
Sourcepub fn set_fragment(&mut self, fragment: Option<&RiFragmentStr<S>>)
pub fn set_fragment(&mut self, fragment: Option<&RiFragmentStr<S>>)
Sets the fragment part to the given string.
Removes fragment part (and following #
character) if None
is given.
§Examples
use iri_string::types::{IriFragmentStr, IriRelativeString};
let mut iri = IriRelativeString::try_from("//user:password@example.com/path?query#frag.old")?;
assert_eq!(iri.fragment_str(), Some("frag.old"));
iri.set_fragment(None);
assert_eq!(iri.fragment(), None);
let frag_new = IriFragmentStr::new("frag-new")?;
iri.set_fragment(Some(frag_new));
assert_eq!(iri.fragment_str(), Some("frag-new"));
Fragment can be empty, and it is distinguished from the absense of a fragment.
use iri_string::types::IriRelativeString;
let mut iri = IriRelativeString::try_from("/path#")?;
assert_eq!(iri, "/path#");
assert_eq!(iri.fragment_str(), Some(""), "Fragment is present and empty");
iri.set_fragment(None);
assert_eq!(iri, "/path", "Note that # is now removed");
assert_eq!(iri.fragment_str(), None, "Fragment is absent");
Sourcepub fn remove_password_inline(&mut self)
pub fn remove_password_inline(&mut self)
Removes the password completely (including separator colon) from self
even if it is empty.
§Examples
use iri_string::types::IriRelativeString;
let mut iri = IriRelativeString::try_from("//user:password@example.com/path?query")?;
iri.remove_password_inline();
assert_eq!(iri, "//user@example.com/path?query");
Even if the password is empty, the password and separator will be removed.
use iri_string::types::IriRelativeString;
let mut iri = IriRelativeString::try_from("//user:@example.com/path?query")?;
iri.remove_password_inline();
assert_eq!(iri, "//user@example.com/path?query");
Sourcepub fn remove_nonempty_password_inline(&mut self)
pub fn remove_nonempty_password_inline(&mut self)
Replaces the non-empty password in self
to the empty password.
This leaves the separator colon if the password part was available.
§Examples
use iri_string::types::IriRelativeString;
let mut iri = IriRelativeString::try_from("//user:password@example.com/path?query")?;
iri.remove_nonempty_password_inline();
assert_eq!(iri, "//user:@example.com/path?query");
If the password is empty, it is left as is.
use iri_string::types::IriRelativeString;
let mut iri = IriRelativeString::try_from("//user:@example.com/path?query")?;
iri.remove_nonempty_password_inline();
assert_eq!(iri, "//user:@example.com/path?query");
Source§impl<S: Spec> RiRelativeString<S>
impl<S: Spec> RiRelativeString<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) -> &RiRelativeStr<S>
pub fn as_slice(&self) -> &RiRelativeStr<S>
Returns the borrowed IRI string slice.
This is equivalent to &*self
.
Trait Implementations§
Source§impl From<RiRelativeString<UriSpec>> for IriRelativeString
impl From<RiRelativeString<UriSpec>> for IriRelativeString
Source§fn from(uri: UriRelativeString) -> Self
fn from(uri: UriRelativeString) -> Self
Source§impl<S: Spec> AsRef<RiReferenceStr<S>> for RiRelativeString<S>
impl<S: Spec> AsRef<RiReferenceStr<S>> for RiRelativeString<S>
Source§fn as_ref(&self) -> &RiReferenceStr<S>
fn as_ref(&self) -> &RiReferenceStr<S>
Source§impl<S: Spec> AsRef<RiRelativeStr<S>> for RiRelativeString<S>
impl<S: Spec> AsRef<RiRelativeStr<S>> for RiRelativeString<S>
Source§fn as_ref(&self) -> &RiRelativeStr<S>
fn as_ref(&self) -> &RiRelativeStr<S>
Source§impl<S: Spec> Borrow<RiRelativeStr<S>> for RiRelativeString<S>
impl<S: Spec> Borrow<RiRelativeStr<S>> for RiRelativeString<S>
Source§fn borrow(&self) -> &RiRelativeStr<S>
fn borrow(&self) -> &RiRelativeStr<S>
Source§impl<S: Spec> Clone for RiRelativeString<S>
impl<S: Spec> Clone for RiRelativeString<S>
Source§impl<S: Spec> Debug for RiRelativeString<S>
impl<S: Spec> Debug for RiRelativeString<S>
Source§impl<S: Spec> Deref for RiRelativeString<S>
impl<S: Spec> Deref for RiRelativeString<S>
Source§type Target = RiRelativeStr<S>
type Target = RiRelativeStr<S>
Source§fn deref(&self) -> &RiRelativeStr<S>
fn deref(&self) -> &RiRelativeStr<S>
Source§impl<'de, S: Spec> Deserialize<'de> for RiRelativeString<S>
Available on crate feature serde
only.
impl<'de, S: Spec> Deserialize<'de> for RiRelativeString<S>
serde
only.