Complete these tasks to reinforce what you learned in this module.
Create an AppState with a counter (e.g. AtomicU32 inside an Arc). Attach it to the router with .with_state(state). Add a GET / handler that uses State<AppState>, increments the counter, and returns the current count as a string. Run the server on port 3000.
Clone; wrap a counter in Arc so all clones share it. Attach state with .with_state(...). In the handler, use the State extractor and increment the counter (e.g. with an atomic).// Task 1: Shared state counter. See tasks/TASKS.md.
fn main() {
todo!("AppState with counter, with_state, handler");
}
Add tower_http::trace::TraceLayer::new_for_http() to the router with .layer(...). Use the same or a minimal route. Run and make a request; you should see trace output in the console.
.layer(...). The theory mentions TraceLayer for request logging; add it so the server logs requests.// Task 2: Add TraceLayer. See tasks/TASKS.md.
fn main() {
todo!("Router with TraceLayer::new_for_http()");
}