Struct mz_ore::codegen::CodegenBuf
source · pub struct CodegenBuf {
inner: String,
level: usize,
}
Expand description
A code generation buffer.
A CodegenBuf
provides a string-based API for generating Rust code. Its
value is in the various function it provides to automatically manage
indentation.
Fields§
§inner: String
§level: usize
Implementations§
source§impl CodegenBuf
impl CodegenBuf
sourcepub fn new() -> CodegenBuf
pub fn new() -> CodegenBuf
Creates a new code generation buffer.
sourcepub fn into_string(self) -> String
pub fn into_string(self) -> String
Consumes the buffer, returning its contents.
sourcepub fn writeln<S>(&mut self, s: S)
pub fn writeln<S>(&mut self, s: S)
Writes a line into the buffer at the current indentation level.
Specifically, the method writes (4 * indentation level) spaces into the
buffer, followed by s
, followed by a newline character.
sourcepub fn start_line(&mut self)
pub fn start_line(&mut self)
Starts a new line.
Specifically, the method writes (4 * indentation level) spaces into the buffer.
sourcepub fn end_line(&mut self)
pub fn end_line(&mut self)
Ends the current line.
Specifically, the method writes a newline character into the buffer.
sourcepub fn write_block<S, F>(&mut self, s: S, f: F)
pub fn write_block<S, F>(&mut self, s: S, f: F)
Writes a new indented block.
Specifically, if s
is empty, the method writes the line {
into the
buffer; otherwise writes the line s {
into the buffer at the current
indentation level. Then it increments the buffer’s indentation level,
runs the provided function, then decrements the indentation level and writes
a closing }
.
sourcepub fn restart_block<S>(&mut self, s: S)
pub fn restart_block<S>(&mut self, s: S)
Closes the current indented block and starts a new one at the same indentation level.
Specifically, the method writes the line } s {
into the buffer at one
less than the buffer’s indentation level.
§Panics
Panics if the current indentation level is zero.
Trait Implementations§
source§impl Clone for CodegenBuf
impl Clone for CodegenBuf
source§fn clone(&self) -> CodegenBuf
fn clone(&self) -> CodegenBuf
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for CodegenBuf
impl Debug for CodegenBuf
source§impl Default for CodegenBuf
impl Default for CodegenBuf
source§fn default() -> CodegenBuf
fn default() -> CodegenBuf
Auto Trait Implementations§
impl Freeze for CodegenBuf
impl RefUnwindSafe for CodegenBuf
impl Send for CodegenBuf
impl Sync for CodegenBuf
impl Unpin for CodegenBuf
impl UnwindSafe for CodegenBuf
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> FutureExt for T
impl<T> FutureExt for T
source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request