Fix examples (& also bugs with args in lib.rs)
I thought I was clever with Into<Handler> :(
This commit is contained in:
parent
4a0d07c2ca
commit
dc18bf2d1c
|
@ -19,7 +19,8 @@ async fn main() -> Result<()> {
|
|||
let users = Arc::<RwLock::<HashMap<CertBytes, String>>>::default();
|
||||
|
||||
Server::bind(("0.0.0.0", GEMINI_PORT))
|
||||
.serve(move|req| handle_request(users.clone(), req))
|
||||
.add_route("/", move|req| handle_request(users.clone(), req))
|
||||
.serve()
|
||||
.await
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,8 @@ async fn main() -> Result<()> {
|
|||
.init();
|
||||
|
||||
Server::bind(("localhost", GEMINI_PORT))
|
||||
.serve(handle_request)
|
||||
.add_route("/",handle_request)
|
||||
.serve()
|
||||
.await
|
||||
}
|
||||
|
||||
|
|
|
@ -11,7 +11,8 @@ async fn main() -> Result<()> {
|
|||
.init();
|
||||
|
||||
Server::bind(("localhost", GEMINI_PORT))
|
||||
.serve(handle_request)
|
||||
.add_route("/", handle_request)
|
||||
.serve()
|
||||
.await
|
||||
}
|
||||
|
||||
|
|
|
@ -290,12 +290,15 @@ impl<A: ToSocketAddrs> Builder<A> {
|
|||
/// "endpoint". Entering a relative or malformed path will result in a panic.
|
||||
///
|
||||
/// For more information about routing mechanics, see the docs for [`RoutingNode`].
|
||||
pub fn add_route(mut self, path: &'static str, handler: impl Into<Handler>) -> Self {
|
||||
self.routes.add_route(path, handler);
|
||||
pub fn add_route<H>(mut self, path: &'static str, handler: H) -> Self
|
||||
where
|
||||
H: Fn(Request) -> HandlerResponse + Send + Sync + 'static,
|
||||
{
|
||||
self.routes.add_route(path, Arc::new(handler));
|
||||
self
|
||||
}
|
||||
|
||||
pub async fn serve<F>(mut self) -> Result<()> {
|
||||
pub async fn serve(mut self) -> Result<()> {
|
||||
let config = tls_config(&self.cert_path, &self.key_path)
|
||||
.context("Failed to create TLS config")?;
|
||||
|
||||
|
|
|
@ -76,7 +76,7 @@ impl RoutingNode {
|
|||
/// static strings. If you would like to add a string dynamically, please use
|
||||
/// [`RoutingNode::add_route_by_path()`] in order to appropriately deal with any
|
||||
/// errors that might arise.
|
||||
pub fn add_route(&mut self, path: &'static str, handler: impl Into<Handler>) {
|
||||
pub fn add_route(&mut self, path: &'static str, handler: Handler) {
|
||||
let path: Path = path.try_into().expect("Malformed path route received");
|
||||
self.add_route_by_path(path, handler).unwrap();
|
||||
}
|
||||
|
@ -87,7 +87,7 @@ impl RoutingNode {
|
|||
/// this method.
|
||||
///
|
||||
/// For information about how routes work, see [`RoutingNode::match_path()`]
|
||||
pub fn add_route_by_path(&mut self, mut path: Path, handler: impl Into<Handler>) -> Result<(), ConflictingRouteError>{
|
||||
pub fn add_route_by_path(&mut self, mut path: Path, handler: Handler) -> Result<(), ConflictingRouteError>{
|
||||
debug_assert!(path.is_absolute());
|
||||
path.normalize(false);
|
||||
|
||||
|
@ -99,7 +99,7 @@ impl RoutingNode {
|
|||
if node.0.is_some() {
|
||||
Err(ConflictingRouteError())
|
||||
} else {
|
||||
node.0 = Some(handler.into());
|
||||
node.0 = Some(handler);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue