pub struct IncomingStream<'a, L>where
L: Listener,{
pub io: &'a TokioIo<L::Io>,
pub remote_addr: L::Addr,
}Expand description
An incoming stream that bundles connection information.
This struct serves as the request type for the make_service Tower service,
allowing it to access connection-level metadata when creating per-connection services.
§Purpose
In Tower/Hyper’s model, make_service is called once per connection to create
a service that handles all HTTP requests on that connection. IncomingStream
provides the connection information needed to customize service creation based on:
- The remote address (for logging or access control)
- The underlying IO type (for protocol detection or configuration)
§Design
This type holds a reference to the IO rather than ownership because:
- The actual IO is still needed by Hyper to serve the connection after
make_servicereturns - The
make_serviceonly needs to inspect connection metadata, not take ownership
§Lifetime Safety
The lifetime 'a ensures the reference to IO remains valid only during the
make_service.call() invocation. After the service is created, the IO is
moved into a spawned task to handle the connection. This is safe because:
let io = TokioIo::new(stream); // IO created
let service = make_service.call(
IncomingStream { io: &io, .. } // Borrowed during call
).await; // Borrow ends
tokio::spawn(serve_connection(io, ..)); // IO moved to taskThe borrow checker guarantees the reference doesn’t outlive the IO object.
Used with serve and crate::routing::IntoMakeServiceWithConnectInfo.
Fields§
§io: &'a TokioIo<L::Io>Reference to the IO for this connection
remote_addr: L::AddrRemote address of the client
Implementations§
Source§impl<L> IncomingStream<'_, L>where
L: Listener,
impl<L> IncomingStream<'_, L>where
L: Listener,
Trait Implementations§
Source§impl<'a, L> Connected<IncomingStream<'a, L>> for SocketAddrwhere
L: Listener<Addr = SocketAddr>,
impl<'a, L> Connected<IncomingStream<'a, L>> for SocketAddrwhere
L: Listener<Addr = SocketAddr>,
Source§fn connect_info(target: IncomingStream<'a, L>) -> Self
fn connect_info(target: IncomingStream<'a, L>) -> Self
Auto Trait Implementations§
impl<'a, L> Freeze for IncomingStream<'a, L>
impl<'a, L> RefUnwindSafe for IncomingStream<'a, L>
impl<'a, L> Send for IncomingStream<'a, L>
impl<'a, L> Sync for IncomingStream<'a, L>
impl<'a, L> Unpin for IncomingStream<'a, L>
impl<'a, L> UnwindSafe for IncomingStream<'a, 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
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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more