Crates.io | simplegen |
lib.rs | simplegen |
version | 0.2.3 |
source | src |
created_at | 2021-04-26 18:51:54.818634 |
updated_at | 2021-09-17 16:06:38.972341 |
description | simplegen is a simple text buffer that maintains indentation for calls to `println()`. The contents of the buffer can be retrieved by calling the `to_string()` method. |
homepage | |
repository | https://github.com/MadManGaz/simplegen/ |
max_upload_size | |
id | 389828 |
size | 13,029 |
simplegen is a simple code generator library.
It is a text buffer that preserves indentation level on calls to println()
.
The contents of the buffer can be retrieved with to_string()
.
use simplegen::CodeBuffer;
fn main() {
let mut buffer = CodeBuffer::new(2);
buffer.println("[");
buffer.indent_right();
for number in 1..=5 {
buffer.println("{");
buffer.println_right(format!("\"number\": {}", number).as_str());
if number != 5 {
buffer.println_left("},");
} else {
buffer.println_left("}");
}
}
buffer.println_left("]");
// CodeBuffer::to_string() joins all the lines in the buffer into
// a single string.
println!("{}", buffer.to_string());
}
[
{
"number": 1
},
{
"number": 2
},
{
"number": 3
},
{
"number": 4
},
{
"number": 5
}
]