我正在尝试从 Rust 官方网站上的 Rust 书中编译以下代码。
fn takes_slice(slice: &str) {
println!("Got: {}", slice);
}
fn main() {
let s = "Hello".to_string();
takes_slice(&s);
}
Run Code Online (Sandbox Code Playgroud)
在编译时,它抛出以下错误
/devl/rust/bc_09/src/main.rs:7:17: 7:19 error: mismatched types: expected
&str, found&collections::string::String(expected str, found struct collections::string::String)/devl/rust/bc_09/src/main.rs:7 take_slice(&s); ^~ 错误:由于先前的错误而中止无法编译
hello_world。
这是我正在运行的 Rust 版本:rustc 1.0.0-nightly (44a287e6e 2015-01-08 17:03:40 -0800)
| 归档时间: |
|
| 查看次数: |
460 次 |
| 最近记录: |