Die Rust file examples erscheinen nicht mit Rust 1.18.0 kompilieren.Rust File Beispiele nicht kompilieren
Für 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!");
}
Fehlerprotokoll:
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
I upvoted. IMO, das ist keine blöde Frage, da der '?' - Operator etwas kryptisch ist, und es ist kontraintuitiv, dass das Codebeispiel nicht in ein 'main' geschrieben werden kann. Wenn ich mich recht erinnere, gibt es einen RFC, der es erlaubt, 'Result' in einem Main zu verwenden. – Boiethios
Für mich ist das Fehlerprotokoll verwirrend, also upvote auch. – Stargateur
Relevante Antwort: https://StackOverflow.com/a/43395610/1233251 –