pub struct Indent<T>(pub T);Expand description
A wrapper which indents any newlines inside its contents.
§Examples
Basic usage:
use pretty_trait::{JoinExt, Sep, Indent, to_string};
let max_line = Some(20);
let tab_size = 4;
let expected = "\
(
lorem
ipsum
dolor
sit
amet
)";
assert_eq!(
to_string(
&"(".join(Indent(
Sep(0)
.join("lorem")
.join(Sep(1))
.join("ipsum")
.join(Sep(1))
.join("dolor")
.join(Sep(1))
.join("sit")
.join(Sep(1))
.join("amet")
)).join(Sep(0)).join(")"),
max_line,
tab_size,
),
expected
);§Caution
To indent a block enclosed in paired delimiters like brackets, care must be taken to ensure that
the first line of the content is indented, and that the closing delimiter is not indented
along with its contents. To ensure this, the newline after the opening delimiter should occur
inside the Indent block, and the newline before the closing delimiter should occur outside
the Indent block, as in the example above. The block function implements this pattern.
Tuple Fields§
§0: TTrait Implementations§
impl<T: Copy> Copy for Indent<T>
Auto Trait Implementations§
impl<T> Freeze for Indent<T>where
T: Freeze,
impl<T> RefUnwindSafe for Indent<T>where
T: RefUnwindSafe,
impl<T> Send for Indent<T>where
T: Send,
impl<T> Sync for Indent<T>where
T: Sync,
impl<T> Unpin for Indent<T>where
T: Unpin,
impl<T> UnwindSafe for Indent<T>where
T: 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