pub struct IndentWriter<'i, W> { /* private fields */ }
Expand description
Adapter for writers to indent each line
An IndentWriter
adapts a fmt::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::fmt::IndentWriter;
let output = String::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(), "\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::fmt::IndentWriter;
let mut buffer = String::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, "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>
Source§fn clone(&self) -> IndentWriter<'i, W>
fn clone(&self) -> IndentWriter<'i, W>
Returns a copy of the value. Read more
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>
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