pub struct NormalizationTask<'a, T: ?Sized> { /* private fields */ }
Expand description

IRI normalization/resolution task.

Most of the main functionalities are provided from ProcessAndWrite trait, so you may need to write use iri_string::task::ProcessAndWrite where you use this task type.

Implementations

Enables normalization for the task.

Enables WHATWG URL Standard serialization for the task.

Returns the estimated maximum size required for IRI normalization/resolution.

With a buffer of the returned size, IRI normalization/resolution would succeed without OOM error. The operation may succeed with smaller buffer than this function estimates, but it is not guaranteed.

Note that this is O(N) operation (where N is input length).

Examples
use iri_string::normalize::NormalizationTask;
use iri_string::task::ProcessAndWrite;
use iri_string::types::IriStr;

let iri = IriStr::new("HTTP://e%78ample%2ecom/a/../slash%2fslash/\u{03B1}%ce%b1%ff")?;
let task = NormalizationTask::from(iri);

let max_size = task.estimate_max_buf_size_for_resolution();
let mut buf = vec![0_u8; max_size];
let resolved = task.write_to_byte_slice(&mut buf[..])?;

assert_eq!(resolved, "http://example.com/slash%2Fslash/\u{03B1}\u{03B1}%FF");

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

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Processes the data, and writes it to the newly allocated buffer.

Failures

This fails if:

  • failed to allocate memory, or
  • failed to process data.

To see examples of unresolvable IRIs, visit the module documentation.

Examples
use iri_string::normalize::NormalizationTask;
use iri_string::task::ProcessAndWrite;
use iri_string::types::IriStr;

let iri = IriStr::new("HTTP://e%78ample%2ecom/a/../slash%2fslash/\u{03B1}%ce%b1%ff")?;
let task = NormalizationTask::from(iri);

assert_eq!(
    task.allocate_and_write()?,
    "http://example.com/slash%2Fslash/\u{03B1}\u{03B1}%FF"
);

Processes the data, and writes it to the given byte slice.

Failures

This fails if:

  • buffer is not large enough, or
  • failed to process data.

To see examples of unresolvable IRIs, visit the module documentation.

Examples
use iri_string::normalize::NormalizationTask;
use iri_string::task::ProcessAndWrite;
use iri_string::types::IriStr;

let iri = IriStr::new("HTTP://e%78ample%2ecom/a/../slash%2fslash/\u{03B1}%ce%b1%ff")?;
let task = NormalizationTask::from(iri);

// Long enough!
let mut buf = [0_u8; 128];
let normalized = task.write_to_byte_slice(&mut buf[..])?;

assert_eq!(normalized, "http://example.com/slash%2Fslash/\u{03B1}\u{03B1}%FF");

This returns error when the buffer is not long enough for processing. You can get maximum required buffer size by estimate_max_buf_size_for_resolution method.

Processes the data, and appends it to the buffer inside the provided String.

Failures

This fails if failed to process data.

Panics

This panics if failed to allocate memory. To avoid panic on allocation failure, use try_append_to_std_string.

Processes the data, and appends it to the buffer inside the provided String.

Failures

This fails if:

  • failed to allocate memory, or
  • failed to process data.

To see examples of unresolvable IRIs, visit the module documentation.

Examples
use iri_string::normalize::NormalizationTask;
use iri_string::task::ProcessAndWrite;
use iri_string::types::IriStr;

let iri = IriStr::new("HTTP://e%78ample%2ecom/a/../slash%2fslash/\u{03B1}%ce%b1%ff")?;
let task = NormalizationTask::from(iri);

let mut buf = String::from("Result: ");

let result: Result<&IriStr, _> = task.try_append_to_std_string(&mut buf);
if let Ok(s) = result {
    assert_eq!(s, "http://example.com/slash%2Fslash/\u{03B1}\u{03B1}%FF");
    assert_eq!(buf, "Result: http://example.com/slash%2Fslash/\u{03B1}\u{03B1}%FF");
}

Borrowed output types.

Owned output types.

Data processing error.

Processes the data, and writes it to the newly allocated buffer.

Failures

This fails if:

  • failed to allocate memory, or
  • failed to process data.

To see examples of unresolvable IRIs, visit the module documentation.

Examples
use iri_string::normalize::NormalizationTask;
use iri_string::task::ProcessAndWrite;
use iri_string::types::IriStr;

let iri = IriStr::new("HTTP://e%78ample%2ecom/a/../slash%2fslash/\u{03B1}%ce%b1%ff")?;
let task = NormalizationTask::from(iri);

assert_eq!(
    task.allocate_and_write()?,
    "http://example.com/slash%2Fslash/\u{03B1}\u{03B1}%FF"
);

Processes the data, and writes it to the given byte slice.

Failures

This fails if:

  • buffer is not large enough, or
  • failed to process data.

To see examples of unresolvable IRIs, visit the module documentation.

Examples
use iri_string::normalize::NormalizationTask;
use iri_string::task::ProcessAndWrite;
use iri_string::types::IriStr;

let iri = IriStr::new("HTTP://e%78ample%2ecom/a/../slash%2fslash/\u{03B1}%ce%b1%ff")?;
let task = NormalizationTask::from(iri);

// Long enough!
let mut buf = [0_u8; 128];
let normalized = task.write_to_byte_slice(&mut buf[..])?;

assert_eq!(normalized, "http://example.com/slash%2Fslash/\u{03B1}\u{03B1}%FF");

This returns error when the buffer is not long enough for processing. You can get maximum required buffer size by estimate_max_buf_size_for_resolution method.

Processes the data, and appends it to the buffer inside the provided String.

Failures

This fails if failed to process data.

Panics

This panics if failed to allocate memory. To avoid panic on allocation failure, use try_append_to_std_string.

Processes the data, and appends it to the buffer inside the provided String.

Failures

This fails if:

  • failed to allocate memory, or
  • failed to process data.

To see examples of unresolvable IRIs, visit the module documentation.

Examples
use iri_string::normalize::NormalizationTask;
use iri_string::task::ProcessAndWrite;
use iri_string::types::IriStr;

let iri = IriStr::new("HTTP://e%78ample%2ecom/a/../slash%2fslash/\u{03B1}%ce%b1%ff")?;
let task = NormalizationTask::from(iri);

let mut buf = String::from("Result: ");

let result: Result<&IriStr, _> = task.try_append_to_std_string(&mut buf);
if let Ok(s) = result {
    assert_eq!(s, "http://example.com/slash%2Fslash/\u{03B1}\u{03B1}%FF");
    assert_eq!(buf, "Result: http://example.com/slash%2Fslash/\u{03B1}\u{03B1}%FF");
}

Borrowed output types.

Owned output types.

Data processing error.

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

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.

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

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.