我无法将字符串变量与字符串字面量连接起来,是否有什么原因?下面是代码:
fn main() {
let x = ~"abcd";
io::println("Message: " + x);
}
会产生以下错误:
test2.rs:3:16: 3:31 error: binary operation + cannot be applied to type `&'static str`
test2.rs:3 io::println("Message: " + x);
^~~~~~~~~~~~~~~
error: aborting due to previous error
我想这是一种相当基本和非常常见的模式,使用fmt!
在这种情况下只会带来不必要的混乱。