1
0
mirror of https://github.com/fafhrd91/actix-net synced 2025-01-19 08:24:41 +01:00
actix-net/actix-server/examples/startup-fail.rs

34 lines
825 B
Rust
Raw Normal View History

use std::io;
use actix_rt::net::TcpStream;
use actix_server::Server;
2021-10-25 18:13:08 +01:00
use actix_service::{fn_factory, fn_service};
use log::info;
#[actix_rt::main]
async fn main() -> io::Result<()> {
env_logger::Builder::from_env(env_logger::Env::new().default_filter_or("trace,mio=info"))
.init();
let addr = ("127.0.0.1", 8080);
info!("starting server on port: {}", &addr.0);
Server::build()
.bind(
"startup-fail",
addr,
2021-10-25 18:13:08 +01:00
fn_factory(|| async move {
if 1 > 2 {
Ok(fn_service(move |mut _stream: TcpStream| async move {
Ok::<u32, u32>(0)
}))
} else {
Err(42)
}
}),
)?
.workers(2)
.run()
.await
}