Skip to content

(edge-http) Server non-static handler #40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading