While following the rustbyexample.com tutorial, I typed the following code:
impl fmt::Display for Structure {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let x = format!("{}", "something");
write!(f, "OMG! {}", self.0);
}
}
And got the following error from the compiler:
error[E0308]: mismatched types
--> src/main.rs:5:58
|
5 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
| __________________________________________________________^
6 | | let x = format!("{}", "something");
7 | | write!(f, "OMG! {}", self.0);
8 | | }
| |_____^ expected enum `std::result::Result`, found ()
|
= note: expected type `std::result::Result<(), std::fmt::Error>`
found type `()`
help: consider removing this semicolon:
--> src/main.rs:7:37
|
7 | write!(f, "OMG! {}", self.0);
| ^
Why is the semicolon relevant (or not) here?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…