feat(server): Make the server code an optional feature (#2334)
				
					
				
			cc #2223 BREAKING CHANGE: The HTTP server code is now an optional feature. To enable the server, add `features = ["server"]` to the dependency in your `Cargo.toml`.
This commit is contained in:
		| @@ -3,17 +3,23 @@ use std::future::Future; | ||||
| use std::pin::Pin; | ||||
| use std::sync::Arc; | ||||
|  | ||||
| #[cfg(feature = "server")] | ||||
| use crate::body::{Body, HttpBody}; | ||||
| #[cfg(feature = "http2")] | ||||
| #[cfg(feature = "server")] | ||||
| use crate::proto::h2::server::H2Stream; | ||||
| use crate::rt::Executor; | ||||
| #[cfg(feature = "server")] | ||||
| use crate::server::conn::spawn_all::{NewSvcTask, Watcher}; | ||||
| #[cfg(feature = "server")] | ||||
| use crate::service::HttpService; | ||||
|  | ||||
| #[cfg(feature = "server")] | ||||
| pub trait ConnStreamExec<F, B: HttpBody>: Clone { | ||||
|     fn execute_h2stream(&mut self, fut: H2Stream<F, B>); | ||||
| } | ||||
|  | ||||
| #[cfg(feature = "server")] | ||||
| pub trait NewSvcExec<I, N, S: HttpService<Body>, E, W: Watcher<I, S, E>>: Clone { | ||||
|     fn execute_new_svc(&mut self, fut: NewSvcTask<I, N, S, E, W>); | ||||
| } | ||||
| @@ -60,6 +66,7 @@ impl fmt::Debug for Exec { | ||||
|     } | ||||
| } | ||||
|  | ||||
| #[cfg(feature = "server")] | ||||
| impl<F, B> ConnStreamExec<F, B> for Exec | ||||
| where | ||||
|     H2Stream<F, B>: Future<Output = ()> + Send + 'static, | ||||
| @@ -70,6 +77,7 @@ where | ||||
|     } | ||||
| } | ||||
|  | ||||
| #[cfg(feature = "server")] | ||||
| impl<I, N, S, E, W> NewSvcExec<I, N, S, E, W> for Exec | ||||
| where | ||||
|     NewSvcTask<I, N, S, E, W>: Future<Output = ()> + Send + 'static, | ||||
| @@ -83,6 +91,7 @@ where | ||||
|  | ||||
| // ==== impl Executor ===== | ||||
|  | ||||
| #[cfg(feature = "server")] | ||||
| impl<E, F, B> ConnStreamExec<F, B> for E | ||||
| where | ||||
|     E: Executor<H2Stream<F, B>> + Clone, | ||||
| @@ -94,6 +103,7 @@ where | ||||
|     } | ||||
| } | ||||
|  | ||||
| #[cfg(feature = "server")] | ||||
| impl<I, N, S, E, W> NewSvcExec<I, N, S, E, W> for E | ||||
| where | ||||
|     E: Executor<NewSvcTask<I, N, S, E, W>> + Clone, | ||||
| @@ -119,7 +129,7 @@ pub struct H2Stream<F, B>(std::marker::PhantomData<(F, B)>); | ||||
| impl<F, B, E> Future for H2Stream<F, B> | ||||
| where | ||||
|     F: Future<Output = Result<http::Response<B>, E>>, | ||||
|     B: HttpBody, | ||||
|     B: crate::body::HttpBody, | ||||
|     B::Error: Into<Box<dyn std::error::Error + Send + Sync>>, | ||||
|     E: Into<Box<dyn std::error::Error + Send + Sync>>, | ||||
| { | ||||
|   | ||||
| @@ -15,6 +15,7 @@ pub(crate) struct Rewind<T> { | ||||
|  | ||||
| impl<T> Rewind<T> { | ||||
|     #[cfg(any(feature = "http2", test))] | ||||
|     #[cfg(feature = "server")] | ||||
|     pub(crate) fn new(io: T) -> Self { | ||||
|         Rewind { | ||||
|             pre: None, | ||||
| @@ -29,7 +30,7 @@ impl<T> Rewind<T> { | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     #[cfg(any(all(feature = "http1", feature = "http2"), test))] | ||||
|     #[cfg(any(all(feature = "http1", feature = "http2", feature = "server"), test))] | ||||
|     pub(crate) fn rewind(&mut self, bs: Bytes) { | ||||
|         debug_assert!(self.pre.is_none()); | ||||
|         self.pre = Some(bs); | ||||
|   | ||||
| @@ -9,8 +9,10 @@ macro_rules! ready { | ||||
|  | ||||
| pub(crate) mod buf; | ||||
| #[cfg(any(feature = "http1", feature = "http2"))] | ||||
| #[cfg(feature = "server")] | ||||
| pub(crate) mod date; | ||||
| #[cfg(any(feature = "http1", feature = "http2"))] | ||||
| #[cfg(feature = "server")] | ||||
| pub(crate) mod drain; | ||||
| #[cfg(any(feature = "http1", feature = "http2"))] | ||||
| pub(crate) mod exec; | ||||
| @@ -24,8 +26,6 @@ pub(crate) mod sync_wrapper; | ||||
| pub(crate) mod task; | ||||
| pub(crate) mod watch; | ||||
|  | ||||
| //#[cfg(any(feature = "http1", feature = "http2"))] | ||||
| //pub(crate) use self::exec::{BoxSendFuture, Exec}; | ||||
| #[cfg(any(feature = "http1", feature = "http2"))] | ||||
| #[cfg(feature = "client")] | ||||
| pub(crate) use self::lazy::{lazy, Started as Lazy}; | ||||
| @@ -33,6 +33,7 @@ pub use self::never::Never; | ||||
| pub(crate) use self::task::Poll; | ||||
|  | ||||
| // group up types normally needed for `Future` | ||||
| #[cfg(any(feature = "http1", feature = "http2"))] | ||||
| pub(crate) use std::marker::Unpin; | ||||
| cfg_proto! { | ||||
|     pub(crate) use std::marker::Unpin; | ||||
| } | ||||
| pub(crate) use std::{future::Future, pin::Pin}; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user