From 594052dc48acae9e303d4514c8b4c6a1047d77f2 Mon Sep 17 00:00:00 2001 From: David Pedersen Date: Tue, 10 Aug 2021 10:03:29 +0200 Subject: [PATCH] Revert hello_world example Accidentally changed it while testing something --- examples/hello_world.rs | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/examples/hello_world.rs b/examples/hello_world.rs index 91a28f68..bdb0a877 100644 --- a/examples/hello_world.rs +++ b/examples/hello_world.rs @@ -1,24 +1,26 @@ +//! Run with +//! +//! ```not_rust +//! cargo run --example hello_world +//! ``` + use axum::prelude::*; -use std::{convert::Infallible, net::SocketAddr, time::Duration}; -use tower::{limit::RateLimitLayer, BoxError, ServiceBuilder}; +use std::net::SocketAddr; #[tokio::main] async fn main() { - let handler_layer = ServiceBuilder::new() - .buffer(1024) - .layer(RateLimitLayer::new(10, Duration::from_secs(10))) - .into_inner(); + // Set the RUST_LOG, if it hasn't been explicitly defined + if std::env::var("RUST_LOG").is_err() { + std::env::set_var("RUST_LOG", "hello_world=debug") + } + tracing_subscriber::fmt::init(); - let app = route( - "/", - get(handler - .layer(handler_layer) - .handle_error(|error: BoxError| { - Ok::<_, Infallible>(format!("Unhandled error: {}", error)) - })), - ); + // build our application with a route + let app = route("/", get(handler)); + // run it let addr = SocketAddr::from(([127, 0, 0, 1], 3000)); + tracing::debug!("listening on {}", addr); axum::Server::bind(&addr) .serve(app.into_make_service()) .await