Struct pretty_trait::Indent [] [src]

pub struct Indent<T>(pub T);

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.

Trait Implementations

impl<T: Clone> Clone for Indent<T>
[src]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

impl<T: Copy> Copy for Indent<T>
[src]

impl<T: Debug> Debug for Indent<T>
[src]

[src]

Formats the value using the given formatter. Read more

impl<T: Pretty> Pretty for Indent<T>
[src]

[src]

Calculate the intrinsic size of this value, if it were to be displayed on a single line.

[src]

Render this value in a given context.

Auto Trait Implementations

impl<T> Send for Indent<T> where
    T: Send

impl<T> Sync for Indent<T> where
    T: Sync