pub struct TcpServer { /* private fields */ }Expand description
The TcpServer struct represents a TCP server with a listener and a notification mechanism.
§Properties:
listener: Thelistenerproperty in theTcpServerstruct is of typeTcpListener. It is used to listen for incoming TCP connections on a specific port.notify: Thenotifyproperty in theTcpServerstruct is of typeArc<Notify>.Arcstands for “Atomically Reference Counted” and is a thread-safe reference-counting pointer.Notifyis a synchronization primitive that allows threads to wait until a condition is satisfied
Implementations§
Source§impl TcpServer
impl TcpServer
Sourcepub async fn bind(addr: &str) -> Result<Self, Box<dyn Error>>
pub async fn bind(addr: &str) -> Result<Self, Box<dyn Error>>
The function bind asynchronously binds a TCP listener to a specified address and returns a
TcpServer instance wrapped in a Result.
§Arguments:
addr: Theaddrparameter in thebindfunction is a reference to a string that represents the address to which the TCP listener will bind. This address typically includes the IP address and port number on which the server will listen for incoming connections.
§Returns:
The bind function returns a Result containing an instance of TcpServer if the operation is
successful, or a boxed dyn Error trait object if an error occurs during the process.
Sourcepub async fn run(&self) -> Result<(), Box<dyn Error>>
pub async fn run(&self) -> Result<(), Box<dyn Error>>
The function run is an asynchronous Rust function that continuously accepts incoming
connections, reads data from the socket, echoes it back, and can be shut down upon notification.
§Returns:
The run function is returning a Result with an empty tuple () on success or a Box
containing any type that implements the Error trait on failure.
Auto Trait Implementations§
impl !Freeze for TcpServer
impl RefUnwindSafe for TcpServer
impl Send for TcpServer
impl Sync for TcpServer
impl Unpin for TcpServer
impl UnwindSafe for TcpServer
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
Mutably borrows from an owned value. Read more