Rustime : Compile Time Code Evaluation And Generation Library

โš“ Rust    ๐Ÿ“… 2026-05-08    ๐Ÿ‘ค surdeus    ๐Ÿ‘๏ธ 2      

surdeus

Hey everyone! I just finished working on Rustime, a library for code evaluation and generation at compile time. I'd really appreciate it if you guys could check it out and give me some feedback or suggestions on how to improve it!

The Github repository : GitHub - fuji-184/Rustime ยท GitHub

Check out this quick example of how Rustime works :

[dependencies]
rustime = { git = "https://github.com/fuji-184/Rustime" }

[features]
default = []
rustime = []    # important
use rustime::*;

init_rustime!();

rustime!(full, "struct_tes");

fn math(i: i32) -> i32 {
  i * 2
}

fn vec() -> String {
  String::from(r#"
      vec![
        String::from("a"),
        String::from("b")
      ]
  "#)
}

fn string() -> Res<String> {
  Ok(String::from("hello"))
}

fn main() {
  rustime_scope!(
      let test = Tes {
        a0: 10,
        a1: 100
      };
      
      let math = rustime!("math");
      let vec = rustime!("vec");
      let string = rustime!("string");
      
      println!("math: {}", math);
      
      for val in vec {
        println!("vec: {}", val);
      }
      
      println!("string: {}", string);
      
  );
}

rustime!(
  use std::fmt::Write;
  
  struct_tes {
    let mut output = String::from("struct Tes {");
    let name = "a";
    for i in 0..2 {
      write!(output, "{}{}: i32,", name, i).unwrap();
    }
    output.push_str("}");
    rustime_output!(raw, output, "struct_tes");
  }
  
  compile_math {
    let output = math(10);
    rustime_output!(raw, output, "math");
  }
  
  compile_vec {
    let output = vec();
    rustime_output!(raw, output, "vec");
  }
  
  compile_string {
    let output = string()?;
    rustime_output!(str, &output, "string");
    
    // calling rustime_output with the same name will trigger panic because each return value should have different name
    // rustime_output!(str, output, "string");
  }
  
);

Bash script for commands pipeline :

cargo test --features=rustime -- --no-capture
clear
cargo run

Give permission to the bash script

chmod +x bash_script_name

Then to run it :

./bash_script_name

1 post - 1 participant

Read full topic

๐Ÿท๏ธ Rust_feed