Rename Escaper argument fmt into dest

I was confused for a moment why an escaper would accept an
`fmt::Formatter` or `fmt::Arguments`.
This commit is contained in:
René Kijewski 2025-02-09 18:43:33 +01:00
parent 742821b1ce
commit e216f1b1ea

View File

@ -138,13 +138,13 @@ pub struct Html;
impl Escaper for Html { impl Escaper for Html {
#[inline] #[inline]
fn write_escaped_str<W: Write>(&self, fmt: W, string: &str) -> fmt::Result { fn write_escaped_str<W: Write>(&self, dest: W, string: &str) -> fmt::Result {
crate::html::write_escaped_str(fmt, string) crate::html::write_escaped_str(dest, string)
} }
#[inline] #[inline]
fn write_escaped_char<W: Write>(&self, fmt: W, c: char) -> fmt::Result { fn write_escaped_char<W: Write>(&self, dest: W, c: char) -> fmt::Result {
crate::html::write_escaped_char(fmt, c) crate::html::write_escaped_char(dest, c)
} }
} }
@ -154,13 +154,13 @@ pub struct Text;
impl Escaper for Text { impl Escaper for Text {
#[inline] #[inline]
fn write_escaped_str<W: Write>(&self, mut fmt: W, string: &str) -> fmt::Result { fn write_escaped_str<W: Write>(&self, mut dest: W, string: &str) -> fmt::Result {
fmt.write_str(string) dest.write_str(string)
} }
#[inline] #[inline]
fn write_escaped_char<W: Write>(&self, mut fmt: W, c: char) -> fmt::Result { fn write_escaped_char<W: Write>(&self, mut dest: W, c: char) -> fmt::Result {
fmt.write_char(c) dest.write_char(c)
} }
} }
@ -169,13 +169,13 @@ impl Escaper for Text {
/// E.g. in an [`Html`] context, any and all generated text can be used in HTML/XML text nodes and /// E.g. in an [`Html`] context, any and all generated text can be used in HTML/XML text nodes and
/// attributes, without for for maliciously injected data. /// attributes, without for for maliciously injected data.
pub trait Escaper: Copy { pub trait Escaper: Copy {
/// Escaped the input string `string` into `fmt` /// Escaped the input string `string` into `dest`
fn write_escaped_str<W: Write>(&self, fmt: W, string: &str) -> fmt::Result; fn write_escaped_str<W: Write>(&self, dest: W, string: &str) -> fmt::Result;
/// Escaped the input char `c` into `fmt` /// Escaped the input char `c` into `dest`
#[inline] #[inline]
fn write_escaped_char<W: Write>(&self, fmt: W, c: char) -> fmt::Result { fn write_escaped_char<W: Write>(&self, dest: W, c: char) -> fmt::Result {
self.write_escaped_str(fmt, c.encode_utf8(&mut [0; 4])) self.write_escaped_str(dest, c.encode_utf8(&mut [0; 4]))
} }
} }