pub struct FixedBaseResolver<'a, S: Spec> { /* private fields */ }
Expand description
A resolver against the fixed base.
Implementations§
source§impl<'a, S: Spec> FixedBaseResolver<'a, S>
impl<'a, S: Spec> FixedBaseResolver<'a, S>
sourcepub fn new(base: &'a RiAbsoluteStr<S>) -> Self
pub fn new(base: &'a RiAbsoluteStr<S>) -> Self
Creates a new resolver with the given base.
§Examples
#[cfg(feature = "alloc")] {
use iri_string::format::ToDedicatedString;
use iri_string::resolve::FixedBaseResolver;
use iri_string::types::{IriAbsoluteStr, IriReferenceStr};
let base = IriAbsoluteStr::new("http://example.com/base/")?;
let resolver = FixedBaseResolver::new(base);
let reference = IriReferenceStr::new("../there")?;
let resolved = resolver.resolve(reference);
assert_eq!(resolved.to_dedicated_string(), "http://example.com/there");
sourcepub fn base(&self) -> &'a RiAbsoluteStr<S>
pub fn base(&self) -> &'a RiAbsoluteStr<S>
Returns the base.
§Examples
use iri_string::resolve::FixedBaseResolver;
use iri_string::types::{IriAbsoluteStr, IriReferenceStr};
let base = IriAbsoluteStr::new("http://example.com/base/")?;
let resolver = FixedBaseResolver::new(base);
assert_eq!(resolver.base(), base);
source§impl<'a, S: Spec> FixedBaseResolver<'a, S>
impl<'a, S: Spec> FixedBaseResolver<'a, S>
Components getters.
These getters are more efficient than calling through the result of .base()
.
sourcepub fn scheme_str(&self) -> &str
pub fn scheme_str(&self) -> &str
Returns the scheme.
The following colon is truncated.
§Examples
use iri_string::resolve::FixedBaseResolver;
use iri_string::types::IriAbsoluteStr;
let base = IriAbsoluteStr::new("http://example.com/base/?query")?;
let resolver = FixedBaseResolver::new(base);
assert_eq!(resolver.scheme_str(), "http");
assert_eq!(base.scheme_str(), "http");
Returns the authority.
The leading //
is truncated.
§Examples
use iri_string::resolve::FixedBaseResolver;
use iri_string::types::IriAbsoluteStr;
let base = IriAbsoluteStr::new("http://user:pass@example.com/base/?query")?;
let resolver = FixedBaseResolver::new(base);
assert_eq!(resolver.authority_str(), Some("user:pass@example.com"));
assert_eq!(base.authority_str(), Some("user:pass@example.com"));
sourcepub fn path_str(&self) -> &str
pub fn path_str(&self) -> &str
Returns the path.
§Examples
use iri_string::resolve::FixedBaseResolver;
use iri_string::types::IriAbsoluteStr;
let base = IriAbsoluteStr::new("http://user:pass@example.com/base/?query")?;
let resolver = FixedBaseResolver::new(base);
assert_eq!(resolver.path_str(), "/base/");
assert_eq!(base.path_str(), "/base/");
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::resolve::FixedBaseResolver;
use iri_string::types::{IriAbsoluteStr, IriQueryStr};
let base = IriAbsoluteStr::new("http://user:pass@example.com/base/?query")?;
let resolver = FixedBaseResolver::new(base);
let query = IriQueryStr::new("query")?;
assert_eq!(resolver.query(), Some(query));
assert_eq!(base.query(), Some(query));
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::resolve::FixedBaseResolver;
use iri_string::types::IriAbsoluteStr;
let base = IriAbsoluteStr::new("http://user:pass@example.com/base/?query")?;
let resolver = FixedBaseResolver::new(base);
assert_eq!(resolver.query_str(), Some("query"));
assert_eq!(base.query_str(), Some("query"));
source§impl<'a, S: Spec> FixedBaseResolver<'a, S>
impl<'a, S: Spec> FixedBaseResolver<'a, S>
sourcepub fn resolve(
&self,
reference: &'a RiReferenceStr<S>,
) -> Normalized<'a, RiStr<S>>
pub fn resolve( &self, reference: &'a RiReferenceStr<S>, ) -> Normalized<'a, RiStr<S>>
Resolves the given reference against the fixed base.
The task returned by this method does not normalize the resolution
result. However, ..
and .
are recognized even when they are
percent-encoded.
§Failures
This function itself does not fail, but resolution algorithm defined by RFC 3986 can fail. In that case, serialization algorithm defined by WHATWG URL Standard would be automatically applied.
See the documentation of Normalized
.
§Examples
use iri_string::format::ToDedicatedString;
use iri_string::resolve::FixedBaseResolver;
use iri_string::types::{IriAbsoluteStr, IriReferenceStr};
let base = IriAbsoluteStr::new("http://example.com/base/")?;
let resolver = FixedBaseResolver::new(base);
let reference = IriReferenceStr::new("../there")?;
let resolved = resolver.resolve(reference);
assert_eq!(resolved.to_dedicated_string(), "http://example.com/there");
Note that ..
and .
path segments are recognized even when they are
percent-encoded.
use iri_string::format::ToDedicatedString;
use iri_string::resolve::FixedBaseResolver;
use iri_string::types::{IriAbsoluteStr, IriReferenceStr};
let base = IriAbsoluteStr::new("HTTP://example.COM/base/base2/")?;
let resolver = FixedBaseResolver::new(base);
// `%2e%2e` is recognized as `..`.
// However, `dot%2edot` is NOT normalized into `dot.dot`.
let reference = IriReferenceStr::new("%2e%2e/../dot%2edot")?;
let resolved = resolver.resolve(reference);
// Resolved but not normalized.
assert_eq!(resolved.to_dedicated_string(), "HTTP://example.COM/dot%2edot");
Trait Implementations§
source§impl<'a, S: Clone + Spec> Clone for FixedBaseResolver<'a, S>
impl<'a, S: Clone + Spec> Clone for FixedBaseResolver<'a, S>
source§fn clone(&self) -> FixedBaseResolver<'a, S>
fn clone(&self) -> FixedBaseResolver<'a, S>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreimpl<'a, S: Copy + Spec> Copy for FixedBaseResolver<'a, S>
Auto Trait Implementations§
impl<'a, S> Freeze for FixedBaseResolver<'a, S>
impl<'a, S> RefUnwindSafe for FixedBaseResolver<'a, S>
impl<'a, S> Send for FixedBaseResolver<'a, S>
impl<'a, S> Sync for FixedBaseResolver<'a, S>
impl<'a, S> Unpin for FixedBaseResolver<'a, S>
impl<'a, S> UnwindSafe for FixedBaseResolver<'a, 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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)