有人能帮我理解为什么这段代码编译得很好吗
use actix_web::{App, HttpServer};
use anyhow::Result;
mod error;
#[actix_rt::main]
async fn main() -> Result<()> {
HttpServer::new(|| App::new())
.bind("127.0.0.1:8080")?
.run()
.await?;
Ok(())
}
虽然这无法编译:
use actix_web::{App, HttpServer};
use anyhow::Result;
mod error;
#[actix_rt::main]
async fn main() -> Result<()> {
HttpServer::new(|| App::new())
.bind("127.0.0.1:8080")?
.run()
.await
}
错误如下:
error[E0308]: mismatched types
--> src/main.rs:6:1
|
6 | #[actix_rt::main]
| ^^^^^^^^^^^^^^^^^ expected struct `anyhow::Error`, found struct `std::io::Error`
7 | async fn main() -> Result<()> {
| ---------- expected `std::result::Result<(), anyhow::Error>` because of return type
|
= note: expected enum `std::result::Result<_, anyhow::Error>`
found enum `std::result::Result<_, std::io::Error>`
= note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)
这两个例子有什么根本不同?