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.
- Host: GitHub
- URL: https://github.com/apskhem/rust-code-builder
- Owner: apskhem
- License: apache-2.0
- Created: 2025-01-29T12:06:34.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-01-29T15:20:16.000Z (over 1 year ago)
- Last Synced: 2025-01-29T15:24:16.260Z (over 1 year ago)
- Language: Rust
- Homepage:
- Size: 21.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
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.