Struct iri_string::resolve::FixedBaseResolver
source · [−]pub struct FixedBaseResolver<'a, S: Spec> { /* private fields */ }Expand description
A resolver against the fixed base.
If you want more control over how to resolve the buffer, create
NormalizationTask by create_task or create_normalizing_task method.
Implementations
sourceimpl<'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
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.try_resolve(reference)?;
assert_eq!(resolved, "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);sourceimpl<'a, S: Spec> FixedBaseResolver<'a, S>
impl<'a, S: Spec> FixedBaseResolver<'a, S>
sourcepub fn try_resolve(
&self,
reference: &RiReferenceStr<S>
) -> Result<RiString<S>, TaskError<Error>>
pub fn try_resolve(
&self,
reference: &RiReferenceStr<S>
) -> Result<RiString<S>, TaskError<Error>>
Resolves the given reference against the fixed base.
Enabled by alloc or std feature.
The task returned by this method does not normalize the resolution
result. However, .. and . are recognized even when they are
percent-encoded.
Failures
This fails if
- memory allocation failed, or
- the IRI referernce is unresolvable against the base.
To see examples of unresolvable IRIs, visit the module documentation.
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);
let reference = IriReferenceStr::new("../there")?;
let resolved = resolver.try_resolve(reference)?;
assert_eq!(resolved, "http://example.com/there");Note that .. and . path segments are recognized even when they are
percent-encoded.
use iri_string::resolve::FixedBaseResolver;
use iri_string::task::ProcessAndWrite;
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 task = resolver.create_task(reference);
let resolved = task.allocate_and_write()?;
// Resolved but not normalized.
assert_eq!(resolved, "HTTP://example.COM/dot%2edot");sourcepub fn resolve(
&self,
reference: &RiReferenceStr<S>
) -> Result<RiString<S>, TaskError<Error>>
👎 Deprecated since 0.5.5: Use try_resolve() for non-panicking normalization
pub fn resolve(
&self,
reference: &RiReferenceStr<S>
) -> Result<RiString<S>, TaskError<Error>>
Use try_resolve() for non-panicking normalization
Resolves the given reference against the fixed base.
Enabled by alloc or std feature.
The task returned by this method does not normalize the resolution
result. However, .. and . are recognized even when they are
percent-encoded.
Failures
This fails if
- memory allocation failed, or
- the IRI referernce is unresolvable against the base.
To see examples of unresolvable IRIs, visit the module documentation.
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);
let reference = IriReferenceStr::new("../there")?;
let resolved = resolver.try_resolve(reference)?;
assert_eq!(resolved, "http://example.com/there");Note that .. and . path segments are recognized even when they are
percent-encoded.
use iri_string::resolve::FixedBaseResolver;
use iri_string::task::ProcessAndWrite;
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 task = resolver.create_task(reference);
let resolved = task.allocate_and_write()?;
// Resolved but not normalized.
assert_eq!(resolved, "HTTP://example.COM/dot%2edot");sourcepub fn try_resolve_normalize(
&self,
reference: &RiReferenceStr<S>
) -> Result<RiString<S>, TaskError<Error>>
pub fn try_resolve_normalize(
&self,
reference: &RiReferenceStr<S>
) -> Result<RiString<S>, TaskError<Error>>
Resolves the given reference against the fixed base, and normalizes the result.
Enabled by alloc or std feature.
The task returned by this method is normalized.
If you don’t want the result to be normalized, use create_task method.
Failures
This fails if
- memory allocation failed, or
- the IRI referernce is unresolvable against the base.
To see examples of unresolvable IRIs, visit the module documentation.
Examples
use iri_string::resolve::FixedBaseResolver;
use iri_string::task::ProcessAndWrite;
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 `..`.
let reference = IriReferenceStr::new("%2e%2e/../dot%2edot")?;
let task = resolver.create_normalizing_task(reference);
let resolved = task.allocate_and_write()?;
// Not only resolved, but also normalized.
assert_eq!(resolved, "http://example.com/dot.dot");sourcepub fn resolve_normalize(
&self,
reference: &RiReferenceStr<S>
) -> Result<RiString<S>, TaskError<Error>>
pub fn resolve_normalize(
&self,
reference: &RiReferenceStr<S>
) -> Result<RiString<S>, TaskError<Error>>
Resolves the given reference against the fixed base, and normalizes the result.
Enabled by alloc or std feature.
The task returned by this method is normalized.
If you don’t want the result to be normalized, use create_task method.
Failures
This fails if
- memory allocation failed, or
- the IRI referernce is unresolvable against the base.
To see examples of unresolvable IRIs, visit the module documentation.
Examples
use iri_string::resolve::FixedBaseResolver;
use iri_string::task::ProcessAndWrite;
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 `..`.
let reference = IriReferenceStr::new("%2e%2e/../dot%2edot")?;
let task = resolver.create_normalizing_task(reference);
let resolved = task.allocate_and_write()?;
// Not only resolved, but also normalized.
assert_eq!(resolved, "http://example.com/dot.dot");sourcepub fn create_task(
&self,
reference: &'a RiReferenceStr<S>
) -> NormalizationTask<'a, RiStr<S>>
pub fn create_task(
&self,
reference: &'a RiReferenceStr<S>
) -> NormalizationTask<'a, RiStr<S>>
Creates a resolution task.
The returned NormalizationTask allows you to resolve the IRI without
memory allocation, resolve to existing buffers, estimate required
memory size, etc. If you need more control than
resolve method, use this.
The task returned by this method does not normalize the resolution
result. However, note that .. and . is recognized even when they
are percent-encoded.
If you want to normalize the result, use
create_normalizing_task
method instead, or call NormalizationTask::enable_normalization for
the returned task.
If you want to avoid resolution failure by using resolution described in
WHATWG URL Standard, call
NormalizationTask::enable_whatwg_serialization for the returned task.
Examples
use iri_string::resolve::FixedBaseResolver;
use iri_string::task::ProcessAndWrite;
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 task = resolver.create_task(reference);
let resolved = task.allocate_and_write()?;
// Resolved but not normalized.
assert_eq!(resolved, "HTTP://example.COM/dot%2edot");sourcepub fn create_normalizing_task(
&self,
reference: &'a RiReferenceStr<S>
) -> NormalizationTask<'a, RiStr<S>>
pub fn create_normalizing_task(
&self,
reference: &'a RiReferenceStr<S>
) -> NormalizationTask<'a, RiStr<S>>
Creates a resolution task.
The returned NormalizationTask allows you to resolve the IRI without
memory allocation, resolve to existing buffers, estimate required
memory size, etc. If you need more control than
try_resolve_normalize method, use this.
The task returned by this method normalizes the resolution result.
If you don’t want to normalize the result, use
create_task instead.
If you want to avoid resolution and normalization failure by using
resolution described in WHATWG URL Standard, call
NormalizationTask::enable_whatwg_serialization for the returned task.
Examples
use iri_string::resolve::FixedBaseResolver;
use iri_string::task::ProcessAndWrite;
use iri_string::types::{IriAbsoluteStr, IriReferenceStr};
let base = IriAbsoluteStr::new("HTTP://example.COM/base/base2/")?;
let resolver = FixedBaseResolver::new(base);
let reference = IriReferenceStr::new("%2e%2e/../dot%2edot")?;
let task = resolver.create_normalizing_task(reference);
let resolved = task.allocate_and_write()?;
// Not only resolved, but also normalized.
assert_eq!(resolved, "http://example.com/dot.dot");Trait Implementations
sourceimpl<'a, S: Clone + Spec> Clone for FixedBaseResolver<'a, S>
impl<'a, S: Clone + Spec> Clone for FixedBaseResolver<'a, S>
sourcefn clone(&self) -> FixedBaseResolver<'a, S>
fn clone(&self) -> FixedBaseResolver<'a, S>
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source. Read more
sourceimpl<'a, S: Debug + Spec> Debug for FixedBaseResolver<'a, S>
impl<'a, S: Debug + Spec> Debug for FixedBaseResolver<'a, S>
impl<'a, S: Copy + Spec> Copy for FixedBaseResolver<'a, S>
Auto Trait Implementations
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more