pub struct Router<A, B, L = Identity> { /* private fields */ }
Expand description
A stack based Service
router.
Implementations
sourceimpl<A, B, L> Router<A, B, L>where
A: 'static + Service<Request<Body>, Response = Response<UnsyncBoxBody<Bytes, Status>>> + Clone + Send,
<A as Service<Request<Body>>>::Future: 'static + Send,
<A as Service<Request<Body>>>::Error: Into<Box<dyn Error + Sync + Send + 'static, Global>> + Send,
B: 'static + Service<Request<Body>, Response = Response<UnsyncBoxBody<Bytes, Status>>> + Clone + Send,
<B as Service<Request<Body>>>::Future: 'static + Send,
<B as Service<Request<Body>>>::Error: Into<Box<dyn Error + Sync + Send + 'static, Global>> + Send,
impl<A, B, L> Router<A, B, L>where
A: 'static + Service<Request<Body>, Response = Response<UnsyncBoxBody<Bytes, Status>>> + Clone + Send,
<A as Service<Request<Body>>>::Future: 'static + Send,
<A as Service<Request<Body>>>::Error: Into<Box<dyn Error + Sync + Send + 'static, Global>> + Send,
B: 'static + Service<Request<Body>, Response = Response<UnsyncBoxBody<Bytes, Status>>> + Clone + Send,
<B as Service<Request<Body>>>::Future: 'static + Send,
<B as Service<Request<Body>>>::Error: Into<Box<dyn Error + Sync + Send + 'static, Global>> + Send,
sourcepub fn add_service<S>(self, svc: S) -> Router<S, Or<A, B, Request<Body>>, L>where
S: 'static + Service<Request<Body>, Response = Response<UnsyncBoxBody<Bytes, Status>>> + NamedService + Clone + Send,
<S as Service<Request<Body>>>::Future: 'static + Send,
<S as Service<Request<Body>>>::Error: Into<Box<dyn Error + Sync + Send + 'static, Global>> + Send,
pub fn add_service<S>(self, svc: S) -> Router<S, Or<A, B, Request<Body>>, L>where
S: 'static + Service<Request<Body>, Response = Response<UnsyncBoxBody<Bytes, Status>>> + NamedService + Clone + Send,
<S as Service<Request<Body>>>::Future: 'static + Send,
<S as Service<Request<Body>>>::Error: Into<Box<dyn Error + Sync + Send + 'static, Global>> + Send,
Add a new service to this router.
sourcepub fn add_optional_service<S>(
self,
svc: Option<S>
) -> Router<Either<S, Unimplemented>, Or<A, B, Request<Body>>, L>where
S: 'static + Service<Request<Body>, Response = Response<UnsyncBoxBody<Bytes, Status>>> + NamedService + Clone + Send,
<S as Service<Request<Body>>>::Future: 'static + Send,
<S as Service<Request<Body>>>::Error: Into<Box<dyn Error + Sync + Send + 'static, Global>> + Send,
pub fn add_optional_service<S>(
self,
svc: Option<S>
) -> Router<Either<S, Unimplemented>, Or<A, B, Request<Body>>, L>where
S: 'static + Service<Request<Body>, Response = Response<UnsyncBoxBody<Bytes, Status>>> + NamedService + Clone + Send,
<S as Service<Request<Body>>>::Future: 'static + Send,
<S as Service<Request<Body>>>::Error: Into<Box<dyn Error + Sync + Send + 'static, Global>> + 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.
sourcepub async fn serve<ResBody>(
self,
addr: SocketAddr
) -> impl Future<Output = Result<(), Error>>where
L: Layer<Routes<A, B, Request<Body>>>,
<L as Layer<Routes<A, B, Request<Body>>>>::Service: 'static + Service<Request<Body>, Response = Response<ResBody>> + Clone + Send,
<<L as Layer<Routes<A, B, Request<Body>>>>::Service as Service<Request<Body>>>::Future: 'static + Send,
<<L as Layer<Routes<A, B, Request<Body>>>>::Service as Service<Request<Body>>>::Error: Into<Box<dyn Error + Sync + Send + 'static, Global>> + Send,
ResBody: 'static + Body<Data = Bytes> + Send,
<ResBody as Body>::Error: Into<Box<dyn Error + Sync + Send + 'static, Global>>,
pub async fn serve<ResBody>(
self,
addr: SocketAddr
) -> impl Future<Output = Result<(), Error>>where
L: Layer<Routes<A, B, Request<Body>>>,
<L as Layer<Routes<A, B, Request<Body>>>>::Service: 'static + Service<Request<Body>, Response = Response<ResBody>> + Clone + Send,
<<L as Layer<Routes<A, B, Request<Body>>>>::Service as Service<Request<Body>>>::Future: 'static + Send,
<<L as Layer<Routes<A, B, Request<Body>>>>::Service as Service<Request<Body>>>::Error: Into<Box<dyn Error + Sync + Send + 'static, Global>> + Send,
ResBody: 'static + Body<Data = Bytes> + Send,
<ResBody as Body>::Error: Into<Box<dyn Error + Sync + Send + 'static, Global>>,
sourcepub async fn serve_with_shutdown<F, ResBody>(
self,
addr: SocketAddr,
signal: F
) -> impl Future<Output = Result<(), Error>>where
F: Future<Output = ()>,
L: Layer<Routes<A, B, Request<Body>>>,
<L as Layer<Routes<A, B, Request<Body>>>>::Service: 'static + Service<Request<Body>, Response = Response<ResBody>> + Clone + Send,
<<L as Layer<Routes<A, B, Request<Body>>>>::Service as Service<Request<Body>>>::Future: 'static + Send,
<<L as Layer<Routes<A, B, Request<Body>>>>::Service as Service<Request<Body>>>::Error: Into<Box<dyn Error + Sync + Send + 'static, Global>> + Send,
ResBody: 'static + Body<Data = Bytes> + Send,
<ResBody as Body>::Error: Into<Box<dyn Error + Sync + Send + 'static, Global>>,
pub async fn serve_with_shutdown<F, ResBody>(
self,
addr: SocketAddr,
signal: F
) -> impl Future<Output = Result<(), Error>>where
F: Future<Output = ()>,
L: Layer<Routes<A, B, Request<Body>>>,
<L as Layer<Routes<A, B, Request<Body>>>>::Service: 'static + Service<Request<Body>, Response = Response<ResBody>> + Clone + Send,
<<L as Layer<Routes<A, B, Request<Body>>>>::Service as Service<Request<Body>>>::Future: 'static + Send,
<<L as Layer<Routes<A, B, Request<Body>>>>::Service as Service<Request<Body>>>::Error: Into<Box<dyn Error + Sync + Send + 'static, Global>> + Send,
ResBody: 'static + Body<Data = Bytes> + Send,
<ResBody as Body>::Error: Into<Box<dyn Error + Sync + Send + 'static, Global>>,
sourcepub async fn serve_with_incoming<I, IO, IE, ResBody>(
self,
incoming: I
) -> impl Future<Output = Result<(), Error>>where
I: Stream<Item = Result<IO, IE>>,
IO: 'static + AsyncRead + AsyncWrite + Connected + Unpin + Send,
<IO as Connected>::ConnectInfo: 'static + Clone + Send + Sync,
IE: Into<Box<dyn Error + Sync + Send + 'static, Global>>,
L: Layer<Routes<A, B, Request<Body>>>,
<L as Layer<Routes<A, B, Request<Body>>>>::Service: 'static + Service<Request<Body>, Response = Response<ResBody>> + Clone + Send,
<<L as Layer<Routes<A, B, Request<Body>>>>::Service as Service<Request<Body>>>::Future: 'static + Send,
<<L as Layer<Routes<A, B, Request<Body>>>>::Service as Service<Request<Body>>>::Error: Into<Box<dyn Error + Sync + Send + 'static, Global>> + Send,
ResBody: 'static + Body<Data = Bytes> + Send,
<ResBody as Body>::Error: Into<Box<dyn Error + Sync + Send + 'static, Global>>,
pub async fn serve_with_incoming<I, IO, IE, ResBody>(
self,
incoming: I
) -> impl Future<Output = Result<(), Error>>where
I: Stream<Item = Result<IO, IE>>,
IO: 'static + AsyncRead + AsyncWrite + Connected + Unpin + Send,
<IO as Connected>::ConnectInfo: 'static + Clone + Send + Sync,
IE: Into<Box<dyn Error + Sync + Send + 'static, Global>>,
L: Layer<Routes<A, B, Request<Body>>>,
<L as Layer<Routes<A, B, Request<Body>>>>::Service: 'static + Service<Request<Body>, Response = Response<ResBody>> + Clone + Send,
<<L as Layer<Routes<A, B, Request<Body>>>>::Service as Service<Request<Body>>>::Future: 'static + Send,
<<L as Layer<Routes<A, B, Request<Body>>>>::Service as Service<Request<Body>>>::Error: Into<Box<dyn Error + Sync + Send + 'static, Global>> + Send,
ResBody: 'static + Body<Data = Bytes> + Send,
<ResBody as Body>::Error: Into<Box<dyn Error + Sync + Send + 'static, Global>>,
Consume this Server
creating a future that will execute the server on
the provided incoming stream of AsyncRead + AsyncWrite
.
sourcepub async fn serve_with_incoming_shutdown<I, IO, IE, F, ResBody>(
self,
incoming: I,
signal: F
) -> impl Future<Output = Result<(), Error>>where
I: Stream<Item = Result<IO, IE>>,
IO: 'static + AsyncRead + AsyncWrite + Connected + Unpin + Send,
<IO as Connected>::ConnectInfo: 'static + Clone + Send + Sync,
IE: Into<Box<dyn Error + Sync + Send + 'static, Global>>,
F: Future<Output = ()>,
L: Layer<Routes<A, B, Request<Body>>>,
<L as Layer<Routes<A, B, Request<Body>>>>::Service: 'static + Service<Request<Body>, Response = Response<ResBody>> + Clone + Send,
<<L as Layer<Routes<A, B, Request<Body>>>>::Service as Service<Request<Body>>>::Future: 'static + Send,
<<L as Layer<Routes<A, B, Request<Body>>>>::Service as Service<Request<Body>>>::Error: Into<Box<dyn Error + Sync + Send + 'static, Global>> + Send,
ResBody: 'static + Body<Data = Bytes> + Send,
<ResBody as Body>::Error: Into<Box<dyn Error + Sync + Send + 'static, Global>>,
pub async fn serve_with_incoming_shutdown<I, IO, IE, F, ResBody>(
self,
incoming: I,
signal: F
) -> impl Future<Output = Result<(), Error>>where
I: Stream<Item = Result<IO, IE>>,
IO: 'static + AsyncRead + AsyncWrite + Connected + Unpin + Send,
<IO as Connected>::ConnectInfo: 'static + Clone + Send + Sync,
IE: Into<Box<dyn Error + Sync + Send + 'static, Global>>,
F: Future<Output = ()>,
L: Layer<Routes<A, B, Request<Body>>>,
<L as Layer<Routes<A, B, Request<Body>>>>::Service: 'static + Service<Request<Body>, Response = Response<ResBody>> + Clone + Send,
<<L as Layer<Routes<A, B, Request<Body>>>>::Service as Service<Request<Body>>>::Future: 'static + Send,
<<L as Layer<Routes<A, B, Request<Body>>>>::Service as Service<Request<Body>>>::Error: Into<Box<dyn Error + Sync + Send + 'static, Global>> + Send,
ResBody: 'static + Body<Data = Bytes> + Send,
<ResBody as Body>::Error: Into<Box<dyn Error + Sync + Send + 'static, Global>>,
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.
sourcepub fn into_service<ResBody>(
self
) -> RouterService<<L as Layer<Routes<A, B, Request<Body>>>>::Service>where
L: Layer<Routes<A, B, Request<Body>>>,
<L as Layer<Routes<A, B, Request<Body>>>>::Service: 'static + Service<Request<Body>, Response = Response<ResBody>> + Clone + Send,
<<L as Layer<Routes<A, B, Request<Body>>>>::Service as Service<Request<Body>>>::Future: 'static + Send,
<<L as Layer<Routes<A, B, Request<Body>>>>::Service as Service<Request<Body>>>::Error: Into<Box<dyn Error + Sync + Send + 'static, Global>> + Send,
ResBody: 'static + Body<Data = Bytes> + Send,
<ResBody as Body>::Error: Into<Box<dyn Error + Sync + Send + 'static, Global>>,
pub fn into_service<ResBody>(
self
) -> RouterService<<L as Layer<Routes<A, B, Request<Body>>>>::Service>where
L: Layer<Routes<A, B, Request<Body>>>,
<L as Layer<Routes<A, B, Request<Body>>>>::Service: 'static + Service<Request<Body>, Response = Response<ResBody>> + Clone + Send,
<<L as Layer<Routes<A, B, Request<Body>>>>::Service as Service<Request<Body>>>::Future: 'static + Send,
<<L as Layer<Routes<A, B, Request<Body>>>>::Service as Service<Request<Body>>>::Error: Into<Box<dyn Error + Sync + Send + 'static, Global>> + Send,
ResBody: 'static + Body<Data = Bytes> + Send,
<ResBody as Body>::Error: Into<Box<dyn Error + Sync + Send + 'static, Global>>,
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> Send for Router<A, B, L>where
A: Send,
B: Send,
L: Send,
impl<A, B, L> Sync for Router<A, B, L>where
A: Sync,
B: Sync,
L: Sync,
impl<A, B, L> Unpin for Router<A, B, L>where
A: Unpin,
B: Unpin,
L: Unpin,
impl<A, B, L = Identity> !UnwindSafe for Router<A, B, L>
Blanket Implementations
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstablefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
sourcefn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T
in a tonic::Request