Skip to content

Commit 465c362

Browse files
add UdpListener::from_tokio() (#14)
* add UdpListener::from_tokio() * Add simple docs to UdpListener methods --------- Co-authored-by: Sajjad (Sage) Pourali <[email protected]>
1 parent 28980d6 commit 465c362

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/lib.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,14 @@ impl Drop for UdpListener {
5454
}
5555

5656
impl UdpListener {
57+
/// Binds the `UdpListener` to the given local address.
5758
pub async fn bind(local_addr: SocketAddr) -> io::Result<Self> {
58-
let (tx, rx) = mpsc::channel(CHANNEL_LEN);
5959
let udp_socket = UdpSocket::bind(local_addr).await?;
60+
Self::from_tokio(udp_socket).await
61+
}
62+
/// Creates a `UdpListener` from an existing `tokio::net::UdpSocket`.
63+
pub async fn from_tokio(udp_socket: UdpSocket) -> io::Result<Self> {
64+
let (tx, rx) = mpsc::channel(CHANNEL_LEN);
6065
let local_addr = udp_socket.local_addr()?;
6166

6267
let handler = tokio::spawn(async move {

0 commit comments

Comments
 (0)