pub struct UdpServer { /* private fields */ }
Expand description
The UdpServer
struct in Rust contains a UDP socket and an Arc-wrapped notification mechanism.
§Properties:
socket
: Thesocket
property in theUdpServer
struct represents a UDP socket that the server uses to send and receive data over the network.notify
: Thenotify
property in theUdpServer
struct is of typeArc<Notify>
.Arc
stands for “atomic reference counting” and is a thread-safe reference-counting pointer.Notify
is a synchronization primitive that allows threads to wait until a condition is satisfied.
Implementations§
Source§impl UdpServer
impl UdpServer
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
creates a UDP server bound to a specified address and returns a result with
the server instance or an error.
§Arguments:
addr
: Theaddr
parameter in thebind
function is a reference to a string that represents the address to bind the UDP socket to. This address typically includes the IP address and port number on which the socket will listen for incoming connections.
§Returns:
The bind
function is returning a Result
containing an instance of UdpServer
if the binding
operation is successful. The UdpServer
struct contains a UdpSocket
and an Arc<Notify>
instance.
Sourcepub async fn run(self: Arc<Self>) -> Result<(), Box<dyn Error>>
pub async fn run(self: Arc<Self>) -> Result<(), Box<dyn Error>>
The function run
is an asynchronous method in Rust that continuously listens for incoming data
on a UDP socket, processes the data, and echoes it back to the sender while also checking for a
shutdown signal.
§Arguments:
- ``: The code you provided is a Rust asynchronous function that runs a UDP server using Tokio. Here’s a breakdown of the key components:
§Returns:
The run
function returns a Result
with an Ok(())
value if the UDP server is shut down
successfully.
Auto Trait Implementations§
impl !Freeze for UdpServer
impl RefUnwindSafe for UdpServer
impl Send for UdpServer
impl Sync for UdpServer
impl Unpin for UdpServer
impl UnwindSafe for UdpServer
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