Crates.io | buns |
lib.rs | buns |
version | 0.1.0 |
source | src |
created_at | 2024-11-11 12:17:48.656821 |
updated_at | 2024-11-11 12:17:48.656821 |
description | Create simple code templates - basically macro_rules lite |
homepage | |
repository | https://github.com/dekirisu/buns |
max_upload_size | |
id | 1443716 |
size | 24,320 |
A simple way to write repeatable code anywhere, by defining buns and toppings. 🍞
This can be seen as format!()
, but for code:
^0 ^1 .. ^N
as (Topping) placeholders#0^1^..^N
, where numbers = any codebuns::sandwich!{
const ^0: u32 = ^1; // Buns
#TEST^10 #OMEGA^59 // Toppings
}
// Will generate:
// const TEST: u32 = 10;
// const OMEGA: u32 = 59;
This can be seen as a simplified macro_rules!{}
, where you prepare named Buns and add the Toppings later using the generated macro (The code (Buns) is automatically added to the macro documentation):
buns::prepare!{
burger // Name
let a = ^0 + ^0; // Buns
println!("{a}"); // "
}
fn main(){
burger!{#1 #2 #4+4 #4 #2*2} // Toppings
// prints: 2 4 16 8 8
}
You can use any other magical token macro like paste to add functionality:
buns::sandwich!{
paste::paste!{const [<^1 _ ^0:upper>]: ^0 = ^2;}
#u32^BREAD^100 #f32^BREAD^12.0
}
// Will generate:
// const BREAD_U32: u32 = 100;
// const BREAD_F32: f32 = 12.9;