You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Current state of affairs when it comes to building complex tower services makes it impossible to use generic tower-http layers when attempting to wrap individual grpc service with layer via ServiceBuilder due to NamedService requirement
Do you think it would be useful to add some sort of wrapper type that would allow to access individual NamedService from within Layered service?
The text was updated successfully, but these errors were encountered:
See #1893 you are able to work around it by calling into_router on the tonic route builder. If you have another use case that would make #1893 make more sense then let me know and I'd be happy to reopen it.
//! Utilities for tonic.use tonic::server::NamedService;use tower::{Layer,Service,ServiceBuilder};/// A helper function to create a layered service as in tonic one normally must/// apply a layer to all services.////// Tonic expects each service to implement the `NamedService` trait. Once a service is layered/// the trait is not implemented anymore.////// This function will automatically/// implement the `NamedService` trait for the layered service.pubfnlayered_service<L,S>(service:S,layer:L) -> LayeredService<<LasLayer<S>>::Service,S>whereS:NamedService,L:Layer<S>,{let service = ServiceBuilder::new().layer(layer).service(service);LayeredService{inner: service,_marker: std::marker::PhantomData::<S>,}}impl<S,I>NamedServiceforLayeredService<S,I>whereI:NamedService,{constNAME:&'static str = I::NAME;}/// A service that is wrapped in a layer.////// In tonic one can only add a layer that is applied to all services. This struct allows to add a layer to a single service.#[derive(Clone,Debug)]pubstructLayeredService<S,I>{inner:S,_marker: std::marker::PhantomData<I>,}impl<B,S,I>Service<hyper::Request<B>>forLayeredService<S,I>whereS:Service<hyper::Request<B>> + Clone,{typeResponse = S::Response;typeError = S::Error;typeFuture = S::Future;fnpoll_ready(&mutself,cx:&mut std::task::Context<'_>,) -> std::task::Poll<Result<(),Self::Error>>{self.inner.poll_ready(cx)}fncall(&mutself,req: hyper::Request<B>) -> Self::Future{self.inner.call(req)}}
Current state of affairs when it comes to building complex tower services makes it impossible to use generic tower-http layers when attempting to wrap individual grpc service with layer via ServiceBuilder due to
NamedService
requirementDo you think it would be useful to add some sort of wrapper type that would allow to access individual
NamedService
from within Layered service?The text was updated successfully, but these errors were encountered: