pub struct Router<L = Identity> { /* private fields */ }
Expand description
A stack based Service
router.
Implementations
sourceimpl<L> Router<L>
impl<L> Router<L>
sourcepub fn add_service<S>(self, svc: S) -> Router<L> where
S: 'static + Service<Request<Body>, Response = Response<UnsyncBoxBody<Bytes, Status>>, Error = Infallible> + NamedService + Clone + Send,
<S as Service<Request<Body>>>::Future: 'static,
<S as Service<Request<Body>>>::Future: Send,
pub fn add_service<S>(self, svc: S) -> Router<L> where
S: 'static + Service<Request<Body>, Response = Response<UnsyncBoxBody<Bytes, Status>>, Error = Infallible> + NamedService + Clone + Send,
<S as Service<Request<Body>>>::Future: 'static,
<S as Service<Request<Body>>>::Future: Send,
Add a new service to this router.
sourcepub fn add_optional_service<S>(self, svc: Option<S>) -> Router<L> where
S: 'static + Service<Request<Body>, Response = Response<UnsyncBoxBody<Bytes, Status>>, Error = Infallible> + NamedService + Clone + Send,
<S as Service<Request<Body>>>::Future: 'static,
<S as Service<Request<Body>>>::Future: Send,
pub fn add_optional_service<S>(self, svc: Option<S>) -> Router<L> where
S: 'static + Service<Request<Body>, Response = Response<UnsyncBoxBody<Bytes, Status>>, Error = Infallible> + NamedService + Clone + Send,
<S as Service<Request<Body>>>::Future: 'static,
<S as Service<Request<Body>>>::Future: 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) -> Result<(), Error> where
L: Layer<Routes>,
ResBody: 'static + Body<Data = Bytes> + Send,
<L as Layer<Routes>>::Service: 'static,
<L as Layer<Routes>>::Service: Service<Request<Body>>,
<L as Layer<Routes>>::Service: Clone,
<L as Layer<Routes>>::Service: Send,
<<L as Layer<Routes>>::Service as Service<Request<Body>>>::Future: 'static,
<<L as Layer<Routes>>::Service as Service<Request<Body>>>::Future: Send,
<<L as Layer<Routes>>::Service as Service<Request<Body>>>::Error: Into<Box<dyn Error + Send + Sync + 'static, Global>>,
<<L as Layer<Routes>>::Service as Service<Request<Body>>>::Error: Send,
<ResBody as Body>::Error: Into<Box<dyn Error + Send + Sync + 'static, Global>>,
<<L as Layer<Routes>>::Service as Service<Request<Body>>>::Response == Response<ResBody>,
pub async fn serve<ResBody>(self, addr: SocketAddr) -> Result<(), Error> where
L: Layer<Routes>,
ResBody: 'static + Body<Data = Bytes> + Send,
<L as Layer<Routes>>::Service: 'static,
<L as Layer<Routes>>::Service: Service<Request<Body>>,
<L as Layer<Routes>>::Service: Clone,
<L as Layer<Routes>>::Service: Send,
<<L as Layer<Routes>>::Service as Service<Request<Body>>>::Future: 'static,
<<L as Layer<Routes>>::Service as Service<Request<Body>>>::Future: Send,
<<L as Layer<Routes>>::Service as Service<Request<Body>>>::Error: Into<Box<dyn Error + Send + Sync + 'static, Global>>,
<<L as Layer<Routes>>::Service as Service<Request<Body>>>::Error: Send,
<ResBody as Body>::Error: Into<Box<dyn Error + Send + Sync + 'static, Global>>,
<<L as Layer<Routes>>::Service as Service<Request<Body>>>::Response == Response<ResBody>,
sourcepub async fn serve_with_shutdown<F, ResBody>(
self,
addr: SocketAddr,
signal: F
) -> Result<(), Error> where
F: Future<Output = ()>,
L: Layer<Routes>,
ResBody: 'static + Body<Data = Bytes> + Send,
<L as Layer<Routes>>::Service: 'static,
<L as Layer<Routes>>::Service: Service<Request<Body>>,
<L as Layer<Routes>>::Service: Clone,
<L as Layer<Routes>>::Service: Send,
<<L as Layer<Routes>>::Service as Service<Request<Body>>>::Future: 'static,
<<L as Layer<Routes>>::Service as Service<Request<Body>>>::Future: Send,
<<L as Layer<Routes>>::Service as Service<Request<Body>>>::Error: Into<Box<dyn Error + Send + Sync + 'static, Global>>,
<<L as Layer<Routes>>::Service as Service<Request<Body>>>::Error: Send,
<ResBody as Body>::Error: Into<Box<dyn Error + Send + Sync + 'static, Global>>,
<<L as Layer<Routes>>::Service as Service<Request<Body>>>::Response == Response<ResBody>,
pub async fn serve_with_shutdown<F, ResBody>(
self,
addr: SocketAddr,
signal: F
) -> Result<(), Error> where
F: Future<Output = ()>,
L: Layer<Routes>,
ResBody: 'static + Body<Data = Bytes> + Send,
<L as Layer<Routes>>::Service: 'static,
<L as Layer<Routes>>::Service: Service<Request<Body>>,
<L as Layer<Routes>>::Service: Clone,
<L as Layer<Routes>>::Service: Send,
<<L as Layer<Routes>>::Service as Service<Request<Body>>>::Future: 'static,
<<L as Layer<Routes>>::Service as Service<Request<Body>>>::Future: Send,
<<L as Layer<Routes>>::Service as Service<Request<Body>>>::Error: Into<Box<dyn Error + Send + Sync + 'static, Global>>,
<<L as Layer<Routes>>::Service as Service<Request<Body>>>::Error: Send,
<ResBody as Body>::Error: Into<Box<dyn Error + Send + Sync + 'static, Global>>,
<<L as Layer<Routes>>::Service as Service<Request<Body>>>::Response == Response<ResBody>,
sourcepub async fn serve_with_incoming<I, IO, IE, ResBody>(
self,
incoming: I
) -> Result<(), Error> where
I: Stream<Item = Result<IO, IE>>,
IO: 'static + AsyncRead + AsyncWrite + Connected + Unpin + Send,
IE: Into<Box<dyn Error + Send + Sync + 'static, Global>>,
L: Layer<Routes>,
ResBody: 'static + Body<Data = Bytes> + Send,
<IO as Connected>::ConnectInfo: 'static,
<IO as Connected>::ConnectInfo: Clone,
<IO as Connected>::ConnectInfo: Send,
<IO as Connected>::ConnectInfo: Sync,
<L as Layer<Routes>>::Service: 'static,
<L as Layer<Routes>>::Service: Service<Request<Body>>,
<L as Layer<Routes>>::Service: Clone,
<L as Layer<Routes>>::Service: Send,
<<L as Layer<Routes>>::Service as Service<Request<Body>>>::Future: 'static,
<<L as Layer<Routes>>::Service as Service<Request<Body>>>::Future: Send,
<<L as Layer<Routes>>::Service as Service<Request<Body>>>::Error: Into<Box<dyn Error + Send + Sync + 'static, Global>>,
<<L as Layer<Routes>>::Service as Service<Request<Body>>>::Error: Send,
<ResBody as Body>::Error: Into<Box<dyn Error + Send + Sync + 'static, Global>>,
<<L as Layer<Routes>>::Service as Service<Request<Body>>>::Response == Response<ResBody>,
pub async fn serve_with_incoming<I, IO, IE, ResBody>(
self,
incoming: I
) -> Result<(), Error> where
I: Stream<Item = Result<IO, IE>>,
IO: 'static + AsyncRead + AsyncWrite + Connected + Unpin + Send,
IE: Into<Box<dyn Error + Send + Sync + 'static, Global>>,
L: Layer<Routes>,
ResBody: 'static + Body<Data = Bytes> + Send,
<IO as Connected>::ConnectInfo: 'static,
<IO as Connected>::ConnectInfo: Clone,
<IO as Connected>::ConnectInfo: Send,
<IO as Connected>::ConnectInfo: Sync,
<L as Layer<Routes>>::Service: 'static,
<L as Layer<Routes>>::Service: Service<Request<Body>>,
<L as Layer<Routes>>::Service: Clone,
<L as Layer<Routes>>::Service: Send,
<<L as Layer<Routes>>::Service as Service<Request<Body>>>::Future: 'static,
<<L as Layer<Routes>>::Service as Service<Request<Body>>>::Future: Send,
<<L as Layer<Routes>>::Service as Service<Request<Body>>>::Error: Into<Box<dyn Error + Send + Sync + 'static, Global>>,
<<L as Layer<Routes>>::Service as Service<Request<Body>>>::Error: Send,
<ResBody as Body>::Error: Into<Box<dyn Error + Send + Sync + 'static, Global>>,
<<L as Layer<Routes>>::Service as Service<Request<Body>>>::Response == Response<ResBody>,
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
) -> Result<(), Error> where
I: Stream<Item = Result<IO, IE>>,
IO: 'static + AsyncRead + AsyncWrite + Connected + Unpin + Send,
IE: Into<Box<dyn Error + Send + Sync + 'static, Global>>,
F: Future<Output = ()>,
L: Layer<Routes>,
ResBody: 'static + Body<Data = Bytes> + Send,
<IO as Connected>::ConnectInfo: 'static,
<IO as Connected>::ConnectInfo: Clone,
<IO as Connected>::ConnectInfo: Send,
<IO as Connected>::ConnectInfo: Sync,
<L as Layer<Routes>>::Service: 'static,
<L as Layer<Routes>>::Service: Service<Request<Body>>,
<L as Layer<Routes>>::Service: Clone,
<L as Layer<Routes>>::Service: Send,
<<L as Layer<Routes>>::Service as Service<Request<Body>>>::Future: 'static,
<<L as Layer<Routes>>::Service as Service<Request<Body>>>::Future: Send,
<<L as Layer<Routes>>::Service as Service<Request<Body>>>::Error: Into<Box<dyn Error + Send + Sync + 'static, Global>>,
<<L as Layer<Routes>>::Service as Service<Request<Body>>>::Error: Send,
<ResBody as Body>::Error: Into<Box<dyn Error + Send + Sync + 'static, Global>>,
<<L as Layer<Routes>>::Service as Service<Request<Body>>>::Response == Response<ResBody>,
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: 'static + AsyncRead + AsyncWrite + Connected + Unpin + Send,
IE: Into<Box<dyn Error + Send + Sync + 'static, Global>>,
F: Future<Output = ()>,
L: Layer<Routes>,
ResBody: 'static + Body<Data = Bytes> + Send,
<IO as Connected>::ConnectInfo: 'static,
<IO as Connected>::ConnectInfo: Clone,
<IO as Connected>::ConnectInfo: Send,
<IO as Connected>::ConnectInfo: Sync,
<L as Layer<Routes>>::Service: 'static,
<L as Layer<Routes>>::Service: Service<Request<Body>>,
<L as Layer<Routes>>::Service: Clone,
<L as Layer<Routes>>::Service: Send,
<<L as Layer<Routes>>::Service as Service<Request<Body>>>::Future: 'static,
<<L as Layer<Routes>>::Service as Service<Request<Body>>>::Future: Send,
<<L as Layer<Routes>>::Service as Service<Request<Body>>>::Error: Into<Box<dyn Error + Send + Sync + 'static, Global>>,
<<L as Layer<Routes>>::Service as Service<Request<Body>>>::Error: Send,
<ResBody as Body>::Error: Into<Box<dyn Error + Send + Sync + 'static, Global>>,
<<L as Layer<Routes>>::Service as Service<Request<Body>>>::Response == Response<ResBody>,
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) -> <L as Layer<Routes>>::Service where
L: Layer<Routes>,
ResBody: 'static + Body<Data = Bytes> + Send,
<L as Layer<Routes>>::Service: 'static,
<L as Layer<Routes>>::Service: Service<Request<Body>>,
<L as Layer<Routes>>::Service: Clone,
<L as Layer<Routes>>::Service: Send,
<<L as Layer<Routes>>::Service as Service<Request<Body>>>::Future: 'static,
<<L as Layer<Routes>>::Service as Service<Request<Body>>>::Future: Send,
<<L as Layer<Routes>>::Service as Service<Request<Body>>>::Error: Into<Box<dyn Error + Send + Sync + 'static, Global>>,
<<L as Layer<Routes>>::Service as Service<Request<Body>>>::Error: Send,
<ResBody as Body>::Error: Into<Box<dyn Error + Send + Sync + 'static, Global>>,
<<L as Layer<Routes>>::Service as Service<Request<Body>>>::Response == Response<ResBody>,
pub fn into_service<ResBody>(self) -> <L as Layer<Routes>>::Service where
L: Layer<Routes>,
ResBody: 'static + Body<Data = Bytes> + Send,
<L as Layer<Routes>>::Service: 'static,
<L as Layer<Routes>>::Service: Service<Request<Body>>,
<L as Layer<Routes>>::Service: Clone,
<L as Layer<Routes>>::Service: Send,
<<L as Layer<Routes>>::Service as Service<Request<Body>>>::Future: 'static,
<<L as Layer<Routes>>::Service as Service<Request<Body>>>::Future: Send,
<<L as Layer<Routes>>::Service as Service<Request<Body>>>::Error: Into<Box<dyn Error + Send + Sync + 'static, Global>>,
<<L as Layer<Routes>>::Service as Service<Request<Body>>>::Error: Send,
<ResBody as Body>::Error: Into<Box<dyn Error + Send + Sync + 'static, Global>>,
<<L as Layer<Routes>>::Service as Service<Request<Body>>>::Response == Response<ResBody>,
Create a tower service out of a router.
Trait Implementations
Auto Trait Implementations
impl<L = Identity> !RefUnwindSafe for Router<L>
impl<L> Send for Router<L> where
L: Send,
impl<L = Identity> !Sync for Router<L>
impl<L> Unpin for Router<L> where
L: Unpin,
impl<L = Identity> !UnwindSafe for Router<L>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn 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>ⓘNotable traits for Instrumented<T>impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;
fn instrument(self, span: Span) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;
T: Future, type Output = <T as Future>::Output;
sourcefn in_current_span(self) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;
fn in_current_span(self) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;
T: Future, type Output = <T as Future>::Output;
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
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>ⓘNotable traits for WithDispatch<T>impl<T> Future for WithDispatch<T> where
T: Future, type Output = <T as Future>::Output;
where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>ⓘNotable traits for WithDispatch<T>impl<T> Future for WithDispatch<T> where
T: Future, type Output = <T as Future>::Output;
where
S: Into<Dispatch>,
T: Future, type Output = <T as Future>::Output;
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>ⓘNotable traits for WithDispatch<T>impl<T> Future for WithDispatch<T> where
T: Future, type Output = <T as Future>::Output;
fn with_current_subscriber(self) -> WithDispatch<Self>ⓘNotable traits for WithDispatch<T>impl<T> Future for WithDispatch<T> where
T: Future, type Output = <T as Future>::Output;
T: Future, type Output = <T as Future>::Output;
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more