iri_string::resolve

Struct FixedBaseResolver

source
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>

source

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");
source

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>

Components getters.

These getters are more efficient than calling through the result of .base().

source

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");
source

pub fn authority_str(&self) -> Option<&str>

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"));
source

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/");
source

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

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>

source

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>

source§

fn clone(&self) -> FixedBaseResolver<'a, S>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'a, S: Debug + Spec> Debug for FixedBaseResolver<'a, S>

source§

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

Formats the value using the given formatter. Read more
source§

impl<'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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.