Skip to content
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

feat(conn): impl Deref and DerefMut for http1 and http2 builders #98

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
76 changes: 27 additions & 49 deletions src/server/conn/auto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -493,12 +494,6 @@ pub struct Http1Builder<'a, E> {

#[cfg(feature = "http1")]
impl<E> 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
Expand Down Expand Up @@ -605,34 +600,21 @@ impl<E> Http1Builder<'_, E> {
self.inner.http1.timer(timer);
self
}
}

/// Bind a connection together with a [`Service`].
#[cfg(feature = "http2")]
pub async fn serve_connection<I, S, B>(&self, io: I, service: S) -> Result<()>
where
S: Service<Request<Incoming>, Response = Response<B>>,
S::Future: 'static,
S::Error: Into<Box<dyn StdError + Send + Sync>>,
B: Body + 'static,
B::Error: Into<Box<dyn StdError + Send + Sync>>,
I: Read + Write + Unpin + 'static,
E: HttpServerConnExec<S::Future, B>,
{
self.inner.serve_connection(io, service).await
#[cfg(feature = "http1")]
impl<'a, E> Deref for Http1Builder<'a, E> {
type Target = Builder<E>;

fn deref(&self) -> &Self::Target {
self.inner
}
}

/// Bind a connection together with a [`Service`].
#[cfg(not(feature = "http2"))]
pub async fn serve_connection<I, S, B>(&self, io: I, service: S) -> Result<()>
where
S: Service<Request<Incoming>, Response = Response<B>>,
S::Future: 'static,
S::Error: Into<Box<dyn StdError + Send + Sync>>,
B: Body + 'static,
B::Error: Into<Box<dyn StdError + Send + Sync>>,
I: Read + Write + Unpin + 'static,
{
self.inner.serve_connection(io, service).await
#[cfg(feature = "http1")]
impl<'a, E> DerefMut for Http1Builder<'a, E> {
fn deref_mut(&mut self) -> &mut Self::Target {
self.inner
}
}

Expand All @@ -644,12 +626,6 @@ pub struct Http2Builder<'a, E> {

#[cfg(feature = "http2")]
impl<E> 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.
///
Expand Down Expand Up @@ -768,19 +744,21 @@ impl<E> Http2Builder<'_, E> {
self.inner.http2.timer(timer);
self
}
}

/// Bind a connection together with a [`Service`].
pub async fn serve_connection<I, S, B>(&self, io: I, service: S) -> Result<()>
where
S: Service<Request<Incoming>, Response = Response<B>>,
S::Future: 'static,
S::Error: Into<Box<dyn StdError + Send + Sync>>,
B: Body + 'static,
B::Error: Into<Box<dyn StdError + Send + Sync>>,
I: Read + Write + Unpin + 'static,
E: HttpServerConnExec<S::Future, B>,
{
self.inner.serve_connection(io, service).await
#[cfg(feature = "http2")]
impl<'a, E> Deref for Http2Builder<'a, E> {
type Target = Builder<E>;

fn deref(&self) -> &Self::Target {
self.inner
}
}

#[cfg(feature = "http2")]
impl<'a, E> DerefMut for Http2Builder<'a, E> {
fn deref_mut(&mut self) -> &mut Self::Target {
self.inner
}
}

Expand Down
Loading