axum/examples/lots_of_routes.rs
David Pedersen f6b1a6f435 More work
2021-05-31 16:28:26 +02:00

232 lines
4.6 KiB
Rust

use http::Request;
use hyper::Server;
use std::net::SocketAddr;
use tower::make::Shared;
use tower_web::{body::Body, Error};
#[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>) -> Result<&'static str, Error> {
Ok("Hello, World!")
}