Struct tonic::transport::server::Router [−][src]
pub struct Router<A, B, L = Identity> { /* fields omitted */ }
Expand description
A stack based Service
router.
Implementations
impl<A, B, L> Router<A, B, L> where
A: Service<Request<Body>, Response = Response<BoxBody>> + Clone + Send + 'static,
A::Future: Send + 'static,
A::Error: Into<Box<dyn Error + Send + Sync>> + Send,
B: Service<Request<Body>, Response = Response<BoxBody>> + Clone + Send + 'static,
B::Future: Send + 'static,
B::Error: Into<Box<dyn Error + Send + Sync>> + Send,
impl<A, B, L> Router<A, B, L> where
A: Service<Request<Body>, Response = Response<BoxBody>> + Clone + Send + 'static,
A::Future: Send + 'static,
A::Error: Into<Box<dyn Error + Send + Sync>> + Send,
B: Service<Request<Body>, Response = Response<BoxBody>> + Clone + Send + 'static,
B::Future: Send + 'static,
B::Error: Into<Box<dyn Error + Send + Sync>> + Send,
Add a new service to this router.
pub fn add_optional_service<S>(
self,
svc: Option<S>
) -> Router<Either<S, Unimplemented>, Or<A, B, Request<Body>>, L> where
S: Service<Request<Body>, Response = Response<BoxBody>> + NamedService + Clone + Send + 'static,
S::Future: Send + 'static,
S::Error: Into<Box<dyn Error + Send + Sync>> + Send,
pub fn add_optional_service<S>(
self,
svc: Option<S>
) -> Router<Either<S, Unimplemented>, Or<A, B, Request<Body>>, L> where
S: Service<Request<Body>, Response = Response<BoxBody>> + NamedService + Clone + Send + 'static,
S::Future: Send + 'static,
S::Error: Into<Box<dyn Error + Send + Sync>> + Send,
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.
pub async fn serve<ResBody>(self, addr: SocketAddr) -> Result<(), Error> where
L: Layer<Routes<A, B, Request<Body>>>,
L::Service: Service<Request<Body>, Response = Response<ResBody>> + Clone + Send + 'static,
<<L as Layer<Routes<A, B, Request<Body>>>>::Service as Service<Request<Body>>>::Future: Send + 'static,
<<L as Layer<Routes<A, B, Request<Body>>>>::Service as Service<Request<Body>>>::Error: Into<Box<dyn Error + Send + Sync>> + Send,
ResBody: Body<Data = Bytes> + Send + Sync + 'static,
ResBody::Error: Into<Box<dyn Error + Send + Sync>>,
pub async fn serve<ResBody>(self, addr: SocketAddr) -> Result<(), Error> where
L: Layer<Routes<A, B, Request<Body>>>,
L::Service: Service<Request<Body>, Response = Response<ResBody>> + Clone + Send + 'static,
<<L as Layer<Routes<A, B, Request<Body>>>>::Service as Service<Request<Body>>>::Future: Send + 'static,
<<L as Layer<Routes<A, B, Request<Body>>>>::Service as Service<Request<Body>>>::Error: Into<Box<dyn Error + Send + Sync>> + Send,
ResBody: Body<Data = Bytes> + Send + Sync + '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<A, B, Request<Body>>>,
L::Service: Service<Request<Body>, Response = Response<ResBody>> + Clone + Send + 'static,
<<L as Layer<Routes<A, B, Request<Body>>>>::Service as Service<Request<Body>>>::Future: Send + 'static,
<<L as Layer<Routes<A, B, Request<Body>>>>::Service as Service<Request<Body>>>::Error: Into<Box<dyn Error + Send + Sync>> + Send,
ResBody: Body<Data = Bytes> + Send + Sync + '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<A, B, Request<Body>>>,
L::Service: Service<Request<Body>, Response = Response<ResBody>> + Clone + Send + 'static,
<<L as Layer<Routes<A, B, Request<Body>>>>::Service as Service<Request<Body>>>::Future: Send + 'static,
<<L as Layer<Routes<A, B, Request<Body>>>>::Service as Service<Request<Body>>>::Error: Into<Box<dyn Error + Send + Sync>> + Send,
ResBody: Body<Data = Bytes> + Send + Sync + '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<A, B, Request<Body>>>,
L::Service: Service<Request<Body>, Response = Response<ResBody>> + Clone + Send + 'static,
<<L as Layer<Routes<A, B, Request<Body>>>>::Service as Service<Request<Body>>>::Future: Send + 'static,
<<L as Layer<Routes<A, B, Request<Body>>>>::Service as Service<Request<Body>>>::Error: Into<Box<dyn Error + Send + Sync>> + Send,
ResBody: Body<Data = Bytes> + Send + Sync + '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<A, B, Request<Body>>>,
L::Service: Service<Request<Body>, Response = Response<ResBody>> + Clone + Send + 'static,
<<L as Layer<Routes<A, B, Request<Body>>>>::Service as Service<Request<Body>>>::Future: Send + 'static,
<<L as Layer<Routes<A, B, Request<Body>>>>::Service as Service<Request<Body>>>::Error: Into<Box<dyn Error + Send + Sync>> + Send,
ResBody: Body<Data = Bytes> + Send + Sync + 'static,
ResBody::Error: Into<Box<dyn Error + Send + Sync>>,
Consume this Server
creating a future that will execute the server on
the provided incoming stream of AsyncRead + AsyncWrite
.
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<A, B, Request<Body>>>,
L::Service: Service<Request<Body>, Response = Response<ResBody>> + Clone + Send + 'static,
<<L as Layer<Routes<A, B, Request<Body>>>>::Service as Service<Request<Body>>>::Future: Send + 'static,
<<L as Layer<Routes<A, B, Request<Body>>>>::Service as Service<Request<Body>>>::Error: Into<Box<dyn Error + Send + Sync>> + Send,
ResBody: Body<Data = Bytes> + Send + Sync + '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<A, B, Request<Body>>>,
L::Service: Service<Request<Body>, Response = Response<ResBody>> + Clone + Send + 'static,
<<L as Layer<Routes<A, B, Request<Body>>>>::Service as Service<Request<Body>>>::Future: Send + 'static,
<<L as Layer<Routes<A, B, Request<Body>>>>::Service as Service<Request<Body>>>::Error: Into<Box<dyn Error + Send + Sync>> + Send,
ResBody: Body<Data = Bytes> + Send + Sync + 'static,
ResBody::Error: Into<Box<dyn Error + Send + Sync>>,
Consume this Server
creating a future that will execute the server on
the provided incoming stream of AsyncRead + AsyncWrite
. Similar to
serve_with_shutdown
this method will also take a signal future to
gracefully shutdown the server.
pub fn into_service<ResBody>(self) -> RouterService<L::Service> where
L: Layer<Routes<A, B, Request<Body>>>,
L::Service: Service<Request<Body>, Response = Response<ResBody>> + Clone + Send + 'static,
<<L as Layer<Routes<A, B, Request<Body>>>>::Service as Service<Request<Body>>>::Future: Send + 'static,
<<L as Layer<Routes<A, B, Request<Body>>>>::Service as Service<Request<Body>>>::Error: Into<Box<dyn Error + Send + Sync>> + Send,
ResBody: Body<Data = Bytes> + Send + Sync + 'static,
ResBody::Error: Into<Box<dyn Error + Send + Sync>>,
pub fn into_service<ResBody>(self) -> RouterService<L::Service> where
L: Layer<Routes<A, B, Request<Body>>>,
L::Service: Service<Request<Body>, Response = Response<ResBody>> + Clone + Send + 'static,
<<L as Layer<Routes<A, B, Request<Body>>>>::Service as Service<Request<Body>>>::Future: Send + 'static,
<<L as Layer<Routes<A, B, Request<Body>>>>::Service as Service<Request<Body>>>::Error: Into<Box<dyn Error + Send + Sync>> + Send,
ResBody: Body<Data = Bytes> + Send + Sync + 'static,
ResBody::Error: Into<Box<dyn Error + Send + Sync>>,
Create a tower service out of a router.
Trait Implementations
Auto Trait Implementations
impl<A, B, L = Identity> !RefUnwindSafe for Router<A, B, L>
impl<A, B, L = Identity> !UnwindSafe for Router<A, B, L>
Blanket Implementations
Mutably borrows from an owned value. Read more
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more