use crate::fmt;
pub struct FmtWriter<W>
where
W: core::fmt::Write,
{
writer: W,
}
impl<W> FmtWriter<W>
where
W: core::fmt::Write,
{
pub fn new(writer: W) -> Self {
Self { writer }
}
pub fn as_formatter<'a>(&'a mut self, config: &'a fmt::Config) -> fmt::Formatter<'a> {
fmt::Formatter::new(self, config)
}
pub fn into_inner(self) -> W {
self.writer
}
}
impl<W> core::fmt::Write for FmtWriter<W>
where
W: core::fmt::Write,
{
#[inline(always)]
fn write_char(&mut self, c: char) -> core::fmt::Result {
self.writer.write_char(c)
}
#[inline(always)]
fn write_str(&mut self, s: &str) -> core::fmt::Result {
self.writer.write_str(s)
}
}
impl<W> fmt::Write for FmtWriter<W>
where
W: core::fmt::Write,
{
#[inline(always)]
fn write_line(&mut self, config: &fmt::Config) -> fmt::Result {
self.writer.write_str(config.newline)
}
}