pub struct Router<L = Identity> { /* private fields */ }
Expand description
A stack based Service
router.
Implementations§
source§impl<L> Router<L>
impl<L> Router<L>
sourcepub fn add_service<S>(self, svc: S) -> Self
pub fn add_service<S>(self, svc: S) -> Self
Add a new service to this router.
sourcepub fn add_optional_service<S>(self, svc: Option<S>) -> Self
pub fn add_optional_service<S>(self, svc: Option<S>) -> Self
Add a new optional service to this router.
§Note
Even when the argument given is None
this will capture all requests to this service name.
As a result, one cannot use this to toggle between two identically named implementations.
sourcepub fn into_router(self) -> Router
👎Deprecated since 0.12.2: Use Routes::into_axum_router
instead.
pub fn into_router(self) -> Router
Routes::into_axum_router
instead.Convert this tonic Router
into an axum Router
consuming the tonic one.
sourcepub async fn serve<ResBody>(self, addr: SocketAddr) -> Result<(), Error>where
L: Layer<Routes> + Clone,
L::Service: Service<Request<BoxBody>, Response = Response<ResBody>> + Clone + Send + 'static,
<<L as Layer<Routes>>::Service as Service<Request<BoxBody>>>::Future: Send + 'static,
<<L as Layer<Routes>>::Service as Service<Request<BoxBody>>>::Error: Into<Box<dyn Error + Send + Sync>> + Send,
ResBody: Body<Data = Bytes> + Send + 'static,
ResBody::Error: Into<Box<dyn Error + Send + Sync>>,
pub async fn serve<ResBody>(self, addr: SocketAddr) -> Result<(), Error>where
L: Layer<Routes> + Clone,
L::Service: Service<Request<BoxBody>, Response = Response<ResBody>> + Clone + Send + 'static,
<<L as Layer<Routes>>::Service as Service<Request<BoxBody>>>::Future: Send + 'static,
<<L as Layer<Routes>>::Service as Service<Request<BoxBody>>>::Error: Into<Box<dyn Error + Send + Sync>> + Send,
ResBody: Body<Data = Bytes> + Send + 'static,
ResBody::Error: Into<Box<dyn Error + Send + Sync>>,
sourcepub async fn serve_with_shutdown<F: Future<Output = ()>, ResBody>(
self,
addr: SocketAddr,
signal: F,
) -> Result<(), Error>where
L: Layer<Routes>,
L::Service: Service<Request<BoxBody>, Response = Response<ResBody>> + Clone + Send + 'static,
<<L as Layer<Routes>>::Service as Service<Request<BoxBody>>>::Future: Send + 'static,
<<L as Layer<Routes>>::Service as Service<Request<BoxBody>>>::Error: Into<Box<dyn Error + Send + Sync>> + Send,
ResBody: Body<Data = Bytes> + Send + 'static,
ResBody::Error: Into<Box<dyn Error + Send + Sync>>,
pub async fn serve_with_shutdown<F: Future<Output = ()>, ResBody>(
self,
addr: SocketAddr,
signal: F,
) -> Result<(), Error>where
L: Layer<Routes>,
L::Service: Service<Request<BoxBody>, Response = Response<ResBody>> + Clone + Send + 'static,
<<L as Layer<Routes>>::Service as Service<Request<BoxBody>>>::Future: Send + 'static,
<<L as Layer<Routes>>::Service as Service<Request<BoxBody>>>::Error: Into<Box<dyn Error + Send + Sync>> + Send,
ResBody: Body<Data = Bytes> + Send + 'static,
ResBody::Error: Into<Box<dyn Error + Send + Sync>>,
sourcepub async fn serve_with_incoming<I, IO, IE, ResBody>(
self,
incoming: I,
) -> Result<(), Error>where
I: Stream<Item = Result<IO, IE>>,
IO: AsyncRead + AsyncWrite + Connected + Unpin + Send + 'static,
IO::ConnectInfo: Clone + Send + Sync + 'static,
IE: Into<Box<dyn Error + Send + Sync>>,
L: Layer<Routes>,
L::Service: Service<Request<BoxBody>, Response = Response<ResBody>> + Clone + Send + 'static,
<<L as Layer<Routes>>::Service as Service<Request<BoxBody>>>::Future: Send + 'static,
<<L as Layer<Routes>>::Service as Service<Request<BoxBody>>>::Error: Into<Box<dyn Error + Send + Sync>> + Send,
ResBody: Body<Data = Bytes> + Send + 'static,
ResBody::Error: Into<Box<dyn Error + Send + Sync>>,
pub async fn serve_with_incoming<I, IO, IE, ResBody>(
self,
incoming: I,
) -> Result<(), Error>where
I: Stream<Item = Result<IO, IE>>,
IO: AsyncRead + AsyncWrite + Connected + Unpin + Send + 'static,
IO::ConnectInfo: Clone + Send + Sync + 'static,
IE: Into<Box<dyn Error + Send + Sync>>,
L: Layer<Routes>,
L::Service: Service<Request<BoxBody>, Response = Response<ResBody>> + Clone + Send + 'static,
<<L as Layer<Routes>>::Service as Service<Request<BoxBody>>>::Future: Send + 'static,
<<L as Layer<Routes>>::Service as Service<Request<BoxBody>>>::Error: Into<Box<dyn Error + Send + Sync>> + Send,
ResBody: Body<Data = Bytes> + Send + 'static,
ResBody::Error: Into<Box<dyn Error + Send + Sync>>,
sourcepub async fn serve_with_incoming_shutdown<I, IO, IE, F, ResBody>(
self,
incoming: I,
signal: F,
) -> Result<(), Error>where
I: Stream<Item = Result<IO, IE>>,
IO: AsyncRead + AsyncWrite + Connected + Unpin + Send + 'static,
IO::ConnectInfo: Clone + Send + Sync + 'static,
IE: Into<Box<dyn Error + Send + Sync>>,
F: Future<Output = ()>,
L: Layer<Routes>,
L::Service: Service<Request<BoxBody>, Response = Response<ResBody>> + Clone + Send + 'static,
<<L as Layer<Routes>>::Service as Service<Request<BoxBody>>>::Future: Send + 'static,
<<L as Layer<Routes>>::Service as Service<Request<BoxBody>>>::Error: Into<Box<dyn Error + Send + Sync>> + Send,
ResBody: Body<Data = Bytes> + Send + 'static,
ResBody::Error: Into<Box<dyn Error + Send + Sync>>,
pub async fn serve_with_incoming_shutdown<I, IO, IE, F, ResBody>(
self,
incoming: I,
signal: F,
) -> Result<(), Error>where
I: Stream<Item = Result<IO, IE>>,
IO: AsyncRead + AsyncWrite + Connected + Unpin + Send + 'static,
IO::ConnectInfo: Clone + Send + Sync + 'static,
IE: Into<Box<dyn Error + Send + Sync>>,
F: Future<Output = ()>,
L: Layer<Routes>,
L::Service: Service<Request<BoxBody>, Response = Response<ResBody>> + Clone + Send + 'static,
<<L as Layer<Routes>>::Service as Service<Request<BoxBody>>>::Future: Send + 'static,
<<L as Layer<Routes>>::Service as Service<Request<BoxBody>>>::Error: Into<Box<dyn Error + Send + Sync>> + Send,
ResBody: Body<Data = Bytes> + Send + 'static,
ResBody::Error: Into<Box<dyn Error + Send + Sync>>,
sourcepub fn into_service<ResBody>(self) -> L::Servicewhere
L: Layer<Routes>,
L::Service: Service<Request<BoxBody>, Response = Response<ResBody>> + Clone + Send + 'static,
<<L as Layer<Routes>>::Service as Service<Request<BoxBody>>>::Future: Send + 'static,
<<L as Layer<Routes>>::Service as Service<Request<BoxBody>>>::Error: Into<Box<dyn Error + Send + Sync>> + Send,
ResBody: Body<Data = Bytes> + Send + 'static,
ResBody::Error: Into<Box<dyn Error + Send + Sync>>,
pub fn into_service<ResBody>(self) -> L::Servicewhere
L: Layer<Routes>,
L::Service: Service<Request<BoxBody>, Response = Response<ResBody>> + Clone + Send + 'static,
<<L as Layer<Routes>>::Service as Service<Request<BoxBody>>>::Future: Send + 'static,
<<L as Layer<Routes>>::Service as Service<Request<BoxBody>>>::Error: Into<Box<dyn Error + Send + Sync>> + Send,
ResBody: Body<Data = Bytes> + Send + 'static,
ResBody::Error: Into<Box<dyn Error + Send + Sync>>,
Create a tower service out of a router.
Trait Implementations§
Auto Trait Implementations§
impl<L> Freeze for Router<L>where
L: Freeze,
impl<L = Identity> !RefUnwindSafe for Router<L>
impl<L> Send for Router<L>where
L: Send,
impl<L> Sync for Router<L>where
L: Sync,
impl<L> Unpin for Router<L>where
L: Unpin,
impl<L = Identity> !UnwindSafe for Router<L>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T
in a tonic::Request