pub struct Normalizer<'a> { /* private fields */ }Expand description
A std::fmt::Write that, if fed a prefix of its input, does not allocate.
Used for things like Ipv6Host where detecting if an input is normalized is super complicated but always allocating is super stupid.
§Examples
use std::fmt::Write;
use std::assert_matches;
use std::borrow::Cow;
use better_url::util::*;
// Prefixes don't get allocated.
let mut normalizer = Normalizer::new("abc");
write!(normalizer, "a").unwrap();
write!(normalizer, "b").unwrap();
assert_matches!(normalizer.done(), (true, Cow::Borrowed("ab")));
// But changes do.
let mut normalizer = Normalizer::new("[1::0]");
write!(normalizer, "[" ).unwrap();
write!(normalizer, "1" ).unwrap();
write!(normalizer, "::").unwrap();
write!(normalizer, "]" ).unwrap();
assert_matches!(normalizer.done(), (true, Cow::Owned(x)) if x == "[1::]");Implementations§
Trait Implementations§
Source§impl<'a> Clone for Normalizer<'a>
impl<'a> Clone for Normalizer<'a>
Source§impl<'a> Debug for Normalizer<'a>
impl<'a> Debug for Normalizer<'a>
Source§impl<'a> From<&'a str> for Normalizer<'a>
impl<'a> From<&'a str> for Normalizer<'a>
Source§impl From<String> for Normalizer<'static>
impl From<String> for Normalizer<'static>
Auto Trait Implementations§
impl<'a> Freeze for Normalizer<'a>
impl<'a> RefUnwindSafe for Normalizer<'a>
impl<'a> Send for Normalizer<'a>
impl<'a> Sync for Normalizer<'a>
impl<'a> Unpin for Normalizer<'a>
impl<'a> UnsafeUnpin for Normalizer<'a>
impl<'a> UnwindSafe for Normalizer<'a>
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