pub struct IndentWriter<'i, W> { /* private fields */ }
Expand description
Adapter for writers to indent each line
An IndentWriter
adapts an io::Write
object to insert an indent before
each non-empty line. Specifically, this means it will insert an indent
between each newline when followed by a non-newline.
These writers can be nested to provide increasing levels of indentation.
§Example
use indent_write::io::IndentWriter;
let output = Vec::new();
let mut indented = IndentWriter::new("\t", output);
// Lines will be indented
write!(indented, "Line 1\nLine 2\n");
// Empty lines will not be indented
write!(indented, "\n\nLine 3\n\n");
assert_eq!(indented.get_ref(), b"\tLine 1\n\tLine 2\n\n\n\tLine 3\n\n");
Implementations§
Source§impl<'i, W: Write> IndentWriter<'i, W>
impl<'i, W: Write> IndentWriter<'i, W>
Sourcepub fn new(indent: &'i str, writer: W) -> Self
pub fn new(indent: &'i str, writer: W) -> Self
Create a new IndentWriter
.
Sourcepub fn new_skip_initial(indent: &'i str, writer: W) -> Self
pub fn new_skip_initial(indent: &'i str, writer: W) -> Self
Create a new IndentWriter
which will not add an indent to the first
written line.
§Example
use indent_write::io::IndentWriter;
let mut buffer = Vec::new();
let mut writer = IndentWriter::new_skip_initial(" ", &mut buffer);
writeln!(writer, "Line 1").unwrap();
writeln!(writer, "Line 2").unwrap();
writeln!(writer, "Line 3").unwrap();
assert_eq!(buffer, b"Line 1\n Line 2\n Line 3\n")
Sourcepub fn into_inner(self) -> W
pub fn into_inner(self) -> W
Extract the writer from the IndentWriter
, discarding any in-progress
indent state.
Trait Implementations§
Source§impl<'i, W: Clone> Clone for IndentWriter<'i, W>
impl<'i, W: Clone> Clone for IndentWriter<'i, W>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl<'i, W: Debug> Debug for IndentWriter<'i, W>
impl<'i, W: Debug> Debug for IndentWriter<'i, W>
Source§impl<'i, W: Write> Write for IndentWriter<'i, W>
impl<'i, W: Write> Write for IndentWriter<'i, W>
Source§fn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
Writes a buffer into this writer, returning how many bytes were written. Read more
Source§fn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
Flushes this output stream, ensuring that all intermediately buffered
contents reach their destination. Read more
Source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
🔬This is a nightly-only experimental API. (
can_vector
)1.0.0 · Source§fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
Attempts to write an entire buffer into this writer. Read more
Source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
🔬This is a nightly-only experimental API. (
write_all_vectored
)Attempts to write multiple buffers into this writer. Read more
Auto Trait Implementations§
impl<'i, W> Freeze for IndentWriter<'i, W>where
W: Freeze,
impl<'i, W> RefUnwindSafe for IndentWriter<'i, W>where
W: RefUnwindSafe,
impl<'i, W> Send for IndentWriter<'i, W>where
W: Send,
impl<'i, W> Sync for IndentWriter<'i, W>where
W: Sync,
impl<'i, W> Unpin for IndentWriter<'i, W>where
W: Unpin,
impl<'i, W> UnwindSafe for IndentWriter<'i, W>where
W: 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