1pub fn html(input: &str) -> String {
5 let mut out = String::with_capacity(input.len());
6 for ch in input.chars() {
7 match ch {
8 '&' => out.push_str("&"),
9 '<' => out.push_str("<"),
10 '>' => out.push_str(">"),
11 '"' => out.push_str("""),
12 '\'' => out.push_str("'"),
13 other => out.push(other),
14 }
15 }
16 out
17}
18
19pub fn safe(input: impl Into<String>) -> SafeString {
21 SafeString(input.into())
22}
23
24#[derive(Debug, Clone)]
25pub struct SafeString(pub String);
26
27impl std::fmt::Display for SafeString {
28 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
29 f.write_str(&self.0)
30 }
31}