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

fix(build): Server service uses generic body bound #306

Merged
merged 2 commits into from
Mar 28, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions tonic-build/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub fn generate<'a, T: Service<'a>>(service: &'a T, context: &T::Context) -> Tok
}
}

impl<T: #server_trait> Service<http::Request<HyperBody>> for #server_service<T> {
impl<T: #server_trait> Service<http::Request<RequestBody>> for #server_service<T> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So instead of making this accept a BoxBody we actually want to make this generic over it. So we can do something like:

impl<T, B> Service<http::Request<B>> for #server_service<T>
where
	T: #server_trait,
	B: HttpBody + Send + Sync + 'static,
	B::Error: Into<StdError> + Send + 'static,
{ ... }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated ! Thanks a lot for your help

type Response = http::Response<tonic::body::BoxBody>;
type Error = Never;
type Future = BoxFuture<Self::Response, Self::Error>;
Expand All @@ -58,7 +58,7 @@ pub fn generate<'a, T: Service<'a>>(service: &'a T, context: &T::Context) -> Tok
Poll::Ready(Ok(()))
}

fn call(&mut self, req: http::Request<HyperBody>) -> Self::Future {
fn call(&mut self, req: http::Request<RequestBody>) -> Self::Future {
let inner = self.inner.clone();

match req.uri().path() {
Expand Down
4 changes: 3 additions & 1 deletion tonic/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ pub use tower_service::Service;
pub type StdError = Box<dyn std::error::Error + Send + Sync + 'static>;
pub use crate::body::Body;

#[cfg(not(feature = "transport"))]
pub use crate::body::BoxBody as RequestBody;
#[cfg(feature = "transport")]
pub use hyper::Body as HyperBody;
pub use hyper::Body as RequestBody;

pub type BoxFuture<T, E> = self::Pin<Box<dyn self::Future<Output = Result<T, E>> + Send + 'static>>;
pub type BoxStream<T> =
Expand Down