pub struct Formatter { /* private fields */ }
Expand description
Collect source code to be written to a file and keep track of indentation.
Implementations§
Source§impl Formatter
impl Formatter
Sourcepub fn new(lang: Language) -> Self
pub fn new(lang: Language) -> Self
Source code formatter class. Used to collect source code of a specific
Language
to be written to a file, and keep track of indentation.
Sourcepub fn indent_push(&mut self)
pub fn indent_push(&mut self)
Increase current indentation level by one.
Sourcepub fn indent_pop(&mut self)
pub fn indent_pop(&mut self)
Decrease indentation by one level.
Sourcepub fn indent<T, F: FnOnce(&mut Formatter) -> T>(&mut self, f: F) -> T
pub fn indent<T, F: FnOnce(&mut Formatter) -> T>(&mut self, f: F) -> T
Increase indentation level for the duration of f
.
Sourcepub fn line_with_location(
&mut self,
contents: impl AsRef<str>,
location: FileLocation,
)
pub fn line_with_location( &mut self, contents: impl AsRef<str>, location: FileLocation, )
Add an indented lin with a given a location
appended as a comment to
the line (this is useful for identifying where a line was generated).
Sourcepub fn empty_line(&mut self)
pub fn empty_line(&mut self)
Pushes an empty line.
Sourcepub fn multi_line(&mut self, s: &str)
pub fn multi_line(&mut self, s: &str)
Add one or more lines after stripping common indentation.
Sourcepub fn doc_comment(&mut self, contents: impl AsRef<str>)
pub fn doc_comment(&mut self, contents: impl AsRef<str>)
Add a (multi-line) documentation comment.
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