pub struct Router<A, B> { /* private fields */ }
Expand description
A stack based Service
router.
Implementations
sourceimpl<A, B> Router<A, B> 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> Router<A, B> 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,
sourcepub fn add_service<S>(self, svc: S) -> Router<S, Or<A, B, Request<Body>>> 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_service<S>(self, svc: S) -> Router<S, Or<A, B, Request<Body>>> 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 service to this router.
sourcepub fn add_optional_service<S>(
self,
svc: Option<S>
) -> Router<Either<S, Unimplemented>, Or<A, B, Request<Body>>> 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>>> 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.
sourcepub async fn serve_with_shutdown<F: Future<Output = ()>>(
self,
addr: SocketAddr,
signal: F
) -> Result<(), Error>
pub async fn serve_with_shutdown<F: Future<Output = ()>>(
self,
addr: SocketAddr,
signal: F
) -> Result<(), Error>
sourcepub async fn serve_with_incoming<I, IO, IE>(
self,
incoming: I
) -> Result<(), Error> where
I: Stream<Item = Result<IO, IE>>,
IO: AsyncRead + AsyncWrite + Connected + Unpin + Send + 'static,
IE: Into<Box<dyn Error + Send + Sync>>,
pub async fn serve_with_incoming<I, IO, IE>(
self,
incoming: I
) -> Result<(), Error> where
I: Stream<Item = Result<IO, IE>>,
IO: AsyncRead + AsyncWrite + Connected + Unpin + Send + 'static,
IE: 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
.
sourcepub async fn serve_with_incoming_shutdown<I, IO, IE, F>(
self,
incoming: I,
signal: F
) -> Result<(), Error> where
I: Stream<Item = Result<IO, IE>>,
IO: AsyncRead + AsyncWrite + Connected + Unpin + Send + 'static,
IE: Into<Box<dyn Error + Send + Sync>>,
F: Future<Output = ()>,
pub async fn serve_with_incoming_shutdown<I, IO, IE, F>(
self,
incoming: I,
signal: F
) -> Result<(), Error> where
I: Stream<Item = Result<IO, IE>>,
IO: AsyncRead + AsyncWrite + Connected + Unpin + Send + 'static,
IE: Into<Box<dyn Error + Send + Sync>>,
F: Future<Output = ()>,
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(self) -> RouterService<A, B>
pub fn into_service(self) -> RouterService<A, B>
Create a tower service out of a router.
Trait Implementations
Auto Trait Implementations
impl<A, B> !RefUnwindSafe for Router<A, B>
impl<A, B> Send for Router<A, B> where
A: Send,
B: Send,
impl<A, B> Sync for Router<A, B> where
A: Sync,
B: Sync,
impl<A, B> Unpin for Router<A, B> where
A: Unpin,
B: Unpin,
impl<A, B> !UnwindSafe for Router<A, B>
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;
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
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> 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;
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
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> 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