Skip to content
Search

Crabtime

lastmod 2025-03-26created 2025-03-261 edits

Let's use Zig's Comptime in Rust

Features

  • A macro that evaluates inline Rust logic at compile time to generate and add new code
  • Offers more flexibility and performance than Procedural macros, while being easier and more natural to read and write than macro_rules
  • Supports Token Stream/Macro Fragments/Rust code for both Input and Output
  • IDE support, code formatting, and inline definitions are possible, with excellent readability
  • One-shot eval : complex compile-time computations can be handled simply
const MY_NUM: usize = crabtime::eval! {
  (std::f32::consts::PI.sqrt() * 10.0).round() as usize
};
  • Function-like macros (Function-like Macros)
    • Function-like macros can be defined with #[crabtime::function]
    • Defined functions are converted into macros and executed at build time
    • Macros can be exported using the standard #[macro_export] attribute
  • Macro-defined functions are inserted as the main function of a temporary Rust project
  • After compilation, the generated code is returned via stdout

See also

Favorite site

author Zer0 sitemap