Struct preserves_schema::syntax::block::Formatter
source · pub struct Formatter {
pub width: usize,
pub buffer: String,
/* private fields */
}
Expand description
State needed for pretty-formatting of Emittables.
Fields§
§width: usize
Number of available columns. Used to decide between horizontal and vertical layouts.
buffer: String
Mutable output buffer. Accumulates emitted text during writing.
Implementations§
source§impl Formatter
impl Formatter
sourcepub fn new() -> Self
pub fn new() -> Self
Construct a Formatter using DEFAULT_WIDTH and a four-space indent.
sourcepub fn copy_empty(&self) -> Formatter
pub fn copy_empty(&self) -> Formatter
Construct a Formatter just like self
but with an empty buffer
.
sourcepub fn indent_size(self) -> usize
pub fn indent_size(self) -> usize
Yields the indent size.
sourcepub fn set_indent_size(&mut self, n: usize)
pub fn set_indent_size(&mut self, n: usize)
Updates the indent size.
sourcepub fn to_string<E: Emittable>(e: E) -> String
pub fn to_string<E: Emittable>(e: E) -> String
Creates a default Formatter, uses it to write e
, and yields the
contents of its buffer
.
sourcepub fn with_indent<R, F: FnOnce(&mut Self) -> R>(&mut self, f: F) -> R
pub fn with_indent<R, F: FnOnce(&mut Self) -> R>(&mut self, f: F) -> R
Calls f
in a context where the indentation has been increased by
Formatter::indent_size spaces. Restores the indentation level after f
returns.
Yields the result of the call to f
.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Formatter
impl RefUnwindSafe for Formatter
impl Send for Formatter
impl Sync for Formatter
impl Unpin for Formatter
impl UnwindSafe for Formatter
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