Struct iri_string::normalize::NormalizationTask
source · [−]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
sourceimpl<'a, T: ?Sized + AsRef<str>> NormalizationTask<'a, T>
impl<'a, T: ?Sized + AsRef<str>> NormalizationTask<'a, T>
sourcepub fn enable_normalization(&mut self)
pub fn enable_normalization(&mut self)
Enables normalization for the task.
sourcepub fn enable_whatwg_serialization(&mut self)
pub fn enable_whatwg_serialization(&mut self)
Enables WHATWG URL Standard serialization for the task.
sourcepub fn estimate_max_buf_size_for_resolution(&self) -> usize
pub fn estimate_max_buf_size_for_resolution(&self) -> usize
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
sourceimpl<'a, T: Clone + ?Sized> Clone for NormalizationTask<'a, T>
impl<'a, T: Clone + ?Sized> Clone for NormalizationTask<'a, T>
sourcefn clone(&self) -> NormalizationTask<'a, T>
fn clone(&self) -> NormalizationTask<'a, T>
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, T: Debug + ?Sized> Debug for NormalizationTask<'a, T>
impl<'a, T: Debug + ?Sized> Debug for NormalizationTask<'a, T>
sourceimpl<'a, S: Spec> From<&'a RiAbsoluteStr<S>> for NormalizationTask<'a, RiAbsoluteStr<S>>
impl<'a, S: Spec> From<&'a RiAbsoluteStr<S>> for NormalizationTask<'a, RiAbsoluteStr<S>>
sourcefn from(iri: &'a RiAbsoluteStr<S>) -> Self
fn from(iri: &'a RiAbsoluteStr<S>) -> Self
Converts to this type from the input type.
sourceimpl<'a, S: Spec> From<&'a RiAbsoluteString<S>> for NormalizationTask<'a, RiAbsoluteStr<S>>
impl<'a, S: Spec> From<&'a RiAbsoluteString<S>> for NormalizationTask<'a, RiAbsoluteStr<S>>
sourcefn from(iri: &'a RiAbsoluteString<S>) -> Self
fn from(iri: &'a RiAbsoluteString<S>) -> Self
Converts to this type from the input type.
sourceimpl<S: Spec> ProcessAndWrite for &NormalizationTask<'_, RiStr<S>>
impl<S: Spec> ProcessAndWrite for &NormalizationTask<'_, RiStr<S>>
sourcefn allocate_and_write(
self
) -> Result<Self::OutputOwned, TaskError<Self::ProcessError>>
fn allocate_and_write(
self
) -> Result<Self::OutputOwned, TaskError<Self::ProcessError>>
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"
);
sourcefn write_to_byte_slice(
self,
buf: &mut [u8]
) -> Result<&Self::OutputBorrowed, TaskError<Self::ProcessError>>
fn write_to_byte_slice(
self,
buf: &mut [u8]
) -> Result<&Self::OutputBorrowed, TaskError<Self::ProcessError>>
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.
sourcefn append_to_std_string(
self,
buf: &mut String
) -> Result<&Self::OutputBorrowed, Self::ProcessError>
fn append_to_std_string(
self,
buf: &mut String
) -> Result<&Self::OutputBorrowed, Self::ProcessError>
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
.
sourcefn try_append_to_std_string(
self,
buf: &mut String
) -> Result<&Self::OutputBorrowed, TaskError<Self::ProcessError>>
fn try_append_to_std_string(
self,
buf: &mut String
) -> Result<&Self::OutputBorrowed, TaskError<Self::ProcessError>>
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");
}
type OutputBorrowed = RiStr<S>
type OutputBorrowed = RiStr<S>
Borrowed output types.
type OutputOwned = RiString<S>
type OutputOwned = RiString<S>
Owned output types.
type ProcessError = Error
type ProcessError = Error
Data processing error.
sourceimpl<S: Spec> ProcessAndWrite for &NormalizationTask<'_, RiAbsoluteStr<S>>
impl<S: Spec> ProcessAndWrite for &NormalizationTask<'_, RiAbsoluteStr<S>>
sourcefn allocate_and_write(
self
) -> Result<Self::OutputOwned, TaskError<Self::ProcessError>>
fn allocate_and_write(
self
) -> Result<Self::OutputOwned, TaskError<Self::ProcessError>>
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"
);
sourcefn write_to_byte_slice(
self,
buf: &mut [u8]
) -> Result<&Self::OutputBorrowed, TaskError<Self::ProcessError>>
fn write_to_byte_slice(
self,
buf: &mut [u8]
) -> Result<&Self::OutputBorrowed, TaskError<Self::ProcessError>>
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.
sourcefn append_to_std_string(
self,
buf: &mut String
) -> Result<&Self::OutputBorrowed, Self::ProcessError>
fn append_to_std_string(
self,
buf: &mut String
) -> Result<&Self::OutputBorrowed, Self::ProcessError>
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
.
sourcefn try_append_to_std_string(
self,
buf: &mut String
) -> Result<&Self::OutputBorrowed, TaskError<Self::ProcessError>>
fn try_append_to_std_string(
self,
buf: &mut String
) -> Result<&Self::OutputBorrowed, TaskError<Self::ProcessError>>
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");
}
type OutputBorrowed = RiAbsoluteStr<S>
type OutputBorrowed = RiAbsoluteStr<S>
Borrowed output types.
type OutputOwned = RiAbsoluteString<S>
type OutputOwned = RiAbsoluteString<S>
Owned output types.
type ProcessError = Error
type ProcessError = Error
Data processing error.
impl<'a, T: Copy + ?Sized> Copy for NormalizationTask<'a, T>
Auto Trait Implementations
impl<'a, T: ?Sized> RefUnwindSafe for NormalizationTask<'a, T>
impl<'a, T: ?Sized> Send for NormalizationTask<'a, T>
impl<'a, T: ?Sized> Sync for NormalizationTask<'a, T>
impl<'a, T: ?Sized> Unpin for NormalizationTask<'a, T>
impl<'a, T: ?Sized> UnwindSafe for NormalizationTask<'a, T>
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