pub struct ServiceURI(/* private fields */);Methods from Deref<Target = UriAbsoluteStr>§
Sourcepub fn ensure_rfc3986_normalizable(&self) -> Result<(), Error>
pub fn ensure_rfc3986_normalizable(&self) -> Result<(), Error>
Returns Ok(()) if the IRI is normalizable by the RFC 3986 algorithm.
§Examples
use iri_string::types::IriAbsoluteStr;
let iri = IriAbsoluteStr::new("HTTP://example.COM/foo/%2e/bar/..")?;
assert!(iri.ensure_rfc3986_normalizable().is_ok());
let iri2 = IriAbsoluteStr::new("scheme:/..//bar")?;
// The normalization result would be `scheme://bar` according to RFC
// 3986, but it is unintended and should be treated as a failure.
// This crate automatically handles this case so that `.normalize()` won't fail.
assert!(!iri.ensure_rfc3986_normalizable().is_err());Sourcepub fn is_normalized(&self) -> bool
pub fn is_normalized(&self) -> bool
Returns true if the IRI is already normalized.
This returns the same result as self.normalize().to_string() == self,
but does this more efficiently without heap allocation.
§Examples
use iri_string::format::ToDedicatedString;
use iri_string::types::IriAbsoluteStr;
let iri = IriAbsoluteStr::new("HTTP://example.COM/foo/./bar/%2e%2e/../baz?query")?;
assert!(!iri.is_normalized());
let normalized = iri.normalize().to_dedicated_string();
assert_eq!(normalized, "http://example.com/baz?query");
assert!(normalized.is_normalized());use iri_string::format::ToDedicatedString;
use iri_string::types::IriAbsoluteStr;
let iri = IriAbsoluteStr::new("scheme:/.///foo")?;
// Already normalized.
assert!(iri.is_normalized());use iri_string::format::ToDedicatedString;
use iri_string::types::IriAbsoluteStr;
let iri = IriAbsoluteStr::new("scheme:relative/..//not-a-host")?;
// Default normalization algorithm assumes the path part to be NOT opaque.
assert!(!iri.is_normalized());
let normalized = iri.normalize().to_dedicated_string();
assert_eq!(normalized, "scheme:/.//not-a-host");Sourcepub fn is_normalized_rfc3986(&self) -> bool
pub fn is_normalized_rfc3986(&self) -> bool
Returns true if the IRI is already normalized.
This returns the same result as
self.ensure_rfc3986_normalizable() && (self.normalize().to_string() == self),
does this more efficiently without heap allocation.
§Examples
use iri_string::format::ToDedicatedString;
use iri_string::types::IriAbsoluteStr;
let iri = IriAbsoluteStr::new("HTTP://example.COM/foo/./bar/%2e%2e/../baz?query")?;
assert!(!iri.is_normalized_rfc3986());
let normalized = iri.normalize().to_dedicated_string();
assert_eq!(normalized, "http://example.com/baz?query");
assert!(normalized.is_normalized_rfc3986());use iri_string::format::ToDedicatedString;
use iri_string::types::IriAbsoluteStr;
let iri = IriAbsoluteStr::new("scheme:/.///foo")?;
// Not normalized in the sense of RFC 3986.
assert!(!iri.is_normalized_rfc3986());use iri_string::format::ToDedicatedString;
use iri_string::types::IriAbsoluteStr;
let iri = IriAbsoluteStr::new("scheme:relative/..//not-a-host")?;
// RFC 3986 normalization algorithm assumes the path part to be NOT opaque.
assert!(!iri.is_normalized_rfc3986());
let normalized = iri.normalize().to_dedicated_string();
assert_eq!(normalized, "scheme:/.//not-a-host");Returns true if the IRI is already normalized in the sense of
normalize_but_preserve_authorityless_relative_path method.
This returns the same result as
self.normalize_but_preserve_authorityless_relative_path().to_string() == self,
but does this more efficiently without heap allocation.
§Examples
use iri_string::format::ToDedicatedString;
use iri_string::types::IriAbsoluteStr;
let iri = IriAbsoluteStr::new("HTTP://example.COM/foo/./bar/%2e%2e/../baz?query")?;
assert!(!iri.is_normalized_but_authorityless_relative_path_preserved());
let normalized = iri
.normalize_but_preserve_authorityless_relative_path()
.to_dedicated_string();
assert_eq!(normalized, "http://example.com/baz?query");
assert!(normalized.is_normalized());use iri_string::format::ToDedicatedString;
use iri_string::types::IriAbsoluteStr;
let iri = IriAbsoluteStr::new("scheme:/.///foo")?;
// Already normalized in the sense of
// `normalize_but_opaque_authorityless_relative_path()` method.
assert!(iri.is_normalized_but_authorityless_relative_path_preserved());use iri_string::format::ToDedicatedString;
use iri_string::types::IriAbsoluteStr;
let iri = IriAbsoluteStr::new("scheme:relative/..//not-a-host")?;
// Relative path is treated as opaque since the autority component is absent.
assert!(iri.is_normalized_but_authorityless_relative_path_preserved());Sourcepub fn normalize(&self) -> Normalized<'_, RiAbsoluteStr<S>>
pub fn normalize(&self) -> Normalized<'_, RiAbsoluteStr<S>>
Returns the normalized IRI.
§Notes
For some abnormal IRIs, the normalization can produce semantically incorrect string that looks syntactically valid. To avoid security issues by this trap, the normalization algorithm by this crate automatically applies the workaround.
If you worry about this, test by
RiAbsoluteStr::ensure_rfc3986_normalizable method or
Normalized::ensure_rfc3986_normalizable before using the result
string.
§Examples
use iri_string::format::ToDedicatedString;
use iri_string::types::IriAbsoluteStr;
let iri = IriAbsoluteStr::new("HTTP://example.COM/foo/./bar/%2e%2e/../baz?query")?;
let normalized = iri.normalize().to_dedicated_string();
assert_eq!(normalized, "http://example.com/baz?query");Returns the normalized IRI, but preserving dot segments in relative path if the authority component is absent.
This normalization would be similar to that of WHATWG URL Standard while this implementation is not guaranteed to stricly follow the spec.
Note that this normalization algorithm is not compatible with RFC 3986 algorithm for some inputs.
Note that case normalization and percent-encoding normalization will still be applied to any path.
§Examples
use iri_string::format::ToDedicatedString;
use iri_string::types::IriAbsoluteStr;
let iri = IriAbsoluteStr::new("HTTP://example.COM/foo/./bar/%2e%2e/../baz?query")?;
let normalized = iri
.normalize_but_preserve_authorityless_relative_path()
.to_dedicated_string();
assert_eq!(normalized, "http://example.com/baz?query");use iri_string::format::ToDedicatedString;
use iri_string::types::IriAbsoluteStr;
let iri = IriAbsoluteStr::new("scheme:relative/../f%6f%6f")?;
let normalized = iri
.normalize_but_preserve_authorityless_relative_path()
.to_dedicated_string();
assert_eq!(normalized, "scheme:relative/../foo");
// `.normalize()` would normalize this to `scheme:/foo`.Sourcepub fn mask_password(&self) -> PasswordMasked<'_, RiAbsoluteStr<S>>
pub fn mask_password(&self) -> PasswordMasked<'_, RiAbsoluteStr<S>>
Returns the proxy to the IRI with password masking feature.
§Examples
use iri_string::format::ToDedicatedString;
use iri_string::types::IriAbsoluteStr;
let iri = IriAbsoluteStr::new("http://user:password@example.com/path?query")?;
let masked = iri.mask_password();
assert_eq!(masked.to_dedicated_string(), "http://user:@example.com/path?query");
assert_eq!(
masked.replace_password("${password}").to_string(),
"http://user:${password}@example.com/path?query"
);Sourcepub fn scheme_str(&self) -> &str
pub fn scheme_str(&self) -> &str
Returns the scheme.
The following colon is truncated.
§Examples
use iri_string::types::IriAbsoluteStr;
let iri = IriAbsoluteStr::new("http://example.com/pathpath?queryquery")?;
assert_eq!(iri.scheme_str(), "http");Returns the authority.
The leading // is truncated.
§Examples
use iri_string::types::IriAbsoluteStr;
let iri = IriAbsoluteStr::new("http://example.com/pathpath?queryquery")?;
assert_eq!(iri.authority_str(), Some("example.com"));use iri_string::types::IriAbsoluteStr;
let iri = IriAbsoluteStr::new("urn:uuid:10db315b-fcd1-4428-aca8-15babc9a2da2")?;
assert_eq!(iri.authority_str(), None);Sourcepub fn path_str(&self) -> &str
pub fn path_str(&self) -> &str
Returns the path.
§Examples
use iri_string::types::IriAbsoluteStr;
let iri = IriAbsoluteStr::new("http://example.com/pathpath?queryquery")?;
assert_eq!(iri.path_str(), "/pathpath");use iri_string::types::IriAbsoluteStr;
let iri = IriAbsoluteStr::new("urn:uuid:10db315b-fcd1-4428-aca8-15babc9a2da2")?;
assert_eq!(iri.path_str(), "uuid:10db315b-fcd1-4428-aca8-15babc9a2da2");Sourcepub fn query(&self) -> Option<&RiQueryStr<S>>
pub fn query(&self) -> Option<&RiQueryStr<S>>
Returns the query.
The leading question mark (?) is truncated.
§Examples
use iri_string::types::{IriAbsoluteStr, IriQueryStr};
let iri = IriAbsoluteStr::new("http://example.com/pathpath?queryquery")?;
let query = IriQueryStr::new("queryquery")?;
assert_eq!(iri.query(), Some(query));use iri_string::types::IriAbsoluteStr;
let iri = IriAbsoluteStr::new("urn:uuid:10db315b-fcd1-4428-aca8-15babc9a2da2")?;
assert_eq!(iri.query(), None);Sourcepub fn query_str(&self) -> Option<&str>
pub fn query_str(&self) -> Option<&str>
Returns the query in a raw string slice.
The leading question mark (?) is truncated.
§Examples
use iri_string::types::IriAbsoluteStr;
let iri = IriAbsoluteStr::new("http://example.com/pathpath?queryquery")?;
assert_eq!(iri.query_str(), Some("queryquery"));use iri_string::types::IriAbsoluteStr;
let iri = IriAbsoluteStr::new("urn:uuid:10db315b-fcd1-4428-aca8-15babc9a2da2")?;
assert_eq!(iri.query_str(), None);Returns the authority components.
§Examples
use iri_string::types::IriAbsoluteStr;
let iri = IriAbsoluteStr::new("http://user:pass@example.com:8080/pathpath?queryquery")?;
let authority = iri.authority_components()
.expect("authority is available");
assert_eq!(authority.userinfo(), Some("user:pass"));
assert_eq!(authority.host(), "example.com");
assert_eq!(authority.port(), Some("8080"));use iri_string::types::IriAbsoluteStr;
let iri = IriAbsoluteStr::new("urn:uuid:10db315b-fcd1-4428-aca8-15babc9a2da2")?;
assert_eq!(iri.authority_str(), None);Sourcepub fn encode_to_uri(&self) -> MappedToUri<'_, RiAbsoluteStr<IriSpec>>
pub fn encode_to_uri(&self) -> MappedToUri<'_, RiAbsoluteStr<IriSpec>>
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::{IriAbsoluteStr, UriAbsoluteString};
let iri = IriAbsoluteStr::new("http://example.com/?alpha=\u{03B1}")?;
// Type annotation here is not necessary.
let uri: UriAbsoluteString = iri.encode_to_uri().to_dedicated_string();
assert_eq!(uri, "http://example.com/?alpha=%CE%B1");Sourcepub fn as_uri(&self) -> Option<&RiAbsoluteStr<UriSpec>>
pub fn as_uri(&self) -> Option<&RiAbsoluteStr<UriSpec>>
Converts an IRI into a URI without modification, if possible.
This is semantically equivalent to
UriAbsoluteStr::new(self.as_str()).ok().
§Examples
use iri_string::types::{IriAbsoluteStr, UriAbsoluteStr};
let ascii_iri = IriAbsoluteStr::new("http://example.com/?alpha=%CE%B1")?;
assert_eq!(
ascii_iri.as_uri().map(AsRef::as_ref),
Some("http://example.com/?alpha=%CE%B1")
);
let nonascii_iri = IriAbsoluteStr::new("http://example.com/?alpha=\u{03B1}")?;
assert_eq!(nonascii_iri.as_uri(), None);Trait Implementations§
Source§impl Clone for ServiceURI
impl Clone for ServiceURI
Source§fn clone(&self) -> ServiceURI
fn clone(&self) -> ServiceURI
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ServiceURI
impl Debug for ServiceURI
Auto Trait Implementations§
impl Freeze for ServiceURI
impl RefUnwindSafe for ServiceURI
impl Send for ServiceURI
impl Sync for ServiceURI
impl Unpin for ServiceURI
impl UnwindSafe for ServiceURI
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);Source§impl<T, P> Patch<Box<P>> for Twhere
T: Patch<P>,
impl<T, P> Patch<Box<P>> for Twhere
T: Patch<P>,
Source§fn into_patch(self) -> Box<P>
fn into_patch(self) -> Box<P>
SelfSource§fn into_patch_by_diff(self, previous_struct: T) -> Box<P>
fn into_patch_by_diff(self, previous_struct: T) -> Box<P>
previous_struct into Self