use axum::{ response::{Html, IntoResponse}, routing::get, Router, }; use tokio::net::TcpListener; #[tokio::main] async fn main() -> Result<(), String> { let app = create_routes().await; let bind_addr = &"0.0.0.0:2900"; let listener = TcpListener::bind(bind_addr) .await .map_err(|e| format!("Failed to parse address: {}", e))?; axum::serve(listener, app.into_make_service()) .await .map_err(|e| format!("Server error: {}", e))?; Ok(()) } pub async fn create_routes() -> Router { Router::new() .route("/", get(index)) .route("/some", get(some)) } pub async fn index() -> impl IntoResponse { let content = r#"

Website index

Go to some page

"#; Html(content) } pub async fn some() -> impl IntoResponse { let hard: i64 = (1..=100).sum(); let easy: i64 = (1 + 100) * (100 / 2); let content = format!( r#"

Sum of all integer numbers from 1 to 100

The hard way: {}

The easy way: {}

Go to home page

"#, hard, easy ); Html(content) }