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
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.resolve(reference)?;
assert_eq!(resolved, "http://example.com/there");
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.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::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");
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::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");
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 don’t want to normalize the result, use create_task
instead.
Examples
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 task = resolver.create_task(reference);
let resolved = task.allocate_and_write()?;
// Resolved but not normalized.
assert_eq!(resolved, "HTTP://example.COM/dot%2edot");
pub fn create_normalizing_task(
&self,
reference: &'a RiReferenceStr<S>
) -> NormalizationTask<'a, S>
pub fn create_normalizing_task(
&self,
reference: &'a RiReferenceStr<S>
) -> NormalizationTask<'a, 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_normalize
method, use this.
The task returned by this method normalizes the resolution result.
Examples
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);
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
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
Mutably borrows from an owned value. Read more