Skip to content

Commit

Permalink
(edge-http) Server non-static handler (#40)
Browse files Browse the repository at this point in the history
* Handlers with non-static socket factories

* embedded-svc compat
  • Loading branch information
ivmarkov authored Nov 4, 2024
1 parent 9e70ba0 commit 722f92a
Show file tree
Hide file tree
Showing 9 changed files with 183 additions and 165 deletions.
25 changes: 14 additions & 11 deletions edge-http/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ where
Ok(())
}

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

```rust
use core::fmt::Display;
use core::fmt::{Debug, Display};

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

struct HttpHandler;

impl<'b, T, const N: usize> Handler<'b, T, N> for HttpHandler
where
T: Read + Write,
{
type Error = Error<T::Error>;
impl Handler for HttpHandler {
type Error<E>
= Error<E>
where
E: Debug;

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

if headers.method != Method::Get {
Expand Down
8 changes: 4 additions & 4 deletions edge-http/src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ where
Ok((connection_type, body_type))
}

impl<'b, const N: usize> Headers<'b, N> {
impl<const N: usize> Headers<'_, N> {
fn resolve<E>(
&self,
carry_over_connection_type: Option<ConnectionType>,
Expand Down Expand Up @@ -497,7 +497,7 @@ where
type Error = Error<R::Error>;
}

impl<'b, R> Read for Body<'b, R>
impl<R> Read for Body<'_, R>
where
R: Read,
{
Expand Down Expand Up @@ -545,7 +545,7 @@ where
type Error = R::Error;
}

impl<'b, R> Read for PartiallyRead<'b, R>
impl<R> Read for PartiallyRead<'_, R>
where
R: Read,
{
Expand Down Expand Up @@ -824,7 +824,7 @@ where
type Error = Error<R::Error>;
}

impl<'b, R> Read for ChunkedRead<'b, R>
impl<R> Read for ChunkedRead<'_, R>
where
R: Read,
{
Expand Down
8 changes: 4 additions & 4 deletions edge-http/src/io/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ where
type Error = Error<T::Error>;
}

impl<'b, T, const N: usize> Read for Connection<'b, T, N>
impl<T, const N: usize> Read for Connection<'_, T, N>
where
T: TcpConnect,
{
Expand All @@ -410,7 +410,7 @@ where
}
}

impl<'b, T, const N: usize> Write for Connection<'b, T, N>
impl<T, const N: usize> Write for Connection<'_, T, N>
where
T: TcpConnect,
{
Expand Down Expand Up @@ -473,7 +473,7 @@ mod embedded_svc_compat {

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

impl<'b, T, const N: usize> Headers for super::Connection<'b, T, N>
impl<T, const N: usize> Headers for super::Connection<'_, T, N>
where
T: TcpConnect,
{
Expand All @@ -484,7 +484,7 @@ mod embedded_svc_compat {
}
}

impl<'b, T, const N: usize> Status for super::Connection<'b, T, N>
impl<T, const N: usize> Status for super::Connection<'_, T, N>
where
T: TcpConnect,
{
Expand Down
Loading

0 comments on commit 722f92a

Please sign in to comment.