| Crates.io | exact_format |
| lib.rs | exact_format |
| version | 0.2.1 |
| created_at | 2025-03-07 16:36:24.105762+00 |
| updated_at | 2025-03-07 17:20:10.52474+00 |
| description | A procedural macro for compile time string replacement without using the standard format placeholder syntax (`{}`). This is most useful when dealing with strings that contain `{ }` blocks you do no wish to interpolate e.g. writing javascript. |
| homepage | |
| repository | https://github.com/mcmah309/exact_format |
| max_upload_size | |
| id | 1583342 |
| size | 12,983 |
A procedural macro for compile time string replacement without using the standard format placeholder syntax ({}). This is most useful when dealing with strings that contain { } blocks you do no wish to interpolate e.g. writing javascript.
The exact_format! macro allows you to replace exact string matches within a template:
use exact_format::exact_format;
// Basic replacement
let result = exact_format!("Hello {name}", "{name}" => "World");
assert_eq!(result, "Hello World");
// JavaScript-style template string replacement
let user_id = 42;
let user_name = "John";
let result = exact_format!("const user = { id: USERID, name: 'USERNAME' };",
"USERID" => user_id.to_string(),
"USERNAME" => user_name);
assert_eq!(result, "const user = { id: 42, name: 'John' };");
The macro expands to a format! call that handles the replacements. For example:
exact_format!("const user = { id: USERID, name: 'USERNAME' };",
"USERID" => user_id.to_string(),
"USERNAME" => user_name);
Expands to:
{
let __value0__ = user_id.to_string();
let __value1__ = user_name;
format!("{}{}{}{}{}",
"const user = { id: ",
__value0__,
", name: '",
__value1__,
"' };"
)
}
{}