Skip to main content

Stream

Struct Stream 

Source
pub struct Stream {
    pub stream: Box<dyn Transport>,
    /* private fields */
}

Fields§

§stream: Box<dyn Transport>

The bidirectional byte pipe the request/response cycle runs over.

The concrete type is erased behind Transport, so a plain TCP socket, a TLS session and a per-request duplex stream are interchangeable here. Address metadata comes from the transport itself, so a transport without a socket identity reports an error instead of a fabricated address.

Implementations§

Source§

impl Stream

Inherent implementation of Stream.

Source

pub fn from_transport<T>( transport: T, request_config: RequestConfig, closed: bool, ) -> Stream
where T: Transport + 'static,

Boxes a transport into a Stream for the request pipeline.

This is the single construction path: a plain TCP socket, a TLS session and a per-request duplex stream all enter here, so nothing above the transport line has to know which one it is serving. The transport is type erased immediately, which keeps Stream a fixed size regardless of the concrete protocol adapter behind it.

§Arguments
  • T - The transport type to serve the request cycle over.
  • RequestConfig - The parsing limits and read timeout for the cycle.
  • bool - Whether the connection starts already closed.
§Returns
  • Self - A stream serving bytes through the boxed transport.
Source

pub fn new( stream: TcpStream, request_config: RequestConfig, closed: bool, ) -> Stream

Boxes a TCP socket into a Stream for the request pipeline.

Kept as the socket-facing constructor so the accept loop keeps its existing call shape; it delegates to from_transport, so there is one construction path rather than two.

§Arguments
  • TcpStream - The accepted socket to serve the request cycle over.
  • RequestConfig - The parsing limits and read timeout for the cycle.
  • bool - Whether the connection starts already closed.
§Returns
  • Self - A stream serving bytes through the boxed socket.
Source

pub fn get_peer_addr(&self) -> Result<SocketAddr, Error>

Reports the address of the remote end of the transport.

Delegates to the transport itself, so a transport without a socket identity answers with an error rather than a fabricated address.

§Returns
  • Result<SocketAddr, io::Error> - The peer address reported by the transport.
Source

pub fn get_local_addr(&self) -> Result<SocketAddr, Error>

Reports the address of the local end of the transport.

Delegates to the transport itself, so a transport without a socket identity answers with an error rather than a fabricated address.

§Returns
  • Result<SocketAddr, io::Error> - The local address reported by the transport.
Source

pub fn is_keep_alive(&self, keep_alive: bool) -> bool

Checks if the connection should be kept alive.

This method evaluates whether the connection should remain open based on the closed state and the keep_alive parameter.

§Arguments
  • bool - Whether keep-alive is enabled for the request.
§Returns
  • bool - True if the connection should be kept alive, otherwise false.
Source

pub async fn try_fill_http_request( &mut self, request: &mut Request, ) -> Result<(), RequestError>

Parses an HTTP request from a TCP stream into the given request.

The request is reset and filled in place, reusing its allocations. If the timeout is DEFAULT_LOW_SECURITY_READ_TIMEOUT_MS, no timeout is applied.

§Arguments
  • &mut Request - The request object to reset and fill.
§Returns
  • Result<(), RequestError> - Ok on success, or an error if parsing fails.
Source

pub async fn try_get_http_request(&mut self) -> Result<Request, RequestError>

Parses an HTTP request from a TCP stream.

Wraps the stream in a buffered reader and delegates to http_from_reader. If the timeout is DEFAULT_LOW_SECURITY_READ_TIMEOUT_MS, no timeout is applied.

§Returns
  • Result<Request, RequestError> - The parsed request or an error.
Source

pub async fn try_get_websocket_request( &mut self, ) -> Result<Vec<u8>, RequestError>

Parses a WebSocket request from a TCP stream.

Wraps the stream in a buffered reader and delegates to ws_from_reader. If the timeout is DEFAULT_LOW_SECURITY_READ_TIMEOUT_MS, no timeout is applied.

§Returns
  • Result<RequestBody, RequestError> - The parsed WebSocket request or an error.
Source

pub async fn try_send<D>(&mut self, data: D) -> Result<(), ResponseError>
where D: AsRef<[u8]>,

Sends data over the stream.

§Arguments
  • D - The data to send, which must implement AsRef<[u8]>.
§Returns
  • Result<(), ResponseError> - Result indicating success or failure.
Source

pub async fn send<D>(&mut self, data: D)
where D: AsRef<[u8]>,

Sends data over the stream.

§Arguments
  • D - The data to send, which must implement AsRef<[u8]>.
§Panics

Panics if the write operation fails.

Source

pub async fn try_send_list<I, D>( &mut self, data_iter: I, ) -> Result<(), ResponseError>
where I: IntoIterator<Item = D>, D: AsRef<[u8]>,

Sends multiple data.

§Arguments
  • I - The data list to send, which must implement IntoIterator<Item = D> with D requiring the AsRef<[u8]> bound.
§Returns
  • Result<(), ResponseError> - Result indicating success or failure.
Source

pub async fn send_list<I, D>(&mut self, data_iter: I)
where I: IntoIterator<Item = D>, D: AsRef<[u8]>,

Sends multiple data.

§Arguments
  • I - The data list to send, which must implement IntoIterator<Item = D> with D requiring the AsRef<[u8]> bound.
§Panics

Panics if any write operation fails.

Source

pub async fn try_flush(&mut self) -> Result<(), ResponseError>

Flushes all buffered data to the stream.

§Returns
  • Result<(), ResponseError> - Result indicating success or failure.
Source

pub async fn flush(&mut self)

Flushes all buffered data to the stream.

§Panics

Panics if the flush operation fails.

Source§

impl Stream

Source

pub fn get_stream(&self) -> &Box<dyn Transport>

Source

pub fn get_mut_stream(&mut self) -> &mut Box<dyn Transport>

Source

pub fn set_stream(&mut self, val: Box<dyn Transport>) -> &mut Stream

Source

pub fn get_request_config(&self) -> &RequestConfig

Source

pub fn get_closed(&self) -> bool

Source

pub fn set_closed(&mut self, val: bool) -> &mut Stream

Source

pub fn get_leftover(&self) -> &Vec<u8> ⓘ

Source

pub fn get_leftover_start(&self) -> usize

Source

pub fn get_leftover_end(&self) -> usize

Source

pub fn get_line_buffer(&self) -> &String

Source

pub fn get_header_line_buffer(&self) -> &String

Trait Implementations§

Source§

impl AsMut<Stream> for Stream

Implementation of AsMut trait for Stream.

Source§

fn as_mut(&mut self) -> &mut Stream

Converts &mut Stream to &mut Stream via memory address conversion.

§Returns
  • &mut Self - A mutable reference to the Stream instance.
Source§

impl AsRef<Stream> for Stream

Implementation of AsRef trait for Stream.

Source§

fn as_ref(&self) -> &Stream

Converts &Stream to &Stream via memory address conversion.

§Returns
  • &Self - A reference to the Stream instance.
Source§

impl Debug for Stream

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the struct fields as a debug struct, skipping excluded fields.

§Arguments
  • &mut std::fmt::Formatter<'_> - The formatter to write the representation into.
§Returns
  • std::fmt::Result - Success or failure of the formatting operation.
Source§

impl Display for Stream

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the standard debug format.

§Arguments
  • &mut std::fmt::Formatter<'_> - The formatter to write the representation into.
§Returns
  • std::fmt::Result - Success or failure of the formatting operation.
Source§

impl From<usize> for &'static Stream

Implementation of From trait for converting usize address into &Stream.

Source§

fn from(address: usize) -> &'static Stream

Converts a memory address into a reference to Stream.

§Arguments
  • usize - The memory address of the Stream instance.
§Returns
  • &'static Stream - A reference to the Stream at the given address.
§Safety
  • The address is guaranteed to be a valid Stream instance that was previously converted from a reference and is managed by the runtime.
Source§

impl<'a> From<usize> for &'a mut Stream

Implementation of From trait for converting usize address into &mut Stream.

Source§

fn from(address: usize) -> &'a mut Stream

Converts a memory address into a mutable reference to Stream.

§Arguments
  • usize - The memory address of the Stream instance.
§Returns
  • &'a mut Stream - A mutable reference to the Stream at the given address.
§Safety
  • The address is guaranteed to be a valid Stream instance that was previously converted from a reference and is managed by the runtime.
Source§

impl Lifetime for Stream

Implementation of Lifetime trait for Stream.

Source§

unsafe fn leak(&self) -> &'static Stream

Converts a reference to the stream into a 'static reference.

§Returns
  • &'static Self - A reference to the stream with a 'static lifetime.
§Safety
  • The address is guaranteed to be a valid Self instance that was previously converted from a reference and is managed by the runtime.
Source§

unsafe fn leak_mut(&self) -> &'static mut Stream

Converts a reference to the stream into a 'static mutable reference.

§Returns
  • &'static mut Self - A mutable reference to the stream with a 'static lifetime.
§Safety
  • The address is guaranteed to be a valid Self instance that was previously converted from a reference and is managed by the runtime.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> AnySend for T
where T: Any + Send,

Source§

impl<T> AnySendSync for T
where T: Any + Send + Sync,

Source§

impl<T> AnySync for T
where T: Any + Sync,

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more