From d91a9e5c16f6fc7f5417b15cf717752d82b27086 Mon Sep 17 00:00:00 2001 From: Programatik Date: Thu, 15 Feb 2024 20:14:53 +0300 Subject: [PATCH 1/3] impl Deref and DerefMut for http1 and http2 builders --- src/server/conn/auto.rs | 72 +++++++++++++---------------------------- 1 file changed, 23 insertions(+), 49 deletions(-) diff --git a/src/server/conn/auto.rs b/src/server/conn/auto.rs index ab29230c..3bed4e64 100644 --- a/src/server/conn/auto.rs +++ b/src/server/conn/auto.rs @@ -5,6 +5,7 @@ use hyper::service::HttpService; use std::future::Future; use std::marker::PhantomPinned; use std::mem::MaybeUninit; +use std::ops::{Deref, DerefMut}; use std::pin::Pin; use std::task::{Context, Poll}; use std::{error::Error as StdError, io, marker::Unpin, time::Duration}; @@ -493,12 +494,6 @@ pub struct Http1Builder<'a, E> { #[cfg(feature = "http1")] impl Http1Builder<'_, E> { - /// Http2 configuration. - #[cfg(feature = "http2")] - pub fn http2(&mut self) -> Http2Builder<'_, E> { - Http2Builder { inner: self.inner } - } - /// Set whether HTTP/1 connections should support half-closures. /// /// Clients can chose to shutdown their write-side while waiting @@ -605,34 +600,19 @@ impl Http1Builder<'_, E> { self.inner.http1.timer(timer); self } +} - /// Bind a connection together with a [`Service`]. - #[cfg(feature = "http2")] - pub async fn serve_connection(&self, io: I, service: S) -> Result<()> - where - S: Service, Response = Response>, - S::Future: 'static, - S::Error: Into>, - B: Body + 'static, - B::Error: Into>, - I: Read + Write + Unpin + 'static, - E: HttpServerConnExec, - { - self.inner.serve_connection(io, service).await +impl<'a, E> Deref for Http1Builder<'a, E> { + type Target = Builder; + + fn deref(&self) -> &Self::Target { + self.inner } +} - /// Bind a connection together with a [`Service`]. - #[cfg(not(feature = "http2"))] - pub async fn serve_connection(&self, io: I, service: S) -> Result<()> - where - S: Service, Response = Response>, - S::Future: 'static, - S::Error: Into>, - B: Body + 'static, - B::Error: Into>, - I: Read + Write + Unpin + 'static, - { - self.inner.serve_connection(io, service).await +impl<'a, E> DerefMut for Http1Builder<'a, E> { + fn deref_mut(&mut self) -> &mut Self::Target { + self.inner } } @@ -644,12 +624,6 @@ pub struct Http2Builder<'a, E> { #[cfg(feature = "http2")] impl Http2Builder<'_, E> { - #[cfg(feature = "http1")] - /// Http1 configuration. - pub fn http1(&mut self) -> Http1Builder<'_, E> { - Http1Builder { inner: self.inner } - } - /// Sets the [`SETTINGS_INITIAL_WINDOW_SIZE`][spec] option for HTTP2 /// stream-level flow control. /// @@ -768,19 +742,19 @@ impl Http2Builder<'_, E> { self.inner.http2.timer(timer); self } +} - /// Bind a connection together with a [`Service`]. - pub async fn serve_connection(&self, io: I, service: S) -> Result<()> - where - S: Service, Response = Response>, - S::Future: 'static, - S::Error: Into>, - B: Body + 'static, - B::Error: Into>, - I: Read + Write + Unpin + 'static, - E: HttpServerConnExec, - { - self.inner.serve_connection(io, service).await +impl<'a, E> Deref for Http2Builder<'a, E> { + type Target = Builder; + + fn deref(&self) -> &Self::Target { + self.inner + } +} + +impl<'a, E> DerefMut for Http2Builder<'a, E> { + fn deref_mut(&mut self) -> &mut Self::Target { + self.inner } } From 5adad132743e0970df21c02c5492bb4b89f710de Mon Sep 17 00:00:00 2001 From: Programatik Date: Thu, 15 Feb 2024 20:27:28 +0300 Subject: [PATCH 2/3] add feature flags for deref impls of http1 and http2 builders --- src/server/conn/auto.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/server/conn/auto.rs b/src/server/conn/auto.rs index 3bed4e64..d426cade 100644 --- a/src/server/conn/auto.rs +++ b/src/server/conn/auto.rs @@ -602,6 +602,7 @@ impl Http1Builder<'_, E> { } } +#[cfg(feature = "http1")] impl<'a, E> Deref for Http1Builder<'a, E> { type Target = Builder; @@ -610,6 +611,7 @@ impl<'a, E> Deref for Http1Builder<'a, E> { } } +#[cfg(feature = "http1")] impl<'a, E> DerefMut for Http1Builder<'a, E> { fn deref_mut(&mut self) -> &mut Self::Target { self.inner @@ -744,6 +746,7 @@ impl Http2Builder<'_, E> { } } +#[cfg(feature = "http2")] impl<'a, E> Deref for Http2Builder<'a, E> { type Target = Builder; @@ -752,6 +755,7 @@ impl<'a, E> Deref for Http2Builder<'a, E> { } } +#[cfg(feature = "http2")] impl<'a, E> DerefMut for Http2Builder<'a, E> { fn deref_mut(&mut self) -> &mut Self::Target { self.inner From 60450949666c162140490c11a3ddc2715eb06cdf Mon Sep 17 00:00:00 2001 From: Programatik Date: Thu, 15 Feb 2024 20:27:47 +0300 Subject: [PATCH 3/3] bump minor version for semver CI --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 610f3009..8222fb3e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hyper-util" -version = "0.1.3" +version = "0.2.0" description = "hyper utilities" readme = "README.md" homepage = "https://hyper.rs"