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

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.