Don't force handlers to return Results

This commit is contained in:
David Pedersen
2021-05-31 20:42:57 +02:00
parent 6f5b2708d5
commit d33be9683c
6 changed files with 26 additions and 21 deletions
+3 -3
View File
@@ -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>")
}
+2 -2
View File
@@ -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
}
+3 -3
View File
@@ -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!"
}