diff --git a/Cargo.toml b/Cargo.toml
index c41335ed..cd5983c0 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -67,7 +67,7 @@ sync_wrapper = "0.1.2"
thiserror = "1.0"
# router
-path-tree = "0.7"
+path-tree = "0.7.3"
# http
headers = "0.4"
diff --git a/examples/hello-world/src/main.rs b/examples/hello-world/src/main.rs
index 520de837..8114da12 100644
--- a/examples/hello-world/src/main.rs
+++ b/examples/hello-world/src/main.rs
@@ -1,7 +1,7 @@
#![deny(warnings)]
#![allow(clippy::unused_async)]
-use std::{net::SocketAddr, sync::Arc};
+use std::{net::SocketAddr, str::FromStr, sync::Arc};
use tokio::net::TcpListener;
use viz::{serve, Request, Result, Router, Tree};
@@ -11,16 +11,20 @@ async fn index(_: Request) -> Result<&'static str> {
#[tokio::main]
async fn main() -> Result<()> {
- let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
+ let addr = SocketAddr::from_str("[::1]:3000").unwrap();
let listener = TcpListener::bind(addr).await?;
println!("listening on http://{addr}");
- let app = Router::new().get("/", index);
+ let mut app = Router::new().get("/", |_| async { Ok("Hello, World!") });
+
+ for n in 0..1000 {
+ app = app.get(&format!("/{}", n), index);
+ }
+
let tree = Arc::new(Tree::from(app));
loop {
let (stream, addr) = listener.accept().await?;
- let tree = tree.clone();
- tokio::task::spawn(serve(stream, tree, Some(addr)));
+ tokio::task::spawn(serve(stream, tree.clone(), Some(addr)));
}
}
diff --git a/viz-core/src/handler.rs b/viz-core/src/handler.rs
index b817a150..5cdfd9d1 100644
--- a/viz-core/src/handler.rs
+++ b/viz-core/src/handler.rs
@@ -1,7 +1,9 @@
//! Traits and types for handling an HTTP.
-use crate::Future;
-use futures_util::future::BoxFuture;
+use crate::future::{BoxFuture, Future};
+
+mod cloneable;
+pub use cloneable::{BoxCloneable, Cloneable};
mod after;
pub use after::After;
@@ -71,8 +73,8 @@ pub trait Handler {
impl Handler for F
where
I: Send + 'static,
- F: Fn(I) -> Fut + ?Sized + Clone + Send + Sync + 'static,
- Fut: Future