axum/examples/lots_of_routes.rs

233 lines
4.6 KiB
Rust
Raw Normal View History

2021-05-31 16:28:26 +02:00
use http::Request;
use hyper::Server;
use std::net::SocketAddr;
use tower::make::Shared;
use tower_web::body::Body;
2021-05-31 16:28:26 +02:00
#[tokio::main]
async fn main() {
// 100 routes should still compile in a reasonable amount of time
// add a .boxed() every 10 routes to improve compile times
let app = tower_web::app()
.at("/")
.get(handler)
.at("/")
.get(handler)
.at("/")
.get(handler)
.at("/")
.get(handler)
.at("/")
.get(handler)
.at("/")
.get(handler)
.at("/")
.get(handler)
.at("/")
.get(handler)
.at("/")
.get(handler)
.at("/")
.get(handler)
.boxed()
.at("/")
.get(handler)
.at("/")
.get(handler)
.at("/")
.get(handler)
.at("/")
.get(handler)
.at("/")
.get(handler)
.at("/")
.get(handler)
.at("/")
.get(handler)
.at("/")
.get(handler)
.at("/")
.get(handler)
.at("/")
.get(handler)
.boxed()
.at("/")
.get(handler)
.at("/")
.get(handler)
.at("/")
.get(handler)
.at("/")
.get(handler)
.at("/")
.get(handler)
.at("/")
.get(handler)
.at("/")
.get(handler)
.at("/")
.get(handler)
.at("/")
.get(handler)
.at("/")
.get(handler)
.boxed()
.at("/")
.get(handler)
.at("/")
.get(handler)
.at("/")
.get(handler)
.at("/")
.get(handler)
.at("/")
.get(handler)
.at("/")
.get(handler)
.at("/")
.get(handler)
.at("/")
.get(handler)
.at("/")
.get(handler)
.at("/")
.get(handler)
.boxed()
.at("/")
.get(handler)
.at("/")
.get(handler)
.at("/")
.get(handler)
.at("/")
.get(handler)
.at("/")
.get(handler)
.at("/")
.get(handler)
.at("/")
.get(handler)
.at("/")
.get(handler)
.at("/")
.get(handler)
.at("/")
.get(handler)
.boxed()
.at("/")
.get(handler)
.at("/")
.get(handler)
.at("/")
.get(handler)
.at("/")
.get(handler)
.at("/")
.get(handler)
.at("/")
.get(handler)
.at("/")
.get(handler)
.at("/")
.get(handler)
.at("/")
.get(handler)
.at("/")
.get(handler)
.boxed()
.at("/")
.get(handler)
.at("/")
.get(handler)
.at("/")
.get(handler)
.at("/")
.get(handler)
.at("/")
.get(handler)
.at("/")
.get(handler)
.at("/")
.get(handler)
.at("/")
.get(handler)
.at("/")
.get(handler)
.at("/")
.get(handler)
.boxed()
.at("/")
.get(handler)
.at("/")
.get(handler)
.at("/")
.get(handler)
.at("/")
.get(handler)
.at("/")
.get(handler)
.at("/")
.get(handler)
.at("/")
.get(handler)
.at("/")
.get(handler)
.at("/")
.get(handler)
.at("/")
.get(handler)
.boxed()
.at("/")
.get(handler)
.at("/")
.get(handler)
.at("/")
.get(handler)
.at("/")
.get(handler)
.at("/")
.get(handler)
.at("/")
.get(handler)
.at("/")
.get(handler)
.at("/")
.get(handler)
.at("/")
.get(handler)
.at("/")
.get(handler)
.boxed()
.at("/")
.get(handler)
.at("/")
.get(handler)
.at("/")
.get(handler)
.at("/")
.get(handler)
.at("/")
.get(handler)
.at("/")
.get(handler)
.at("/")
.get(handler)
.at("/")
.get(handler)
.at("/")
.get(handler)
.at("/")
.get(handler)
.boxed()
.into_service();
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
tracing::debug!("listening on {}", addr);
let server = Server::bind(&addr).serve(Shared::new(app));
server.await.unwrap();
}
async fn handler(_req: Request<Body>) -> &'static str {
"Hello, World!"
2021-05-31 16:28:26 +02:00
}