3 stable releases
| 1.0.2 | Feb 16, 2025 |
|---|---|
| 1.0.0 | Dec 10, 2024 |
#2980 in Rust patterns
276 downloads per month
Used in rpgn
9KB
77 lines
The fastest, constant able (thanks to constcat), no-std compatible way to concatenate &strs.
Due to how macros work, you need to import constcat as a separate dependency.
Comparison with other macros
This is as fast or faster than the fastest string concatenating crates (I checked those in hoodie/concatenation_benchmarks-rs).
Those have other problems too:
concat_string_macroevaluates expressions twice and requires std.concat_strs_macrodoesn't work for certain expressions.string_concat_macrois the best, but it doesn't have the last two of the optimizations below. As a nitpick, it also requires that youuse string_concat::string_concat_impl. I know, I know. Grasping at straws, but I wanted to go over all the differences.
Optimizations
- Each expression gets a variable and thus won't be evaluated twice at runtime.
- If you pass multiple constants or literals in a row, they will be concatenated at compile time and pushed to the buffer only once.
- Passing only constants or literals makes the macro act as the
concat!macro, and a literal will be returned.
Dependencies
~115–485KB
~12K SLoC