这个问题与 Rust 的预发布版本有关。 这个年轻的问题是相似的。
我试图打印一个符号println
:
fn main() {
println!('c');
}
但我得到了下一个错误:
$ rustc pdst.rs
pdst.rs:2:16: 2:19 error: mismatched types: expected `&str` but found `char` (expected &str but found char)
pdst.rs:2 println!('c');
^~~
error: aborting due to previous error
如何将字符转换为字符串?
直接类型转换不起作用:
let text:str = 'c';
let text:&str = 'c';
它返回:
pdst.rs:7:13: 7:16 error: bare `str` is not a type
pdst.rs:7 let text:str = 'c';
^~~
pdst.rs:7:19: 7:22 error: mismatched types: expected `~str` but found `char` (expected ~str but found char)
pdst.rs:7 let text:str = 'c';
^~~
pdst.rs:8:20: 8:23 error: mismatched types: expected `&str` but found `char` (expected &str but found char)
pdst.rs:8 let text:&str = 'c';
^~~