pub struct Esc<T: AsRef<str>>(pub T);
Expand description
A formatting wrapper for escaping HTML in a string.
The Display
implementation replaces
&
with&
<
with<
>
with>
"
with"
'
with'
Esc
is lazy: If you don’t use it, it does nothing. Also, it
doesn’t allocate a String
unless you call .to_string()
.
§Examples
In a format!
-like macro:
assert_eq!(&format!("{}", Esc("<h1>")), "<h1>");
Convert it to a String directly:
assert_eq!(&Esc("<h1>").to_string(), "<h1>");
Tuple Fields§
§0: T
Trait Implementations§
impl<T: Copy + AsRef<str>> Copy for Esc<T>
impl<T: Eq + AsRef<str>> Eq for Esc<T>
impl<T: AsRef<str>> StructuralPartialEq for Esc<T>
Auto Trait Implementations§
impl<T> Freeze for Esc<T>where
T: Freeze,
impl<T> RefUnwindSafe for Esc<T>where
T: RefUnwindSafe,
impl<T> Send for Esc<T>where
T: Send,
impl<T> Sync for Esc<T>where
T: Sync,
impl<T> Unpin for Esc<T>where
T: Unpin,
impl<T> UnwindSafe for Esc<T>where
T: UnwindSafe,
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