use core::fmt::Write; use unicode_segmentation::UnicodeSegmentation; /// A writer that writes to a writer, replacing `\n` with `\r\n` pub struct WriterWithCr { writer: T } impl WriterWithCr { pub const fn new(writer: T) -> Self { Self { writer } } } impl Write for WriterWithCr { fn write_str(&mut self, s: &str) -> core::fmt::Result { for c in s.graphemes(true) { match c { "\n" => self.writer.write_str("\r\n")?, s => self.writer.write_str(s)? } } Ok(()) } }