]> git.lizzy.rs Git - connect-rs.git/blobdiff - src/writer.rs
renamed server to listener and add thorough documentation
[connect-rs.git] / src / writer.rs
index 24030249110beb3768a0211e46654c779e488d71..9a6f20af85ab3e3bc43243b94e29a325141bc4a1 100644 (file)
@@ -11,6 +11,21 @@ use protobuf::Message;
 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,
@@ -20,6 +35,8 @@ pub struct ConnectionWriter {
 }
 
 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,
@@ -34,14 +51,17 @@ impl ConnectionWriter {
         }
     }
 
+    /// 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
     }