錆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
私はこれを支持した。 IMOでは、これは愚かな質問ではありません。なぜなら、 '? '演算子は少し不明瞭で、コード例を' main'に入れることができないという直感的ではないからです。私がよく覚えているなら、メインで 'Result'を使うことを許可するRFCがあります。 – Boiethios
私にとって、エラーログは混乱してしまいます。 – Stargateur
関連する回答:https://stackoverflow.com/a/43395610/1233251 –