$ macro-string
v0.2.0MAJOR UPDATEEager evaluation of macros like `concat!` and `env!`
Latest Update Summary
Crate
Name: macro-string New version: 0.2.0 Release date: 2026-02-24T17:53:12.864771Z
Crate readme
Short description A helper library for procedural macros to perform eager evaluation of standard library string macros.
Long description
This crate aids in the implementation of procedural macros by allowing eager evaluation of standard library string macros like concat!, env!, include!, include_str!, and stringify!. It includes functionality to parse input and return evaluated tokens, particularly useful in scenarios like parsing JSON at compile time with macros like include_json!. The crate is designed for Rust's macro system and interacts with the standard library.
Features
• supports standard library macros: concat!, env!, include!, include_str!, stringify!
Code Examples Basic usage
use macro_string::MacroString;
use proc_macro::TokenStream;
use std::fs;
use syn::parse_macro_input;
#[proc_macro]
pub fn include_json(input: TokenStream) -> TokenStream {
let macro_string = parse_macro_input!(input as MacroString);
let path = match macro_string.eval() {
Ok(path) => path,
Err(err) => return TokenStream::from(err.to_compile_error()),
};
let content = match fs::read(&path) {
Ok(content) => content,
Err(err) => return TokenStream::from(macro_string.error(err).to_compile_error()),
};
let json: serde_json::Value = match serde_json::from_slice(&content) {
Ok(json) => json,
Err(err) => return TokenStream::from(macro_string.error(err).to_compile_error()),
};
/*TODO: print serde_json::Value to TokenStream*/
}
Links • https://github.com/dtolnay/macro-string • https://crates.io/crates/macro-string • https://docs.rs/macro-string
https://docs.rs/macro-string https://api.github.com/repos/dtolnay/macro-string/releases/289989049
Release info
Release version:
Release description
Code Examples
Minor update: 0.1.4 → 0.2.0
$ DOWNLOADS TREND
$ VERSION HISTORY
$ LINKS
$ INSTALL
cargo add macro-stringOr add to Cargo.toml: macro-string = "0.2.0"