simplegen

Crates.iosimplegen
lib.rssimplegen
version0.2.3
sourcesrc
created_at2021-04-26 18:51:54.818634
updated_at2021-09-17 16:06:38.972341
descriptionsimplegen 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
repositoryhttps://github.com/MadManGaz/simplegen/
max_upload_size
id389828
size13,029
Gary Moore (doggodoge)

documentation

README

simplegen ⚙️

simplegen is a simple code generator library.

simplegen

It is a text buffer that preserves indentation level on calls to println(). The contents of the buffer can be retrieved with to_string().

Example

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());
}

Output

[
  {
    "number": 1
  },
  {
    "number": 2
  },
  {
    "number": 3
  },
  {
    "number": 4
  },
  {
    "number": 5
  }
]
Commit count: 19

cargo fmt