blob: 10297809972cba438c5ec35fc3bbc390fd77a966 [file] [log] [blame]
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="A User Datagram Protocol socket."><meta name="keywords" content="rust, rustlang, rust-lang, UdpSocket"><title>UdpSocket in mio::net - Rust</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceSerif4-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../FiraSans-Regular.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../FiraSans-Medium.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceCodePro-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceSerif4-Bold.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceCodePro-Semibold.ttf.woff2"><link rel="stylesheet" href="../../normalize.css"><link rel="stylesheet" href="../../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" href="../../ayu.css" disabled><link rel="stylesheet" href="../../dark.css" disabled><link rel="stylesheet" href="../../light.css" id="themeStyle"><script id="default-settings" ></script><script src="../../storage.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../main.js"></script><noscript><link rel="stylesheet" href="../../noscript.css"></noscript><link rel="alternate icon" type="image/png" href="../../favicon-16x16.png"><link rel="alternate icon" type="image/png" href="../../favicon-32x32.png"><link rel="icon" type="image/svg+xml" href="../../favicon.svg"></head><body class="rustdoc struct"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle">&#9776;</button><a class="sidebar-logo" href="../../mio/index.html"><div class="logo-container"><img class="rust-logo" src="../../rust-logo.svg" alt="logo"></div></a><h2></h2></nav><nav class="sidebar"><a class="sidebar-logo" href="../../mio/index.html"><div class="logo-container"><img class="rust-logo" src="../../rust-logo.svg" alt="logo"></div></a><h2 class="location"><a href="#">UdpSocket</a></h2><div class="sidebar-elems"><section><h3><a href="#implementations">Methods</a></h3><ul class="block"><li><a href="#method.bind">bind</a></li><li><a href="#method.broadcast">broadcast</a></li><li><a href="#method.connect">connect</a></li><li><a href="#method.from_std">from_std</a></li><li><a href="#method.join_multicast_v4">join_multicast_v4</a></li><li><a href="#method.join_multicast_v6">join_multicast_v6</a></li><li><a href="#method.leave_multicast_v4">leave_multicast_v4</a></li><li><a href="#method.leave_multicast_v6">leave_multicast_v6</a></li><li><a href="#method.local_addr">local_addr</a></li><li><a href="#method.multicast_loop_v4">multicast_loop_v4</a></li><li><a href="#method.multicast_loop_v6">multicast_loop_v6</a></li><li><a href="#method.multicast_ttl_v4">multicast_ttl_v4</a></li><li><a href="#method.only_v6">only_v6</a></li><li><a href="#method.peek">peek</a></li><li><a href="#method.peek_from">peek_from</a></li><li><a href="#method.peer_addr">peer_addr</a></li><li><a href="#method.recv">recv</a></li><li><a href="#method.recv_from">recv_from</a></li><li><a href="#method.send">send</a></li><li><a href="#method.send_to">send_to</a></li><li><a href="#method.set_broadcast">set_broadcast</a></li><li><a href="#method.set_multicast_loop_v4">set_multicast_loop_v4</a></li><li><a href="#method.set_multicast_loop_v6">set_multicast_loop_v6</a></li><li><a href="#method.set_multicast_ttl_v4">set_multicast_ttl_v4</a></li><li><a href="#method.set_ttl">set_ttl</a></li><li><a href="#method.take_error">take_error</a></li><li><a href="#method.try_io">try_io</a></li><li><a href="#method.ttl">ttl</a></li></ul><h3><a href="#trait-implementations">Trait Implementations</a></h3><ul class="block"><li><a href="#impl-AsRawFd-for-UdpSocket">AsRawFd</a></li><li><a href="#impl-Debug-for-UdpSocket">Debug</a></li><li><a href="#impl-FromRawFd-for-UdpSocket">FromRawFd</a></li><li><a href="#impl-IntoRawFd-for-UdpSocket">IntoRawFd</a></li><li><a href="#impl-Source-for-UdpSocket">Source</a></li></ul><h3><a href="#synthetic-implementations">Auto Trait Implementations</a></h3><ul class="block"><li><a href="#impl-RefUnwindSafe-for-UdpSocket">RefUnwindSafe</a></li><li><a href="#impl-Send-for-UdpSocket">Send</a></li><li><a href="#impl-Sync-for-UdpSocket">Sync</a></li><li><a href="#impl-Unpin-for-UdpSocket">Unpin</a></li><li><a href="#impl-UnwindSafe-for-UdpSocket">UnwindSafe</a></li></ul><h3><a href="#blanket-implementations">Blanket Implementations</a></h3><ul class="block"><li><a href="#impl-Any-for-UdpSocket">Any</a></li><li><a href="#impl-Borrow%3CT%3E-for-UdpSocket">Borrow&lt;T&gt;</a></li><li><a href="#impl-BorrowMut%3CT%3E-for-UdpSocket">BorrowMut&lt;T&gt;</a></li><li><a href="#impl-From%3CT%3E-for-UdpSocket">From&lt;T&gt;</a></li><li><a href="#impl-Into%3CU%3E-for-UdpSocket">Into&lt;U&gt;</a></li><li><a href="#impl-TryFrom%3CU%3E-for-UdpSocket">TryFrom&lt;U&gt;</a></li><li><a href="#impl-TryInto%3CU%3E-for-UdpSocket">TryInto&lt;U&gt;</a></li></ul></section><h2><a href="index.html">In mio::net</a></h2></div></nav><main><div class="width-limiter"><nav class="sub"><form class="search-form"><div class="search-container"><span></span><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><div id="help-button" title="help" tabindex="-1"><a href="../../help.html">?</a></div><div id="settings-menu" tabindex="-1"><a href="../../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../../wheel.svg"></a></div></div></form></nav><section id="main-content" class="content"><div class="main-heading"><h1 class="fqn">Struct <a href="../index.html">mio</a>::<wbr><a href="index.html">net</a>::<wbr><a class="struct" href="#">UdpSocket</a><button id="copy-path" onclick="copy_path(this)" title="Copy item path to clipboard"><img src="../../clipboard.svg" width="19" height="18" alt="Copy item path"></button></h1><span class="out-of-band"><a class="srclink" href="../../src/mio/net/udp.rs.html#91-93">source</a> · <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">&#x2212;</span>]</a></span></div><div class="item-decl"><pre class="rust struct"><code>pub struct UdpSocket { /* private fields */ }</code></pre></div><details class="rustdoc-toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>A User Datagram Protocol socket.</p>
<p>This is an implementation of a bound UDP socket. This supports both IPv4 and
IPv6 addresses, and there is no corresponding notion of a server because UDP
is a datagram protocol.</p>
<h2 id="examples"><a href="#examples">Examples</a></h2>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="comment">// An Echo program:
// SENDER -&gt; sends a message.
// ECHOER -&gt; listens and prints the message received.
</span><span class="kw">use </span>mio::net::UdpSocket;
<span class="kw">use </span>mio::{Events, Interest, Poll, Token};
<span class="kw">use </span>std::time::Duration;
<span class="kw">const </span>SENDER: Token = Token(<span class="number">0</span>);
<span class="kw">const </span>ECHOER: Token = Token(<span class="number">1</span>);
<span class="comment">// This operation will fail if the address is in use, so we select different ports for each
// socket.
</span><span class="kw">let </span><span class="kw-2">mut </span>sender_socket = UdpSocket::bind(<span class="string">&quot;127.0.0.1:0&quot;</span>.parse()<span class="question-mark">?</span>)<span class="question-mark">?</span>;
<span class="kw">let </span><span class="kw-2">mut </span>echoer_socket = UdpSocket::bind(<span class="string">&quot;127.0.0.1:0&quot;</span>.parse()<span class="question-mark">?</span>)<span class="question-mark">?</span>;
<span class="comment">// If we do not use connect here, SENDER and ECHOER would need to call send_to and recv_from
// respectively.
</span>sender_socket.connect(echoer_socket.local_addr()<span class="question-mark">?</span>)<span class="question-mark">?</span>;
<span class="comment">// We need a Poll to check if SENDER is ready to be written into, and if ECHOER is ready to be
// read from.
</span><span class="kw">let </span><span class="kw-2">mut </span>poll = Poll::new()<span class="question-mark">?</span>;
<span class="comment">// We register our sockets here so that we can check if they are ready to be written/read.
</span>poll.registry().register(<span class="kw-2">&amp;mut </span>sender_socket, SENDER, Interest::WRITABLE)<span class="question-mark">?</span>;
poll.registry().register(<span class="kw-2">&amp;mut </span>echoer_socket, ECHOER, Interest::READABLE)<span class="question-mark">?</span>;
<span class="kw">let </span>msg_to_send = [<span class="number">9</span>; <span class="number">9</span>];
<span class="kw">let </span><span class="kw-2">mut </span>buffer = [<span class="number">0</span>; <span class="number">9</span>];
<span class="kw">let </span><span class="kw-2">mut </span>events = Events::with_capacity(<span class="number">128</span>);
<span class="kw">loop </span>{
poll.poll(<span class="kw-2">&amp;mut </span>events, <span class="prelude-val">Some</span>(Duration::from_millis(<span class="number">100</span>)))<span class="question-mark">?</span>;
<span class="kw">for </span>event <span class="kw">in </span>events.iter() {
<span class="kw">match </span>event.token() {
<span class="comment">// Our SENDER is ready to be written into.
</span>SENDER =&gt; {
<span class="kw">let </span>bytes_sent = sender_socket.send(<span class="kw-2">&amp;</span>msg_to_send)<span class="question-mark">?</span>;
<span class="macro">assert_eq!</span>(bytes_sent, <span class="number">9</span>);
<span class="macro">println!</span>(<span class="string">&quot;sent {:?} -&gt; {:?} bytes&quot;</span>, msg_to_send, bytes_sent);
},
<span class="comment">// Our ECHOER is ready to be read from.
</span>ECHOER =&gt; {
<span class="kw">let </span>num_recv = echoer_socket.recv(<span class="kw-2">&amp;mut </span>buffer)<span class="question-mark">?</span>;
<span class="macro">println!</span>(<span class="string">&quot;echo {:?} -&gt; {:?}&quot;</span>, buffer, num_recv);
buffer = [<span class="number">0</span>; <span class="number">9</span>];
}
<span class="kw">_ </span>=&gt; <span class="macro">unreachable!</span>()
}
}
}</code></pre></div>
</div></details><h2 id="implementations" class="small-section-header">Implementations<a href="#implementations" class="anchor"></a></h2><div id="implementations-list"><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-UdpSocket" class="impl has-srclink"><a class="srclink rightside" href="../../src/mio/net/udp.rs.html#95-613">source</a><a href="#impl-UdpSocket" class="anchor"></a><h3 class="code-header">impl <a class="struct" href="struct.UdpSocket.html" title="struct mio::net::UdpSocket">UdpSocket</a></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.bind" class="method has-srclink"><a class="srclink rightside" href="../../src/mio/net/udp.rs.html#121-123">source</a><h4 class="code-header">pub fn <a href="#method.bind" class="fnname">bind</a>(addr: SocketAddr) -&gt; Result&lt;<a class="struct" href="struct.UdpSocket.html" title="struct mio::net::UdpSocket">UdpSocket</a>&gt;</h4></section></summary><div class="docblock"><p>Creates a UDP socket from the given address.</p>
<h5 id="examples-1"><a href="#examples-1">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>mio::net::UdpSocket;
<span class="comment">// We must bind it to an open address.
</span><span class="kw">let </span>socket = <span class="kw">match </span>UdpSocket::bind(<span class="string">&quot;127.0.0.1:0&quot;</span>.parse()<span class="question-mark">?</span>) {
<span class="prelude-val">Ok</span>(new_socket) =&gt; new_socket,
<span class="prelude-val">Err</span>(fail) =&gt; {
<span class="comment">// We panic! here, but you could try to bind it again on another address.
</span><span class="macro">panic!</span>(<span class="string">&quot;Failed to bind socket. {:?}&quot;</span>, fail);
}
};
<span class="comment">// Our socket was created, but we should not use it before checking it&#39;s readiness.</span></code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.from_std" class="method has-srclink"><a class="srclink rightside" href="../../src/mio/net/udp.rs.html#131-135">source</a><h4 class="code-header">pub fn <a href="#method.from_std" class="fnname">from_std</a>(socket: UdpSocket) -&gt; <a class="struct" href="struct.UdpSocket.html" title="struct mio::net::UdpSocket">UdpSocket</a></h4></section></summary><div class="docblock"><p>Creates a new <code>UdpSocket</code> from a standard <code>net::UdpSocket</code>.</p>
<p>This function is intended to be used to wrap a UDP socket from the
standard library in the Mio equivalent. The conversion assumes nothing
about the underlying socket; it is left up to the user to set it in
non-blocking mode.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.local_addr" class="method has-srclink"><a class="srclink rightside" href="../../src/mio/net/udp.rs.html#160-162">source</a><h4 class="code-header">pub fn <a href="#method.local_addr" class="fnname">local_addr</a>(&amp;self) -&gt; Result&lt;SocketAddr&gt;</h4></section></summary><div class="docblock"><p>Returns the socket address that this socket was created from.</p>
<h5 id="examples-2"><a href="#examples-2">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>mio::net::UdpSocket;
<span class="kw">let </span>addr = <span class="string">&quot;127.0.0.1:0&quot;</span>.parse()<span class="question-mark">?</span>;
<span class="kw">let </span>socket = UdpSocket::bind(addr)<span class="question-mark">?</span>;
<span class="macro">assert_eq!</span>(socket.local_addr()<span class="question-mark">?</span>.ip(), addr.ip());</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.peer_addr" class="method has-srclink"><a class="srclink rightside" href="../../src/mio/net/udp.rs.html#183-185">source</a><h4 class="code-header">pub fn <a href="#method.peer_addr" class="fnname">peer_addr</a>(&amp;self) -&gt; Result&lt;SocketAddr&gt;</h4></section></summary><div class="docblock"><p>Returns the socket address of the remote peer this socket was connected to.</p>
<h5 id="examples-3"><a href="#examples-3">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>mio::net::UdpSocket;
<span class="kw">let </span>addr = <span class="string">&quot;127.0.0.1:0&quot;</span>.parse()<span class="question-mark">?</span>;
<span class="kw">let </span>peer_addr = <span class="string">&quot;127.0.0.1:11100&quot;</span>.parse()<span class="question-mark">?</span>;
<span class="kw">let </span>socket = UdpSocket::bind(addr)<span class="question-mark">?</span>;
socket.connect(peer_addr)<span class="question-mark">?</span>;
<span class="macro">assert_eq!</span>(socket.peer_addr()<span class="question-mark">?</span>.ip(), peer_addr.ip());</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.send_to" class="method has-srclink"><a class="srclink rightside" href="../../src/mio/net/udp.rs.html#211-213">source</a><h4 class="code-header">pub fn <a href="#method.send_to" class="fnname">send_to</a>(&amp;self, buf: &amp;[u8], target: SocketAddr) -&gt; Result&lt;usize&gt;</h4></section></summary><div class="docblock"><p>Sends data on the socket to the given address. On success, returns the
number of bytes written.</p>
<p>Address type can be any implementor of <code>ToSocketAddrs</code> trait. See its
documentation for concrete examples.</p>
<h5 id="examples-4"><a href="#examples-4">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>mio::net::UdpSocket;
<span class="kw">let </span>socket = UdpSocket::bind(<span class="string">&quot;127.0.0.1:0&quot;</span>.parse()<span class="question-mark">?</span>)<span class="question-mark">?</span>;
<span class="comment">// We must check if the socket is writable before calling send_to,
// or we could run into a WouldBlock error.
</span><span class="kw">let </span>bytes_sent = socket.send_to(<span class="kw-2">&amp;</span>[<span class="number">9</span>; <span class="number">9</span>], <span class="string">&quot;127.0.0.1:11100&quot;</span>.parse()<span class="question-mark">?</span>)<span class="question-mark">?</span>;
<span class="macro">assert_eq!</span>(bytes_sent, <span class="number">9</span>);</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.recv_from" class="method has-srclink"><a class="srclink rightside" href="../../src/mio/net/udp.rs.html#246-248">source</a><h4 class="code-header">pub fn <a href="#method.recv_from" class="fnname">recv_from</a>(&amp;self, buf: &amp;mut [u8]) -&gt; Result&lt;(usize, SocketAddr)&gt;</h4></section></summary><div class="docblock"><p>Receives data from the socket. On success, returns the number of bytes
read and the address from whence the data came.</p>
<h5 id="notes"><a href="#notes">Notes</a></h5>
<p>On Windows, if the data is larger than the buffer specified, the buffer
is filled with the first part of the data, and recv_from returns the error
WSAEMSGSIZE(10040). The excess data is lost.
Make sure to always use a sufficiently large buffer to hold the
maximum UDP packet size, which can be up to 65536 bytes in size.</p>
<h5 id="examples-5"><a href="#examples-5">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>mio::net::UdpSocket;
<span class="kw">let </span>socket = UdpSocket::bind(<span class="string">&quot;127.0.0.1:0&quot;</span>.parse()<span class="question-mark">?</span>)<span class="question-mark">?</span>;
<span class="comment">// We must check if the socket is readable before calling recv_from,
// or we could run into a WouldBlock error.
</span><span class="kw">let </span><span class="kw-2">mut </span>buf = [<span class="number">0</span>; <span class="number">9</span>];
<span class="kw">let </span>(num_recv, from_addr) = socket.recv_from(<span class="kw-2">&amp;mut </span>buf)<span class="question-mark">?</span>;
<span class="macro">println!</span>(<span class="string">&quot;Received {:?} -&gt; {:?} bytes from {:?}&quot;</span>, buf, num_recv, from_addr);</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.peek_from" class="method has-srclink"><a class="srclink rightside" href="../../src/mio/net/udp.rs.html#282-284">source</a><h4 class="code-header">pub fn <a href="#method.peek_from" class="fnname">peek_from</a>(&amp;self, buf: &amp;mut [u8]) -&gt; Result&lt;(usize, SocketAddr)&gt;</h4></section></summary><div class="docblock"><p>Receives data from the socket, without removing it from the input queue.
On success, returns the number of bytes read and the address from whence
the data came.</p>
<h5 id="notes-1"><a href="#notes-1">Notes</a></h5>
<p>On Windows, if the data is larger than the buffer specified, the buffer
is filled with the first part of the data, and peek_from returns the error
WSAEMSGSIZE(10040). The excess data is lost.
Make sure to always use a sufficiently large buffer to hold the
maximum UDP packet size, which can be up to 65536 bytes in size.</p>
<h5 id="examples-6"><a href="#examples-6">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>mio::net::UdpSocket;
<span class="kw">let </span>socket = UdpSocket::bind(<span class="string">&quot;127.0.0.1:0&quot;</span>.parse()<span class="question-mark">?</span>)<span class="question-mark">?</span>;
<span class="comment">// We must check if the socket is readable before calling recv_from,
// or we could run into a WouldBlock error.
</span><span class="kw">let </span><span class="kw-2">mut </span>buf = [<span class="number">0</span>; <span class="number">9</span>];
<span class="kw">let </span>(num_recv, from_addr) = socket.peek_from(<span class="kw-2">&amp;mut </span>buf)<span class="question-mark">?</span>;
<span class="macro">println!</span>(<span class="string">&quot;Received {:?} -&gt; {:?} bytes from {:?}&quot;</span>, buf, num_recv, from_addr);</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.send" class="method has-srclink"><a class="srclink rightside" href="../../src/mio/net/udp.rs.html#288-290">source</a><h4 class="code-header">pub fn <a href="#method.send" class="fnname">send</a>(&amp;self, buf: &amp;[u8]) -&gt; Result&lt;usize&gt;</h4></section></summary><div class="docblock"><p>Sends data on the socket to the address previously bound via connect(). On success,
returns the number of bytes written.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.recv" class="method has-srclink"><a class="srclink rightside" href="../../src/mio/net/udp.rs.html#302-304">source</a><h4 class="code-header">pub fn <a href="#method.recv" class="fnname">recv</a>(&amp;self, buf: &amp;mut [u8]) -&gt; Result&lt;usize&gt;</h4></section></summary><div class="docblock"><p>Receives data from the socket previously bound with connect(). On success, returns
the number of bytes read.</p>
<h5 id="notes-2"><a href="#notes-2">Notes</a></h5>
<p>On Windows, if the data is larger than the buffer specified, the buffer
is filled with the first part of the data, and recv returns the error
WSAEMSGSIZE(10040). The excess data is lost.
Make sure to always use a sufficiently large buffer to hold the
maximum UDP packet size, which can be up to 65536 bytes in size.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.peek" class="method has-srclink"><a class="srclink rightside" href="../../src/mio/net/udp.rs.html#316-318">source</a><h4 class="code-header">pub fn <a href="#method.peek" class="fnname">peek</a>(&amp;self, buf: &amp;mut [u8]) -&gt; Result&lt;usize&gt;</h4></section></summary><div class="docblock"><p>Receives data from the socket, without removing it from the input queue.
On success, returns the number of bytes read.</p>
<h5 id="notes-3"><a href="#notes-3">Notes</a></h5>
<p>On Windows, if the data is larger than the buffer specified, the buffer
is filled with the first part of the data, and peek returns the error
WSAEMSGSIZE(10040). The excess data is lost.
Make sure to always use a sufficiently large buffer to hold the
maximum UDP packet size, which can be up to 65536 bytes in size.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.connect" class="method has-srclink"><a class="srclink rightside" href="../../src/mio/net/udp.rs.html#327-329">source</a><h4 class="code-header">pub fn <a href="#method.connect" class="fnname">connect</a>(&amp;self, addr: SocketAddr) -&gt; Result&lt;()&gt;</h4></section></summary><div class="docblock"><p>Connects the UDP socket setting the default destination for <code>send()</code>
and limiting packets that are read via <code>recv</code> from the address specified
in <code>addr</code>.</p>
<p>This may return a <code>WouldBlock</code> in which case the socket connection
cannot be completed immediately, it usually means there are insufficient
entries in the routing cache.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.set_broadcast" class="method has-srclink"><a class="srclink rightside" href="../../src/mio/net/udp.rs.html#355-357">source</a><h4 class="code-header">pub fn <a href="#method.set_broadcast" class="fnname">set_broadcast</a>(&amp;self, on: bool) -&gt; Result&lt;()&gt;</h4></section></summary><div class="docblock"><p>Sets the value of the <code>SO_BROADCAST</code> option for this socket.</p>
<p>When enabled, this socket is allowed to send packets to a broadcast
address.</p>
<h5 id="examples-7"><a href="#examples-7">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>mio::net::UdpSocket;
<span class="kw">let </span>broadcast_socket = UdpSocket::bind(<span class="string">&quot;127.0.0.1:0&quot;</span>.parse()<span class="question-mark">?</span>)<span class="question-mark">?</span>;
<span class="kw">if </span>broadcast_socket.broadcast()<span class="question-mark">? </span>== <span class="bool-val">false </span>{
broadcast_socket.set_broadcast(<span class="bool-val">true</span>)<span class="question-mark">?</span>;
}
<span class="macro">assert_eq!</span>(broadcast_socket.broadcast()<span class="question-mark">?</span>, <span class="bool-val">true</span>);</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.broadcast" class="method has-srclink"><a class="srclink rightside" href="../../src/mio/net/udp.rs.html#381-383">source</a><h4 class="code-header">pub fn <a href="#method.broadcast" class="fnname">broadcast</a>(&amp;self) -&gt; Result&lt;bool&gt;</h4></section></summary><div class="docblock"><p>Gets the value of the <code>SO_BROADCAST</code> option for this socket.</p>
<p>For more information about this option, see
<a href="#method.set_broadcast"><code>set_broadcast</code></a>.</p>
<h5 id="examples-8"><a href="#examples-8">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>mio::net::UdpSocket;
<span class="kw">let </span>broadcast_socket = UdpSocket::bind(<span class="string">&quot;127.0.0.1:0&quot;</span>.parse()<span class="question-mark">?</span>)<span class="question-mark">?</span>;
<span class="macro">assert_eq!</span>(broadcast_socket.broadcast()<span class="question-mark">?</span>, <span class="bool-val">false</span>);</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.set_multicast_loop_v4" class="method has-srclink"><a class="srclink rightside" href="../../src/mio/net/udp.rs.html#389-391">source</a><h4 class="code-header">pub fn <a href="#method.set_multicast_loop_v4" class="fnname">set_multicast_loop_v4</a>(&amp;self, on: bool) -&gt; Result&lt;()&gt;</h4></section></summary><div class="docblock"><p>Sets the value of the <code>IP_MULTICAST_LOOP</code> option for this socket.</p>
<p>If enabled, multicast packets will be looped back to the local socket.
Note that this may not have any affect on IPv6 sockets.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.multicast_loop_v4" class="method has-srclink"><a class="srclink rightside" href="../../src/mio/net/udp.rs.html#399-401">source</a><h4 class="code-header">pub fn <a href="#method.multicast_loop_v4" class="fnname">multicast_loop_v4</a>(&amp;self) -&gt; Result&lt;bool&gt;</h4></section></summary><div class="docblock"><p>Gets the value of the <code>IP_MULTICAST_LOOP</code> option for this socket.</p>
<p>For more information about this option, see
<a href="#method.set_multicast_loop_v4"><code>set_multicast_loop_v4</code></a>.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.set_multicast_ttl_v4" class="method has-srclink"><a class="srclink rightside" href="../../src/mio/net/udp.rs.html#410-412">source</a><h4 class="code-header">pub fn <a href="#method.set_multicast_ttl_v4" class="fnname">set_multicast_ttl_v4</a>(&amp;self, ttl: u32) -&gt; Result&lt;()&gt;</h4></section></summary><div class="docblock"><p>Sets the value of the <code>IP_MULTICAST_TTL</code> option for this socket.</p>
<p>Indicates the time-to-live value of outgoing multicast packets for
this socket. The default value is 1 which means that multicast packets
don’t leave the local network unless explicitly requested.</p>
<p>Note that this may not have any affect on IPv6 sockets.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.multicast_ttl_v4" class="method has-srclink"><a class="srclink rightside" href="../../src/mio/net/udp.rs.html#420-422">source</a><h4 class="code-header">pub fn <a href="#method.multicast_ttl_v4" class="fnname">multicast_ttl_v4</a>(&amp;self) -&gt; Result&lt;u32&gt;</h4></section></summary><div class="docblock"><p>Gets the value of the <code>IP_MULTICAST_TTL</code> option for this socket.</p>
<p>For more information about this option, see
<a href="#method.set_multicast_ttl_v4"><code>set_multicast_ttl_v4</code></a>.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.set_multicast_loop_v6" class="method has-srclink"><a class="srclink rightside" href="../../src/mio/net/udp.rs.html#428-430">source</a><h4 class="code-header">pub fn <a href="#method.set_multicast_loop_v6" class="fnname">set_multicast_loop_v6</a>(&amp;self, on: bool) -&gt; Result&lt;()&gt;</h4></section></summary><div class="docblock"><p>Sets the value of the <code>IPV6_MULTICAST_LOOP</code> option for this socket.</p>
<p>Controls whether this socket sees the multicast packets it sends itself.
Note that this may not have any affect on IPv4 sockets.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.multicast_loop_v6" class="method has-srclink"><a class="srclink rightside" href="../../src/mio/net/udp.rs.html#438-440">source</a><h4 class="code-header">pub fn <a href="#method.multicast_loop_v6" class="fnname">multicast_loop_v6</a>(&amp;self) -&gt; Result&lt;bool&gt;</h4></section></summary><div class="docblock"><p>Gets the value of the <code>IPV6_MULTICAST_LOOP</code> option for this socket.</p>
<p>For more information about this option, see
<a href="#method.set_multicast_loop_v6"><code>set_multicast_loop_v6</code></a>.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.set_ttl" class="method has-srclink"><a class="srclink rightside" href="../../src/mio/net/udp.rs.html#466-468">source</a><h4 class="code-header">pub fn <a href="#method.set_ttl" class="fnname">set_ttl</a>(&amp;self, ttl: u32) -&gt; Result&lt;()&gt;</h4></section></summary><div class="docblock"><p>Sets the value for the <code>IP_TTL</code> option on this socket.</p>
<p>This value sets the time-to-live field that is used in every packet sent
from this socket.</p>
<h5 id="examples-9"><a href="#examples-9">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>mio::net::UdpSocket;
<span class="kw">let </span>socket = UdpSocket::bind(<span class="string">&quot;127.0.0.1:0&quot;</span>.parse()<span class="question-mark">?</span>)<span class="question-mark">?</span>;
<span class="kw">if </span>socket.ttl()<span class="question-mark">? </span>&lt; <span class="number">255 </span>{
socket.set_ttl(<span class="number">255</span>)<span class="question-mark">?</span>;
}
<span class="macro">assert_eq!</span>(socket.ttl()<span class="question-mark">?</span>, <span class="number">255</span>);</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.ttl" class="method has-srclink"><a class="srclink rightside" href="../../src/mio/net/udp.rs.html#493-495">source</a><h4 class="code-header">pub fn <a href="#method.ttl" class="fnname">ttl</a>(&amp;self) -&gt; Result&lt;u32&gt;</h4></section></summary><div class="docblock"><p>Gets the value of the <code>IP_TTL</code> option for this socket.</p>
<p>For more information about this option, see <a href="#method.set_ttl"><code>set_ttl</code></a>.</p>
<h5 id="examples-10"><a href="#examples-10">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>mio::net::UdpSocket;
<span class="kw">let </span>socket = UdpSocket::bind(<span class="string">&quot;127.0.0.1:0&quot;</span>.parse()<span class="question-mark">?</span>)<span class="question-mark">?</span>;
socket.set_ttl(<span class="number">255</span>)<span class="question-mark">?</span>;
<span class="macro">assert_eq!</span>(socket.ttl()<span class="question-mark">?</span>, <span class="number">255</span>);</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.join_multicast_v4" class="method has-srclink"><a class="srclink rightside" href="../../src/mio/net/udp.rs.html#505-507">source</a><h4 class="code-header">pub fn <a href="#method.join_multicast_v4" class="fnname">join_multicast_v4</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;self,<br>&nbsp;&nbsp;&nbsp;&nbsp;multiaddr: &amp;Ipv4Addr,<br>&nbsp;&nbsp;&nbsp;&nbsp;interface: &amp;Ipv4Addr<br>) -&gt; Result&lt;()&gt;</h4></section></summary><div class="docblock"><p>Executes an operation of the <code>IP_ADD_MEMBERSHIP</code> type.</p>
<p>This function specifies a new multicast group for this socket to join.
The address must be a valid multicast address, and <code>interface</code> is the
address of the local interface with which the system should join the
multicast group. If it’s equal to <code>INADDR_ANY</code> then an appropriate
interface is chosen by the system.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.join_multicast_v6" class="method has-srclink"><a class="srclink rightside" href="../../src/mio/net/udp.rs.html#515-517">source</a><h4 class="code-header">pub fn <a href="#method.join_multicast_v6" class="fnname">join_multicast_v6</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;self,<br>&nbsp;&nbsp;&nbsp;&nbsp;multiaddr: &amp;Ipv6Addr,<br>&nbsp;&nbsp;&nbsp;&nbsp;interface: u32<br>) -&gt; Result&lt;()&gt;</h4></section></summary><div class="docblock"><p>Executes an operation of the <code>IPV6_ADD_MEMBERSHIP</code> type.</p>
<p>This function specifies a new multicast group for this socket to join.
The address must be a valid multicast address, and <code>interface</code> is the
index of the interface to join/leave (or 0 to indicate any interface).</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.leave_multicast_v4" class="method has-srclink"><a class="srclink rightside" href="../../src/mio/net/udp.rs.html#526-528">source</a><h4 class="code-header">pub fn <a href="#method.leave_multicast_v4" class="fnname">leave_multicast_v4</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;self,<br>&nbsp;&nbsp;&nbsp;&nbsp;multiaddr: &amp;Ipv4Addr,<br>&nbsp;&nbsp;&nbsp;&nbsp;interface: &amp;Ipv4Addr<br>) -&gt; Result&lt;()&gt;</h4></section></summary><div class="docblock"><p>Executes an operation of the <code>IP_DROP_MEMBERSHIP</code> type.</p>
<p>For more information about this option, see
<a href="#method.join_multicast_v4"><code>join_multicast_v4</code></a>.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.leave_multicast_v6" class="method has-srclink"><a class="srclink rightside" href="../../src/mio/net/udp.rs.html#537-539">source</a><h4 class="code-header">pub fn <a href="#method.leave_multicast_v6" class="fnname">leave_multicast_v6</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;self,<br>&nbsp;&nbsp;&nbsp;&nbsp;multiaddr: &amp;Ipv6Addr,<br>&nbsp;&nbsp;&nbsp;&nbsp;interface: u32<br>) -&gt; Result&lt;()&gt;</h4></section></summary><div class="docblock"><p>Executes an operation of the <code>IPV6_DROP_MEMBERSHIP</code> type.</p>
<p>For more information about this option, see
<a href="#method.join_multicast_v6"><code>join_multicast_v6</code></a>.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.only_v6" class="method has-srclink"><a class="srclink rightside" href="../../src/mio/net/udp.rs.html#543-545">source</a><h4 class="code-header">pub fn <a href="#method.only_v6" class="fnname">only_v6</a>(&amp;self) -&gt; Result&lt;bool&gt;</h4></section></summary><div class="docblock"><p>Get the value of the <code>IPV6_V6ONLY</code> option on this socket.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.take_error" class="method has-srclink"><a class="srclink rightside" href="../../src/mio/net/udp.rs.html#552-554">source</a><h4 class="code-header">pub fn <a href="#method.take_error" class="fnname">take_error</a>(&amp;self) -&gt; Result&lt;Option&lt;Error&gt;&gt;</h4></section></summary><div class="docblock"><p>Get the value of the <code>SO_ERROR</code> option on this socket.</p>
<p>This will retrieve the stored error in the underlying socket, clearing
the field in the process. This can be useful for checking errors between
calls.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.try_io" class="method has-srclink"><a class="srclink rightside" href="../../src/mio/net/udp.rs.html#607-612">source</a><h4 class="code-header">pub fn <a href="#method.try_io" class="fnname">try_io</a>&lt;F, T&gt;(&amp;self, f: F) -&gt; Result&lt;T&gt;<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;F: FnOnce() -&gt; Result&lt;T&gt;,</span></h4></section></summary><div class="docblock"><p>Execute an I/O operation ensuring that the socket receives more events
if it hits a <a href="io::ErrorKind::WouldBlock"><code>WouldBlock</code></a> error.</p>
<h5 id="notes-4"><a href="#notes-4">Notes</a></h5>
<p>This method is required to be called for <strong>all</strong> I/O operations to
ensure the user will receive events once the socket is ready again after
returning a <a href="io::ErrorKind::WouldBlock"><code>WouldBlock</code></a> error.</p>
<h5 id="examples-11"><a href="#examples-11">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::io;
<span class="attribute">#[cfg(unix)]
</span><span class="kw">use </span>std::os::unix::io::AsRawFd;
<span class="attribute">#[cfg(windows)]
</span><span class="kw">use </span>std::os::windows::io::AsRawSocket;
<span class="kw">use </span>mio::net::UdpSocket;
<span class="kw">let </span>address = <span class="string">&quot;127.0.0.1:8080&quot;</span>.parse().unwrap();
<span class="kw">let </span>dgram = UdpSocket::bind(address)<span class="question-mark">?</span>;
<span class="comment">// Wait until the dgram is readable...
// Read from the dgram using a direct libc call, of course the
// `io::Read` implementation would be easier to use.
</span><span class="kw">let </span><span class="kw-2">mut </span>buf = [<span class="number">0</span>; <span class="number">512</span>];
<span class="kw">let </span>n = dgram.try_io(|| {
<span class="kw">let </span>buf_ptr = <span class="kw-2">&amp;mut </span>buf <span class="kw">as </span><span class="kw-2">*mut </span><span class="kw">_ as </span><span class="kw-2">*mut </span><span class="kw">_</span>;
<span class="attribute">#[cfg(unix)]
</span><span class="kw">let </span>res = <span class="kw">unsafe </span>{ libc::recv(dgram.as_raw_fd(), buf_ptr, buf.len(), <span class="number">0</span>) };
<span class="attribute">#[cfg(windows)]
</span><span class="kw">let </span>res = <span class="kw">unsafe </span>{ libc::recvfrom(dgram.as_raw_socket() <span class="kw">as </span>usize, buf_ptr, buf.len() <span class="kw">as </span>i32, <span class="number">0</span>, std::ptr::null_mut(), std::ptr::null_mut()) };
<span class="kw">if </span>res != -<span class="number">1 </span>{
<span class="prelude-val">Ok</span>(res <span class="kw">as </span>usize)
} <span class="kw">else </span>{
<span class="comment">// If EAGAIN or EWOULDBLOCK is set by libc::recv, the closure
// should return `WouldBlock` error.
</span><span class="prelude-val">Err</span>(io::Error::last_os_error())
}
})<span class="question-mark">?</span>;
<span class="macro">eprintln!</span>(<span class="string">&quot;read {} bytes&quot;</span>, n);</code></pre></div>
</div></details></div></details></div><h2 id="trait-implementations" class="small-section-header">Trait Implementations<a href="#trait-implementations" class="anchor"></a></h2><div id="trait-implementations-list"><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-AsRawFd-for-UdpSocket" class="impl has-srclink"><a class="srclink rightside" href="../../src/mio/net/udp.rs.html#653-657">source</a><a href="#impl-AsRawFd-for-UdpSocket" class="anchor"></a><h3 class="code-header">impl AsRawFd for <a class="struct" href="struct.UdpSocket.html" title="struct mio::net::UdpSocket">UdpSocket</a></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.as_raw_fd" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/mio/net/udp.rs.html#654-656">source</a><a href="#method.as_raw_fd" class="anchor"></a><h4 class="code-header">fn <a class="fnname">as_raw_fd</a>(&amp;self) -&gt; RawFd</h4></section></summary><div class='docblock'>Extracts the raw file descriptor. <a>Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-Debug-for-UdpSocket" class="impl has-srclink"><a class="srclink rightside" href="../../src/mio/net/udp.rs.html#639-643">source</a><a href="#impl-Debug-for-UdpSocket" class="anchor"></a><h3 class="code-header">impl Debug for <a class="struct" href="struct.UdpSocket.html" title="struct mio::net::UdpSocket">UdpSocket</a></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.fmt" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/mio/net/udp.rs.html#640-642">source</a><a href="#method.fmt" class="anchor"></a><h4 class="code-header">fn <a class="fnname">fmt</a>(&amp;self, f: &amp;mut Formatter&lt;'_&gt;) -&gt; Result</h4></section></summary><div class='docblock'>Formats the value using the given formatter. <a>Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-FromRawFd-for-UdpSocket" class="impl has-srclink"><a class="srclink rightside" href="../../src/mio/net/udp.rs.html#660-670">source</a><a href="#impl-FromRawFd-for-UdpSocket" class="anchor"></a><h3 class="code-header">impl FromRawFd for <a class="struct" href="struct.UdpSocket.html" title="struct mio::net::UdpSocket">UdpSocket</a></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.from_raw_fd" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/mio/net/udp.rs.html#667-669">source</a><a href="#method.from_raw_fd" class="anchor"></a><h4 class="code-header">unsafe fn <a class="fnname">from_raw_fd</a>(fd: RawFd) -&gt; <a class="struct" href="struct.UdpSocket.html" title="struct mio::net::UdpSocket">UdpSocket</a></h4></section></summary><div class="docblock"><p>Converts a <code>RawFd</code> to a <code>UdpSocket</code>.</p>
<h5 id="notes-5"><a href="#notes-5">Notes</a></h5>
<p>The caller is responsible for ensuring that the socket is in
non-blocking mode.</p>
</div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-IntoRawFd-for-UdpSocket" class="impl has-srclink"><a class="srclink rightside" href="../../src/mio/net/udp.rs.html#646-650">source</a><a href="#impl-IntoRawFd-for-UdpSocket" class="anchor"></a><h3 class="code-header">impl IntoRawFd for <a class="struct" href="struct.UdpSocket.html" title="struct mio::net::UdpSocket">UdpSocket</a></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.into_raw_fd" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/mio/net/udp.rs.html#647-649">source</a><a href="#method.into_raw_fd" class="anchor"></a><h4 class="code-header">fn <a class="fnname">into_raw_fd</a>(self) -&gt; RawFd</h4></section></summary><div class='docblock'>Consumes this object, returning the raw underlying file descriptor. <a>Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-Source-for-UdpSocket" class="impl has-srclink"><a class="srclink rightside" href="../../src/mio/net/udp.rs.html#615-637">source</a><a href="#impl-Source-for-UdpSocket" class="anchor"></a><h3 class="code-header">impl <a class="trait" href="../event/trait.Source.html" title="trait mio::event::Source">Source</a> for <a class="struct" href="struct.UdpSocket.html" title="struct mio::net::UdpSocket">UdpSocket</a></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.register" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/mio/net/udp.rs.html#616-623">source</a><a href="#method.register" class="anchor"></a><h4 class="code-header">fn <a href="../event/trait.Source.html#tymethod.register" class="fnname">register</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;mut self,<br>&nbsp;&nbsp;&nbsp;&nbsp;registry: &amp;<a class="struct" href="../struct.Registry.html" title="struct mio::Registry">Registry</a>,<br>&nbsp;&nbsp;&nbsp;&nbsp;token: <a class="struct" href="../struct.Token.html" title="struct mio::Token">Token</a>,<br>&nbsp;&nbsp;&nbsp;&nbsp;interests: <a class="struct" href="../struct.Interest.html" title="struct mio::Interest">Interest</a><br>) -&gt; Result&lt;()&gt;</h4></section></summary><div class='docblock'>Register <code>self</code> with the given <code>Registry</code> instance. <a href="../event/trait.Source.html#tymethod.register">Read more</a></div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.reregister" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/mio/net/udp.rs.html#625-632">source</a><a href="#method.reregister" class="anchor"></a><h4 class="code-header">fn <a href="../event/trait.Source.html#tymethod.reregister" class="fnname">reregister</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;mut self,<br>&nbsp;&nbsp;&nbsp;&nbsp;registry: &amp;<a class="struct" href="../struct.Registry.html" title="struct mio::Registry">Registry</a>,<br>&nbsp;&nbsp;&nbsp;&nbsp;token: <a class="struct" href="../struct.Token.html" title="struct mio::Token">Token</a>,<br>&nbsp;&nbsp;&nbsp;&nbsp;interests: <a class="struct" href="../struct.Interest.html" title="struct mio::Interest">Interest</a><br>) -&gt; Result&lt;()&gt;</h4></section></summary><div class='docblock'>Re-register <code>self</code> with the given <code>Registry</code> instance. <a href="../event/trait.Source.html#tymethod.reregister">Read more</a></div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.deregister" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/mio/net/udp.rs.html#634-636">source</a><a href="#method.deregister" class="anchor"></a><h4 class="code-header">fn <a href="../event/trait.Source.html#tymethod.deregister" class="fnname">deregister</a>(&amp;mut self, registry: &amp;<a class="struct" href="../struct.Registry.html" title="struct mio::Registry">Registry</a>) -&gt; Result&lt;()&gt;</h4></section></summary><div class='docblock'>Deregister <code>self</code> from the given <code>Registry</code> instance. <a href="../event/trait.Source.html#tymethod.deregister">Read more</a></div></details></div></details></div><h2 id="synthetic-implementations" class="small-section-header">Auto Trait Implementations<a href="#synthetic-implementations" class="anchor"></a></h2><div id="synthetic-implementations-list"><section id="impl-RefUnwindSafe-for-UdpSocket" class="impl has-srclink"><a href="#impl-RefUnwindSafe-for-UdpSocket" class="anchor"></a><h3 class="code-header">impl RefUnwindSafe for <a class="struct" href="struct.UdpSocket.html" title="struct mio::net::UdpSocket">UdpSocket</a></h3></section><section id="impl-Send-for-UdpSocket" class="impl has-srclink"><a href="#impl-Send-for-UdpSocket" class="anchor"></a><h3 class="code-header">impl Send for <a class="struct" href="struct.UdpSocket.html" title="struct mio::net::UdpSocket">UdpSocket</a></h3></section><section id="impl-Sync-for-UdpSocket" class="impl has-srclink"><a href="#impl-Sync-for-UdpSocket" class="anchor"></a><h3 class="code-header">impl Sync for <a class="struct" href="struct.UdpSocket.html" title="struct mio::net::UdpSocket">UdpSocket</a></h3></section><section id="impl-Unpin-for-UdpSocket" class="impl has-srclink"><a href="#impl-Unpin-for-UdpSocket" class="anchor"></a><h3 class="code-header">impl Unpin for <a class="struct" href="struct.UdpSocket.html" title="struct mio::net::UdpSocket">UdpSocket</a></h3></section><section id="impl-UnwindSafe-for-UdpSocket" class="impl has-srclink"><a href="#impl-UnwindSafe-for-UdpSocket" class="anchor"></a><h3 class="code-header">impl UnwindSafe for <a class="struct" href="struct.UdpSocket.html" title="struct mio::net::UdpSocket">UdpSocket</a></h3></section></div><h2 id="blanket-implementations" class="small-section-header">Blanket Implementations<a href="#blanket-implementations" class="anchor"></a></h2><div id="blanket-implementations-list"><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-Any-for-UdpSocket" class="impl has-srclink"><a href="#impl-Any-for-UdpSocket" class="anchor"></a><h3 class="code-header">impl&lt;T&gt; Any for T<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: 'static + ?Sized,</span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.type_id" class="method trait-impl has-srclink"><a href="#method.type_id" class="anchor"></a><h4 class="code-header">fn <a class="fnname">type_id</a>(&amp;self) -&gt; TypeId</h4></section></summary><div class='docblock'>Gets the <code>TypeId</code> of <code>self</code>. <a>Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-Borrow%3CT%3E-for-UdpSocket" class="impl has-srclink"><a href="#impl-Borrow%3CT%3E-for-UdpSocket" class="anchor"></a><h3 class="code-header">impl&lt;T&gt; Borrow&lt;T&gt; for T<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: ?Sized,</span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.borrow" class="method trait-impl has-srclink"><span class="since rightside" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/91522" title="Tracking issue for const_borrow">unstable</a></span><a href="#method.borrow" class="anchor"></a><h4 class="code-header">fn <a class="fnname">borrow</a>(&amp;self) -&gt; &amp;T</h4></section></summary><div class='docblock'>Immutably borrows from an owned value. <a>Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-BorrowMut%3CT%3E-for-UdpSocket" class="impl has-srclink"><a href="#impl-BorrowMut%3CT%3E-for-UdpSocket" class="anchor"></a><h3 class="code-header">impl&lt;T&gt; BorrowMut&lt;T&gt; for T<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: ?Sized,</span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.borrow_mut" class="method trait-impl has-srclink"><span class="since rightside" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/91522" title="Tracking issue for const_borrow">unstable</a></span><a href="#method.borrow_mut" class="anchor"></a><h4 class="code-header">fn <a class="fnname">borrow_mut</a>(&amp;mut self) -&gt; &amp;mut T</h4></section></summary><div class='docblock'>Mutably borrows from an owned value. <a>Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-From%3CT%3E-for-UdpSocket" class="impl has-srclink"><a href="#impl-From%3CT%3E-for-UdpSocket" class="anchor"></a><h3 class="code-header">impl&lt;T&gt; From&lt;T&gt; for T</h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.from" class="method trait-impl has-srclink"><span class="since rightside" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/88674" title="Tracking issue for const_convert">unstable</a></span><a href="#method.from" class="anchor"></a><h4 class="code-header">fn <a class="fnname">from</a>(t: T) -&gt; T</h4></section></summary><div class="docblock"><p>Returns the argument unchanged.</p>
</div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-Into%3CU%3E-for-UdpSocket" class="impl has-srclink"><a href="#impl-Into%3CU%3E-for-UdpSocket" class="anchor"></a><h3 class="code-header">impl&lt;T, U&gt; Into&lt;U&gt; for T<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;U: From&lt;T&gt;,</span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.into" class="method trait-impl has-srclink"><span class="since rightside" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/88674" title="Tracking issue for const_convert">unstable</a></span><a href="#method.into" class="anchor"></a><h4 class="code-header">fn <a class="fnname">into</a>(self) -&gt; U</h4></section></summary><div class="docblock"><p>Calls <code>U::from(self)</code>.</p>
<p>That is, this conversion is whatever the implementation of
<code>[From]&lt;T&gt; for U</code> chooses to do.</p>
</div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-TryFrom%3CU%3E-for-UdpSocket" class="impl has-srclink"><a href="#impl-TryFrom%3CU%3E-for-UdpSocket" class="anchor"></a><h3 class="code-header">impl&lt;T, U&gt; TryFrom&lt;U&gt; for T<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;U: Into&lt;T&gt;,</span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle" open><summary><section id="associatedtype.Error-1" class="associatedtype trait-impl has-srclink"><a href="#associatedtype.Error-1" class="anchor"></a><h4 class="code-header">type <a class="associatedtype">Error</a> = Infallible</h4></section></summary><div class='docblock'>The type returned in the event of a conversion error.</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.try_from" class="method trait-impl has-srclink"><span class="since rightside" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/88674" title="Tracking issue for const_convert">unstable</a></span><a href="#method.try_from" class="anchor"></a><h4 class="code-header">fn <a class="fnname">try_from</a>(value: U) -&gt; Result&lt;T, &lt;T as TryFrom&lt;U&gt;&gt;::Error&gt;</h4></section></summary><div class='docblock'>Performs the conversion.</div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-TryInto%3CU%3E-for-UdpSocket" class="impl has-srclink"><a href="#impl-TryInto%3CU%3E-for-UdpSocket" class="anchor"></a><h3 class="code-header">impl&lt;T, U&gt; TryInto&lt;U&gt; for T<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;U: TryFrom&lt;T&gt;,</span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle" open><summary><section id="associatedtype.Error" class="associatedtype trait-impl has-srclink"><a href="#associatedtype.Error" class="anchor"></a><h4 class="code-header">type <a class="associatedtype">Error</a> = &lt;U as TryFrom&lt;T&gt;&gt;::Error</h4></section></summary><div class='docblock'>The type returned in the event of a conversion error.</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.try_into" class="method trait-impl has-srclink"><span class="since rightside" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/88674" title="Tracking issue for const_convert">unstable</a></span><a href="#method.try_into" class="anchor"></a><h4 class="code-header">fn <a class="fnname">try_into</a>(self) -&gt; Result&lt;U, &lt;U as TryFrom&lt;T&gt;&gt;::Error&gt;</h4></section></summary><div class='docblock'>Performs the conversion.</div></details></div></details></div></section></div></main><div id="rustdoc-vars" data-root-path="../../" data-current-crate="mio" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.66.0-nightly (5c8bff74b 2022-10-21)" ></div></body></html>