Struct pretty_trait::Sep [] [src]

pub struct Sep(pub usize);

A whitespace separator, rendered as a space if unbroken or a newline if broken.

The most common uses of Sep are Sep(1), which renders as a single space or a newline, and Sep(0), which introduces a point where a newline will be inserted if the content is broken.

Examples

Breaking into multiple lines:

use pretty_trait::{JoinExt, Sep, to_string};

let max_line = Some(10);
let tab_size = 4;

// Exceeding the line length without a separator:
assert_eq!(to_string(&"hello".join("world!"), max_line, tab_size), "helloworld!");

let expected_broken = "\
hello
world!";

assert_eq!(
    to_string(&"hello".join(Sep(0)).join("world!"), max_line, tab_size),
    expected_broken
);

assert_eq!(
    to_string(&"hello".join(Sep(1)).join("world!"), max_line, tab_size),
    expected_broken
);

Introducing spaces on a single line:

assert_eq!(
    to_string(&"hello".join(Sep(1)).join("world!"), None, tab_size),
    "hello world!"
);

assert_eq!(
    to_string(&"hello".join(Sep(0)).join("world!"), None, tab_size),
    "helloworld!"
);

Trait Implementations

impl Clone for Sep
[src]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

impl Copy for Sep
[src]

impl Debug for Sep
[src]

[src]

Formats the value using the given formatter. Read more

impl Pretty for Sep
[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 Send for Sep

impl Sync for Sep