Rust’s generic `Result<T, E>` carries either a success value of type `T` or an error. Functions and methods that can fail commonly return it so callers can inspect the outcome. `unwrap()` extracts a success value but panics on error; `?` can propagate errors from functions that return `Result`. section 2.2.2 section 7.2
Server examples use `Result` around operations that can fail:
- TCP server and client code calls `unwrap()` on bind, connect, read, and write operations. This simplifies the examples, but is not presented as appropriate real-world handling of recoverable failures. section 2.2.2
- An Actix server’s `main` function returns a `Result`; the example uses `?` to propagate a bind error. section 7.2
- Actix Web error handling can convert custom errors into HTTP responses, using `ResponseError` and `From` implementations. section 5.7
use actix_files as fs; #1
use actix_web::{error, web, App, Error, HttpResponse, HttpServer, Result};
#[actix_web::main]
async fn main() -> std::io::Result<()> { #2
let addr = env::var("SERVER_ADDR").unwrap_or_else(|_|
"127.0.0.1:8080".to_string());
println!("Listening on: {}, open browser and visit have a try!",addr);
HttpServer::new(|| {
App::new().service(fs::Files::new(
"/static", "./static").show_files_listing()) #3
})
.bind(addr)? #4
.run() #5
.await #6
}
The server entry point returns `std::io::Result<()>` and propagates a bind failure with `?`. section 7.2







