Expand description
std::concat!
with support for const
variables and expressions.
Works on stable Rust ✨.
🚀 Getting started
Add constcat
to your Cargo manifest.
cargo add constcat
Import the macro using the following.
use constcat::concat;
🤸 Usage
concat!
works exactly like std::concat!
except you can
now pass variables and constant expressions. For example:
const CRATE_NAME: &str = env!("CARGO_PKG_NAME");
const CRATE_VERSION: &str = env!("CARGO_PKG_VERSION");
const fn tada() -> &'static str { "🎉" }
const VERSION: &str = concat!(CRATE_NAME, " ", CRATE_VERSION, tada());
concat_bytes!
works similarly except it yields a static byte slice. For
example:
const VERSION: u32 = 1;
const fn entries() -> &'static [u8] { b"example" }
const HEADER: &[u8] = concat_bytes!(&VERSION.to_le_bytes(), entries());