pub struct Safe<T>(pub T);Expand description
Mark the output of a filter as “safe”
This struct can be used as a transparent return type of custom filters that want to mark their output as “safe” no matter what, i.e. that their output does not need to be escaped.
If the filter is not used as the last element in the filter chain, then any assumption is void. Let the next filter decide if the output is safe or not.
§Example
mod filters {
use askama::{filters::Safe, Result};
// Do not actually use this filter! It's an intentionally bad example.
pub fn strip_except_apos(s: impl ToString) -> Result<Safe<String>> {
Ok(Safe(s
.to_string()
.chars()
.filter(|c| !matches!(c, '<' | '>' | '"' | '&'))
.collect()
))
}
}
#[derive(askama::Template)]
#[template(
source = "<div class='{{ klass|strip_except_apos }}'></div>",
ext = "html"
)]
struct DivWithClass<'a> {
klass: &'a str,
}
assert_eq!(
DivWithClass { klass: "<&'lifetime X>" }.to_string(),
"<div class=''lifetime X'></div>",
);Tuple Fields§
§0: TTrait Implementations§
Source§impl<T: FastWritable> FastWritable for Safe<T>
impl<T: FastWritable> FastWritable for Safe<T>
Auto Trait Implementations§
impl<T> Freeze for Safe<T>where
T: Freeze,
impl<T> RefUnwindSafe for Safe<T>where
T: RefUnwindSafe,
impl<T> Send for Safe<T>where
T: Send,
impl<T> Sync for Safe<T>where
T: Sync,
impl<T> Unpin for Safe<T>where
T: Unpin,
impl<T> UnwindSafe for Safe<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