pub use futures::SinkExt;
pub use futures::StreamExt;
+/// An interface to write messages to the network connection
+///
+/// Implements the [`Sink`] trait to asynchronously write messages to the network connection.
+///
+/// # Example
+///
+/// Basic usage:
+///
+/// ```ignore
+/// writer.send(msg).await?;
+/// ```
+///
+/// Please see the [tcp-client](https://github.com/sachanganesh/connect-rs/blob/main/examples/tcp-client/)
+/// example program or other client example programs for a more thorough showcase.
+///
pub struct ConnectionWriter {
local_addr: SocketAddr,
peer_addr: SocketAddr,
}
impl ConnectionWriter {
+ /// Creates a new [`ConnectionWriter`] from an [`AsyncWrite`] trait object and the local and peer
+ /// socket metadata
pub fn new(
local_addr: SocketAddr,
peer_addr: SocketAddr,
}
}
+ /// Get the local IP address and port
pub fn local_addr(&self) -> SocketAddr {
self.local_addr.clone()
}
+ /// Get the peer IP address and port
pub fn peer_addr(&self) -> SocketAddr {
self.peer_addr.clone()
}
+ /// Check if the [`Sink`] of messages to the network is closed
pub fn is_closed(&self) -> bool {
self.closed
}