mirror of
https://github.com/tokio-rs/axum.git
synced 2026-08-22 00:00:17 +02:00
Don't force handlers to return Results
This commit is contained in:
@@ -3,7 +3,7 @@ use hyper::Server;
|
||||
use std::net::SocketAddr;
|
||||
use tower::{make::Shared, ServiceBuilder};
|
||||
use tower_http::trace::TraceLayer;
|
||||
use tower_web::{body::Body, response::Html, Error};
|
||||
use tower_web::{body::Body, response::Html};
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
@@ -28,6 +28,6 @@ async fn main() {
|
||||
server.await.unwrap();
|
||||
}
|
||||
|
||||
async fn handler(_req: Request<Body>) -> Result<Html<&'static str>, Error> {
|
||||
Ok(Html("<h1>Hello, World!</h1>"))
|
||||
async fn handler(_req: Request<Body>) -> Html<&'static str> {
|
||||
Html("<h1>Hello, World!</h1>")
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ async fn set(
|
||||
params: extract::UrlParams<(String,)>,
|
||||
value: extract::BytesMaxLength<{ 1024 * 5_000 }>, // ~5mb
|
||||
state: extract::Extension<SharedState>,
|
||||
) -> Result<response::Empty, Error> {
|
||||
) -> response::Empty {
|
||||
let state = state.into_inner();
|
||||
let db = &mut state.lock().unwrap().db;
|
||||
|
||||
@@ -81,5 +81,5 @@ async fn set(
|
||||
|
||||
db.insert(key.to_string(), value);
|
||||
|
||||
Ok(response::Empty)
|
||||
response::Empty
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ use http::Request;
|
||||
use hyper::Server;
|
||||
use std::net::SocketAddr;
|
||||
use tower::make::Shared;
|
||||
use tower_web::{body::Body, Error};
|
||||
use tower_web::body::Body;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
@@ -227,6 +227,6 @@ async fn main() {
|
||||
server.await.unwrap();
|
||||
}
|
||||
|
||||
async fn handler(_req: Request<Body>) -> Result<&'static str, Error> {
|
||||
Ok("Hello, World!")
|
||||
async fn handler(_req: Request<Body>) -> &'static str {
|
||||
"Hello, World!"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user