pub struct Sep(pub usize);Expand description
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!"
);Tuple Fields§
§0: usizeTrait Implementations§
impl Copy for Sep
Auto Trait Implementations§
impl Freeze for Sep
impl RefUnwindSafe for Sep
impl Send for Sep
impl Sync for Sep
impl Unpin for Sep
impl UnwindSafe for Sep
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