pub struct Normalizer { /* private fields */ }Available on crate feature
alloc only.Expand description
A configurable URI/IRI (reference) normalizer.
Implementations§
Source§impl Normalizer
impl Normalizer
Sourcepub fn allow_path_underflow(self, value: bool) -> Self
pub fn allow_path_underflow(self, value: bool) -> Self
Sets whether to allow underflow in path normalization.
This defaults to true. A value of false is a deviation from the
normalization methods described in
Section 6 of RFC 3986.
§Examples
use fluent_uri::{normalize::{Normalizer, NormalizeError}, Uri};
let normalizer = Normalizer::new().allow_path_underflow(false);
let uri = Uri::parse("http://example.com/..")?;
assert_eq!(normalizer.normalize(&uri).unwrap_err(), NormalizeError::PathUnderflow);Sourcepub fn default_port_with(self, f: fn(&Scheme) -> Option<u16>) -> Self
pub fn default_port_with(self, f: fn(&Scheme) -> Option<u16>) -> Self
Sets the function with which to get the default port of a scheme.
This defaults to Scheme::default_port.
§Examples
use fluent_uri::{component::Scheme, normalize::Normalizer, Uri};
const SCHEME_FOO: &Scheme = Scheme::new_or_panic("foo");
let normalizer = Normalizer::new().default_port_with(|scheme| {
if scheme == SCHEME_FOO {
Some(4673)
} else {
scheme.default_port()
}
});
let uri = Uri::parse("foo://localhost:4673")?;
assert_eq!(normalizer.normalize(&uri).unwrap(), "foo://localhost");Sourcepub fn normalize<R: RiMaybeRef>(
&self,
r: &R,
) -> Result<R::WithVal<String>, NormalizeError>
pub fn normalize<R: RiMaybeRef>( &self, r: &R, ) -> Result<R::WithVal<String>, NormalizeError>
Normalizes the given URI/IRI (reference).
See Uri::normalize for the exact behavior of this method.
§Errors
Returns Err if an underflow occurred in path normalization
when allow_path_underflow is set to false.
Trait Implementations§
Source§impl Clone for Normalizer
impl Clone for Normalizer
Source§fn clone(&self) -> Normalizer
fn clone(&self) -> Normalizer
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Default for Normalizer
impl Default for Normalizer
impl Copy for Normalizer
Auto Trait Implementations§
impl Freeze for Normalizer
impl RefUnwindSafe for Normalizer
impl Send for Normalizer
impl Sync for Normalizer
impl Unpin for Normalizer
impl UnwindSafe for Normalizer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more