【发布时间】:2016-09-22 20:13:30
【问题描述】:
在“猜谜游戏”教程示例 (here) 中,我的编译器给出了以下错误,我将其解释为 expect 不存在于 read_line 的 Result 上。
error: type `core::result::Result<usize, std::io::error::Error>` does not implement any method in scope named `expect`
违规代码:
use std::io;
fn main() {
println!("**********************");
println!("***Guess the number***");
println!("**********************");
let mut guess = String::new();
io::stdin()
.read_line(&mut guess)
.expect("Failed to read line"); //<<-- error on this line
//let guess_result=io::stdin().read_line(&mut guess);
println!("You guessed: {}", guess);
// println!("Result: {}", guess_result.is_ok());
}
我可以删除带有.expect() 的行并使用上面注释的行并使其正常工作。我担心的是,io::stdin().read_line 的结果类型似乎是 core::result::Result,而不是教程中提到的 std::io::Result。
如果我在 Rust 操场上运行相同的代码,它似乎运行良好,所以它可能在我的环境中,但我想不出它会是什么。
其他可能相关的信息:
- 我使用了一个重新签署 SSL 证书的公司代理,因此 rust-lang 网站推荐的安装脚本不起作用
- 我使用
rust-1.0.0-x86_64-pc-windows-gnu.msi安装 - 我正在使用上述“1.0.0”安装程序中包含的货物
- 我已经手动将 rustc 和 cargo 的路径添加到我的环境
PATH - 我在 64 位 Windows 7 上使用 cygwin
TL;DR
我需要进行哪些更改才能在我的环境中编译 expect() 行?
【问题讨论】:
-
Rust 1.0.0 已经有一年多了。卸载它,然后尝试最新的稳定版本:static.rust-lang.org/dist/rust-1.11.0-x86_64-pc-windows-gnu.msi。我不知道这是否是根本问题,但保持最新不会有什么坏处!
-
为了将来的参考,可以随时从rust-lang.org/en-US/downloads.html 下载最新版 Rust 的安装程序。您不需要使用 shell 脚本(尽管如果可以,那就更好了,因为 rustup.sh 允许您并行安装多个版本的编译器)!
标签: rust