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§unsafe fn clone_to_uninit(&self, dst: *mut T)
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