An open API service indexing awesome lists of open source software.

https://github.com/apskhem/rust-code-builder

A code builder used for Rust code generation.
https://github.com/apskhem/rust-code-builder

Last synced: 8 months ago
JSON representation

A code builder used for Rust code generation.

Awesome Lists containing this project

README

          

# Rust Code Builder

A simple crate for building and managing structured code elements dynamically. It provides tools to create blocks of code, insert lines, and handle indentation, making it useful for code generation in a `no_std` environment.

## Features
- Supports structured code blocks with nested elements
- Allows inserting lines and empty lines dynamically
- Provides configurable indentation settings
- Works in `no_std` environments

## Usage

Add `rust-code-builder` as a dependency in your `Cargo.toml`:
```toml
[dependencies]
rust-code-builder = "0.1.0"
```

### Example
```rust
use rust_code_builder::{CodeSpace, Block};

let code = CodeSpace::new()
.insert_line("let x = 42;")
.insert_new_line()
.insert_block(
Block::new()
.set_signature(Some(BlockSignature::Custom(String::from("if x > 0"))))
.insert_line("println!(\"Positive number!\");"),
);

println!("{}", code);
```

### Output
```
let x = 42;

if x > 0 {
println!("Positive number!");
}

```

## License

Licensed under either of

- Apache License, Version 2.0
([LICENSE-APACHE](LICENSE-APACHE) or )
- MIT license
([LICENSE-MIT](LICENSE-MIT) or )

## Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in the work by you, as defined in the Apache-2.0 license, shall be
dual licensed as above, without any additional terms or conditions.

Always welcome you to participate, contribute and together.