代码点读机 / Rust / concat!

concat! Rust · 宏

在编译期把多个字符串字面量拼接成一个静态字符串,不产生运行时开销。

怎么用

concat!("a", "b");,用于编译期拼接字符串

小例子

let s = concat!("Hello", " ", "World");
println!("{}", s);

运行结果

Hello World

提醒:只能接收字符串字面量和数字字面量

官方文档:https://doc.rust-lang.org/std/macro.concat.html

在代码里遇到不认识的词?打开代码点读机,点一下就懂 → ← Rust全部词条