From 00cc15e1f40fe227064a0d012a8bac4a3f94fc37 Mon Sep 17 00:00:00 2001 From: Luca Barbato Date: Tue, 26 Dec 2023 14:28:27 +0100 Subject: [PATCH] feat!: Update to axum 0.7.2 --- Cargo.toml | 5 +++-- src/servient.rs | 6 ++++-- src/servient/builder.rs | 20 ++++++++++---------- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8d40896..8a93cf7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,12 +13,13 @@ mdns-sd = "0.10.1" thiserror = "1.0" if-addrs = "0.10.1" hostname = "0.3" -axum = "0.6.10" +axum = "0.7.2" serde = "1.0.141" serde_json = "1.0.83" uuid = { version = "1.1.2", features = ["v4"] } datta = "0.1" -tower-http = { version = "0.4.0", features = ["cors"] } +tower-http = { version = "0.5.0", features = ["cors"] } +tokio = { version = "1.20.1", features = ["net"] } [dev-dependencies] tokio = { version = "1.20.1", features = ["macros", "rt-multi-thread"] } diff --git a/src/servient.rs b/src/servient.rs index 1385f00..086a690 100644 --- a/src/servient.rs +++ b/src/servient.rs @@ -119,8 +119,10 @@ impl Servient { .port(self.http_addr.port()) .build()?; - axum::Server::bind(&self.http_addr) - .serve(self.router.clone().into_make_service()) + let listener = tokio::net::TcpListener::bind(&self.http_addr) + .await + .map_err(axum::Error::new)?; + axum::serve(listener, self.router.clone()) .await .map_err(axum::Error::new)?; diff --git a/src/servient/builder.rs b/src/servient/builder.rs index da7c8a2..0568138 100644 --- a/src/servient/builder.rs +++ b/src/servient/builder.rs @@ -249,27 +249,27 @@ pub trait HttpRouter { /// Route GET requests to the given handler. fn http_get(self, handler: H) -> Self::Target where - H: Handler, + H: Handler, T: 'static; /// Route PUT requests to the given handler. fn http_put(self, handler: H) -> Self::Target where - H: Handler, + H: Handler, T: 'static; /// Route POST requests to the given handler. fn http_post(self, handler: H) -> Self::Target where - H: Handler, + H: Handler, T: 'static; /// Route PATCH requests to the given handler. fn http_patch(self, handler: H) -> Self::Target where - H: Handler, + H: Handler, T: 'static; /// Route DELETE requests to the given handler. fn http_delete(self, handler: H) -> Self::Target where - H: Handler, + H: Handler, T: 'static; } @@ -375,7 +375,7 @@ where /// Route GET requests to the given handler. fn http_get(mut self, handler: H) -> Self::Target where - H: Handler, + H: Handler, T: 'static, { let method_router = std::mem::take(&mut self.other.field_mut().method_router); @@ -387,7 +387,7 @@ where /// Route PUT requests to the given handler. fn http_put(mut self, handler: H) -> Self::Target where - H: Handler, + H: Handler, T: 'static, { let method_router = std::mem::take(&mut self.other.field_mut().method_router); @@ -399,7 +399,7 @@ where /// Route POST requests to the given handler. fn http_post(mut self, handler: H) -> Self::Target where - H: Handler, + H: Handler, T: 'static, { let method_router = std::mem::take(&mut self.other.field_mut().method_router); @@ -411,7 +411,7 @@ where /// Route PATCH requests to the given handler. fn http_patch(mut self, handler: H) -> Self::Target where - H: Handler, + H: Handler, T: 'static, { let method_router = std::mem::take(&mut self.other.field_mut().method_router); @@ -423,7 +423,7 @@ where /// Route DELETE requests to the given handler. fn http_delete(mut self, handler: H) -> Self::Target where - H: Handler, + H: Handler, T: 'static, { let method_router = std::mem::take(&mut self.other.field_mut().method_router);