2
生鏽file examples不出現與Rust 1.18.0編譯。生鏽的文件示例不編譯
對於example:
use std::fs::File;
use std::io::prelude::*;
fn main() {
let mut file = File::open("foo.txt")?;
let mut contents = String::new();
file.read_to_string(&mut contents)?;
assert_eq!(contents, "Hello, world!");
}
錯誤日誌:
rustc 1.18.0 (03fc9d622 2017-06-06)
error[E0277]: the trait bound `(): std::ops::Carrier` is not satisfied
--> <anon>:4:20
|
4 | let mut file = File::open("foo.txt")?;
| ----------------------
| |
| the trait `std::ops::Carrier` is not implemented for `()`
| in this macro invocation
|
= note: required by `std::ops::Carrier::from_error`
error[E0277]: the trait bound `(): std::ops::Carrier` is not satisfied
--> <anon>:6:5
|
6 | file.read_to_string(&mut contents)?;
| -----------------------------------
| |
| the trait `std::ops::Carrier` is not implemented for `()`
| in this macro invocation
|
= note: required by `std::ops::Carrier::from_error`
error: aborting due to 2 previous errors
我upvoted。國際海事組織,這不是一個愚蠢的問題,因爲'?'操作符有點神祕,而且直覺上代碼示例不能放在'main'中。如果我記得,有一個RFC允許在主要中使用'Result'。 – Boiethios
對我來說,錯誤日誌也是如此搞砸了。 – Stargateur
相關答案:https://stackoverflow.com/a/43395610/1233251 –