Signed-off-by: Erik Hollensbe <linux@hollensbe.org>
This commit is contained in:
Erik Hollensbe
2022-01-21 00:08:39 -08:00
parent b9af85d0c1
commit 6226446239
5 changed files with 6 additions and 5 deletions
+1
View File
@@ -6,6 +6,7 @@ use tokio::net::TcpListener;
use crate::{handler::Handler, router::Router, Error, ServerError};
#[derive(Clone)]
pub struct App {
router: Router,
}
+3 -3
View File
@@ -6,13 +6,13 @@ use async_recursion::async_recursion;
use http::{Request, Response};
use hyper::Body;
pub(crate) type Params = BTreeMap<String, String>;
pub type Params = BTreeMap<String, String>;
pub type HandlerFunc = fn(
req: Request<Body>,
response: Option<Response<Body>>,
params: Params,
) -> PinBox<dyn Future<Output = HTTPResult> + Send + 'static>;
) -> PinBox<dyn Future<Output = HTTPResult> + Send>;
#[derive(Clone)]
pub struct Handler {
@@ -22,7 +22,7 @@ pub struct Handler {
impl Handler
where
Self: Send + 'static,
Self: Send,
{
pub fn new(handler: HandlerFunc, next: Option<Handler>) -> Self {
Self {
+1
View File
@@ -9,6 +9,7 @@ use std::pin::Pin;
pub(crate) type PinBox<F> = Pin<Box<F>>;
#[derive(Debug, Clone)]
pub struct ServerError(String);
impl<T> From<T> for ServerError
+1 -1
View File
@@ -2,7 +2,7 @@
macro_rules! compose_handler {
($( $x:path ),*) => {
{
use crate::handler::{HandlerFunc, Handler};
use $crate::handler::{HandlerFunc, Handler};
{
let mut funcs: Vec<HandlerFunc> = Vec::new();
-1
View File
@@ -67,7 +67,6 @@ impl Router {
self.clone()
}
#[allow(dead_code)]
pub(crate) async fn dispatch(&self, req: Request<Body>) -> Result<Response<Body>, Error> {
let path = req.uri().path().to_string();