logparse_pretty_print/traits/mod.rs
1use crate::{PrettyTree, providers::PrettyProvider};
2use alloc::string::String;
3
4pub mod printer;
5
6/// The `PrettyPrint` trait is implemented by types that can be pretty-printed.
7pub trait PrettyBuilder<'a, T> {
8 /// Acts as `self` when laid out on multiple lines and acts as `that` when laid out on a single line.
9 ///
10 /// ```
11 /// use pretty::{Arena, DocAllocator};
12 ///
13 /// let arena = Arena::<()>::new();
14 /// let body = arena.line().append("x");
15 /// let doc = arena
16 /// .text("let")
17 /// .append(arena.line())
18 /// .append("x")
19 /// .group()
20 /// .append(body.clone().flat_alt(arena.line().append("in").append(body)))
21 /// .group();
22 ///
23 /// assert_eq!(doc.1.pretty(100).to_string(), "let x in x");
24 /// assert_eq!(doc.1.pretty(8).to_string(), "let x\nx");
25 /// ```
26 fn flat_alt<E>(self, inline: E) -> PrettyTree<'a, T>
27 where
28 E: Into<PrettyTree<'a, T>>;
29 /// Acts as `self` when laid out on a single line and acts as `that` when laid out on multiple lines.
30 fn indent(self, indent: usize) -> PrettyTree<'a, T>;
31
32 /// Increase the indentation level of this document.
33 fn nest(self, offset: isize) -> PrettyTree<'a, T>;
34}