Skip to content

Commit 722f92a

Browse files
authored
(edge-http) Server non-static handler (#40)
* Handlers with non-static socket factories * embedded-svc compat
1 parent 9e70ba0 commit 722f92a

File tree

9 files changed

+183
-165
lines changed

9 files changed

+183
-165
lines changed

edge-http/README.md

+14-11
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ where
6868
Ok(())
6969
}
7070

71-
async fn request<'b, const N: usize, T: TcpConnect>(
72-
conn: &mut Connection<'b, T, N>,
71+
async fn request<const N: usize, T: TcpConnect>(
72+
conn: &mut Connection<'_, T, N>,
7373
uri: &str,
7474
) -> Result<(), Error<T::Error>> {
7575
conn.initiate_request(true, Method::Get, uri, &[("Host", "httpbin.org")])
@@ -103,7 +103,7 @@ async fn request<'b, const N: usize, T: TcpConnect>(
103103
### HTTP server
104104

105105
```rust
106-
use core::fmt::Display;
106+
use core::fmt::{Debug, Display};
107107

108108
use edge_http::io::server::{Connection, DefaultServer, Handler};
109109
use edge_http::io::Error;
@@ -140,17 +140,20 @@ pub async fn run(server: &mut DefaultServer) -> Result<(), anyhow::Error> {
140140

141141
struct HttpHandler;
142142

143-
impl<'b, T, const N: usize> Handler<'b, T, N> for HttpHandler
144-
where
145-
T: Read + Write,
146-
{
147-
type Error = Error<T::Error>;
143+
impl Handler for HttpHandler {
144+
type Error<E>
145+
= Error<E>
146+
where
147+
E: Debug;
148148

149-
async fn handle(
149+
async fn handle<T, const N: usize>(
150150
&self,
151151
_task_id: impl Display + Copy,
152-
conn: &mut Connection<'b, T, N>,
153-
) -> Result<(), Self::Error> {
152+
conn: &mut Connection<'_, T, N>,
153+
) -> Result<(), Self::Error<T::Error>>
154+
where
155+
T: Read + Write,
156+
{
154157
let headers = conn.headers()?;
155158

156159
if headers.method != Method::Get {

edge-http/src/io.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ where
373373
Ok((connection_type, body_type))
374374
}
375375

376-
impl<'b, const N: usize> Headers<'b, N> {
376+
impl<const N: usize> Headers<'_, N> {
377377
fn resolve<E>(
378378
&self,
379379
carry_over_connection_type: Option<ConnectionType>,
@@ -497,7 +497,7 @@ where
497497
type Error = Error<R::Error>;
498498
}
499499

500-
impl<'b, R> Read for Body<'b, R>
500+
impl<R> Read for Body<'_, R>
501501
where
502502
R: Read,
503503
{
@@ -545,7 +545,7 @@ where
545545
type Error = R::Error;
546546
}
547547

548-
impl<'b, R> Read for PartiallyRead<'b, R>
548+
impl<R> Read for PartiallyRead<'_, R>
549549
where
550550
R: Read,
551551
{
@@ -824,7 +824,7 @@ where
824824
type Error = Error<R::Error>;
825825
}
826826

827-
impl<'b, R> Read for ChunkedRead<'b, R>
827+
impl<R> Read for ChunkedRead<'_, R>
828828
where
829829
R: Read,
830830
{

edge-http/src/io/client.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ where
401401
type Error = Error<T::Error>;
402402
}
403403

404-
impl<'b, T, const N: usize> Read for Connection<'b, T, N>
404+
impl<T, const N: usize> Read for Connection<'_, T, N>
405405
where
406406
T: TcpConnect,
407407
{
@@ -410,7 +410,7 @@ where
410410
}
411411
}
412412

413-
impl<'b, T, const N: usize> Write for Connection<'b, T, N>
413+
impl<T, const N: usize> Write for Connection<'_, T, N>
414414
where
415415
T: TcpConnect,
416416
{
@@ -473,7 +473,7 @@ mod embedded_svc_compat {
473473

474474
use embedded_svc::http::client::asynch::{Connection, Headers, Method, Status};
475475

476-
impl<'b, T, const N: usize> Headers for super::Connection<'b, T, N>
476+
impl<T, const N: usize> Headers for super::Connection<'_, T, N>
477477
where
478478
T: TcpConnect,
479479
{
@@ -484,7 +484,7 @@ mod embedded_svc_compat {
484484
}
485485
}
486486

487-
impl<'b, T, const N: usize> Status for super::Connection<'b, T, N>
487+
impl<T, const N: usize> Status for super::Connection<'_, T, N>
488488
where
489489
T: TcpConnect,
490490
{

0 commit comments

Comments
 (0)