|
|
<!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."><title>UdpSocket in mio::net - Rust</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/SourceSerif4-Regular-46f98efaafac5295.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/FiraSans-Regular-018c141bf0843ffd.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/FiraSans-Medium-8f9a781e4970d388.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2"><link rel="stylesheet" href="../../static.files/normalize-76eba96aa4d2e634.css"><link rel="stylesheet" href="../../static.files/rustdoc-ac92e1bbe349e143.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="mio" data-themes="" data-resource-suffix="" data-rustdoc-version="1.76.0 (07dca489a 2024-02-04)" data-channel="1.76.0" data-search-js="search-2b6ce74ff89ae146.js" data-settings-js="settings-4313503d2e1961c2.js" ><script src="../../static.files/storage-f2adc0d6ca4d09fb.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../static.files/main-305769736d49e732.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-feafe1bb7466e4bd.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-16x16-8b506e7a72182f1c.png"><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-422f7d1d52889060.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-2c020d218678b618.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">☰</button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../mio/index.html">mio</a><span class="version">1.0.3</span></h2></div><h2 class="location"><a href="#">UdpSocket</a></h2><div class="sidebar-elems"><section><h3><a href="#implementations">Methods</a></h3><ul class="block method"><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 trait-implementation"><li><a href="#impl-AsFd-for-UdpSocket">AsFd</a></li><li><a href="#impl-AsRawFd-for-UdpSocket">AsRawFd</a></li><li><a href="#impl-Debug-for-UdpSocket">Debug</a></li><li><a href="#impl-From%3COwnedFd%3E-for-UdpSocket">From<OwnedFd></a></li><li><a href="#impl-From%3CUdpSocket%3E-for-OwnedFd">From<UdpSocket></a></li><li><a href="#impl-From%3CUdpSocket%3E-for-UdpSocket">From<UdpSocket></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 synthetic-implementation"><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 blanket-implementation"><li><a href="#impl-Any-for-T">Any</a></li><li><a href="#impl-Borrow%3CT%3E-for-T">Borrow<T></a></li><li><a href="#impl-BorrowMut%3CT%3E-for-T">BorrowMut<T></a></li><li><a href="#impl-From%3CT%3E-for-T">From<T></a></li><li><a href="#impl-Into%3CU%3E-for-T">Into<U></a></li><li><a href="#impl-TryFrom%3CU%3E-for-T">TryFrom<U></a></li><li><a href="#impl-TryInto%3CU%3E-for-T">TryInto<U></a></li></ul></section><h2><a href="index.html">In mio::net</a></h2></div></nav><div class="sidebar-resizer"></div>
|
|
|
<main><div class="width-limiter"><nav class="sub"><form class="search-form"><span></span><div id="sidebar-button" tabindex="-1"><a href="../../mio/all.html" title="show sidebar"></a></div><input class="search-input" name="search" aria-label="Run search in the documentation" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><div id="help-button" tabindex="-1"><a href="../../help.html" title="help">?</a></div><div id="settings-menu" tabindex="-1"><a href="../../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../../static.files/wheel-7b819b6101059cd0.svg"></a></div></form></nav><section id="main-content" class="content"><div class="main-heading"><h1>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" title="Copy item path to clipboard"><img src="../../static.files/clipboard-7571035ce49a181d.svg" width="19" height="18" alt="Copy item path"></button></h1><span class="out-of-band"><a class="src" href="../../src/mio/net/udp.rs.html#95-97">source</a> · <button id="toggle-all-docs" title="collapse all docs">[<span>−</span>]</button></span></div><pre class="rust item-decl"><code>pub struct UdpSocket { <span class="comment">/* private fields */</span> }</code></pre><details class="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 -> sends a message.
|
|
|
// ECHOER -> 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">"127.0.0.1:0"</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">"127.0.0.1:0"</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">&mut </span>sender_socket, SENDER, Interest::WRITABLE)<span class="question-mark">?</span>;
|
|
|
poll.registry().register(<span class="kw-2">&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">&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 => {
|
|
|
<span class="kw">let </span>bytes_sent = sender_socket.send(<span class="kw-2">&</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">"sent {:?} -> {:?} bytes"</span>, msg_to_send, bytes_sent);
|
|
|
},
|
|
|
<span class="comment">// Our ECHOER is ready to be read from.
|
|
|
</span>ECHOER => {
|
|
|
<span class="kw">let </span>num_recv = echoer_socket.recv(<span class="kw-2">&mut </span>buffer)<span class="question-mark">?</span>;
|
|
|
<span class="macro">println!</span>(<span class="string">"echo {:?} -> {:?}"</span>, buffer, num_recv);
|
|
|
buffer = [<span class="number">0</span>; <span class="number">9</span>];
|
|
|
}
|
|
|
<span class="kw">_ </span>=> <span class="macro">unreachable!</span>()
|
|
|
}
|
|
|
}
|
|
|
}</code></pre></div>
|
|
|
</div></details><h2 id="implementations" class="section-header">Implementations<a href="#implementations" class="anchor">§</a></h2><div id="implementations-list"><details class="toggle implementors-toggle" open><summary><section id="impl-UdpSocket" class="impl"><a class="src rightside" href="../../src/mio/net/udp.rs.html#99-617">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="toggle method-toggle" open><summary><section id="method.bind" class="method"><a class="src rightside" href="../../src/mio/net/udp.rs.html#125-127">source</a><h4 class="code-header">pub fn <a href="#method.bind" class="fn">bind</a>(addr: <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/net/socket_addr/enum.SocketAddr.html" title="enum core::net::socket_addr::SocketAddr">SocketAddr</a>) -> <a class="type" href="https://doc.rust-lang.org/1.76.0/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a><<a class="struct" href="struct.UdpSocket.html" title="struct mio::net::UdpSocket">UdpSocket</a>></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">"127.0.0.1:0"</span>.parse()<span class="question-mark">?</span>) {
|
|
|
<span class="prelude-val">Ok</span>(new_socket) => new_socket,
|
|
|
<span class="prelude-val">Err</span>(fail) => {
|
|
|
<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">"Failed to bind socket. {:?}"</span>, fail);
|
|
|
}
|
|
|
};
|
|
|
|
|
|
<span class="comment">// Our socket was created, but we should not use it before checking it's readiness.</span></code></pre></div>
|
|
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.from_std" class="method"><a class="src rightside" href="../../src/mio/net/udp.rs.html#135-139">source</a><h4 class="code-header">pub fn <a href="#method.from_std" class="fn">from_std</a>(socket: <a class="struct" href="https://doc.rust-lang.org/1.76.0/std/net/udp/struct.UdpSocket.html" title="struct std::net::udp::UdpSocket">UdpSocket</a>) -> <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="toggle method-toggle" open><summary><section id="method.local_addr" class="method"><a class="src rightside" href="../../src/mio/net/udp.rs.html#164-166">source</a><h4 class="code-header">pub fn <a href="#method.local_addr" class="fn">local_addr</a>(&self) -> <a class="type" href="https://doc.rust-lang.org/1.76.0/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a><<a class="enum" href="https://doc.rust-lang.org/1.76.0/core/net/socket_addr/enum.SocketAddr.html" title="enum core::net::socket_addr::SocketAddr">SocketAddr</a>></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">"127.0.0.1:0"</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="toggle method-toggle" open><summary><section id="method.peer_addr" class="method"><a class="src rightside" href="../../src/mio/net/udp.rs.html#187-189">source</a><h4 class="code-header">pub fn <a href="#method.peer_addr" class="fn">peer_addr</a>(&self) -> <a class="type" href="https://doc.rust-lang.org/1.76.0/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a><<a class="enum" href="https://doc.rust-lang.org/1.76.0/core/net/socket_addr/enum.SocketAddr.html" title="enum core::net::socket_addr::SocketAddr">SocketAddr</a>></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">"127.0.0.1:0"</span>.parse()<span class="question-mark">?</span>;
|
|
|
<span class="kw">let </span>peer_addr = <span class="string">"127.0.0.1:11100"</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="toggle method-toggle" open><summary><section id="method.send_to" class="method"><a class="src rightside" href="../../src/mio/net/udp.rs.html#215-217">source</a><h4 class="code-header">pub fn <a href="#method.send_to" class="fn">send_to</a>(&self, buf: &[<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.u8.html">u8</a>], target: <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/net/socket_addr/enum.SocketAddr.html" title="enum core::net::socket_addr::SocketAddr">SocketAddr</a>) -> <a class="type" href="https://doc.rust-lang.org/1.76.0/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>></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">"127.0.0.1:0"</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">&</span>[<span class="number">9</span>; <span class="number">9</span>], <span class="string">"127.0.0.1:11100"</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="toggle method-toggle" open><summary><section id="method.recv_from" class="method"><a class="src rightside" href="../../src/mio/net/udp.rs.html#250-252">source</a><h4 class="code-header">pub fn <a href="#method.recv_from" class="fn">recv_from</a>(&self, buf: &mut [<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.u8.html">u8</a>]) -> <a class="type" href="https://doc.rust-lang.org/1.76.0/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a><(<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>, <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/net/socket_addr/enum.SocketAddr.html" title="enum core::net::socket_addr::SocketAddr">SocketAddr</a>)></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">"127.0.0.1:0"</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">&mut </span>buf)<span class="question-mark">?</span>;
|
|
|
<span class="macro">println!</span>(<span class="string">"Received {:?} -> {:?} bytes from {:?}"</span>, buf, num_recv, from_addr);</code></pre></div>
|
|
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.peek_from" class="method"><a class="src rightside" href="../../src/mio/net/udp.rs.html#286-288">source</a><h4 class="code-header">pub fn <a href="#method.peek_from" class="fn">peek_from</a>(&self, buf: &mut [<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.u8.html">u8</a>]) -> <a class="type" href="https://doc.rust-lang.org/1.76.0/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a><(<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>, <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/net/socket_addr/enum.SocketAddr.html" title="enum core::net::socket_addr::SocketAddr">SocketAddr</a>)></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">"127.0.0.1:0"</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">&mut </span>buf)<span class="question-mark">?</span>;
|
|
|
<span class="macro">println!</span>(<span class="string">"Received {:?} -> {:?} bytes from {:?}"</span>, buf, num_recv, from_addr);</code></pre></div>
|
|
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.send" class="method"><a class="src rightside" href="../../src/mio/net/udp.rs.html#292-294">source</a><h4 class="code-header">pub fn <a href="#method.send" class="fn">send</a>(&self, buf: &[<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.u8.html">u8</a>]) -> <a class="type" href="https://doc.rust-lang.org/1.76.0/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>></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="toggle method-toggle" open><summary><section id="method.recv" class="method"><a class="src rightside" href="../../src/mio/net/udp.rs.html#306-308">source</a><h4 class="code-header">pub fn <a href="#method.recv" class="fn">recv</a>(&self, buf: &mut [<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.u8.html">u8</a>]) -> <a class="type" href="https://doc.rust-lang.org/1.76.0/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>></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="toggle method-toggle" open><summary><section id="method.peek" class="method"><a class="src rightside" href="../../src/mio/net/udp.rs.html#320-322">source</a><h4 class="code-header">pub fn <a href="#method.peek" class="fn">peek</a>(&self, buf: &mut [<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.u8.html">u8</a>]) -> <a class="type" href="https://doc.rust-lang.org/1.76.0/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>></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="toggle method-toggle" open><summary><section id="method.connect" class="method"><a class="src rightside" href="../../src/mio/net/udp.rs.html#331-333">source</a><h4 class="code-header">pub fn <a href="#method.connect" class="fn">connect</a>(&self, addr: <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/net/socket_addr/enum.SocketAddr.html" title="enum core::net::socket_addr::SocketAddr">SocketAddr</a>) -> <a class="type" href="https://doc.rust-lang.org/1.76.0/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.unit.html">()</a>></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="toggle method-toggle" open><summary><section id="method.set_broadcast" class="method"><a class="src rightside" href="../../src/mio/net/udp.rs.html#359-361">source</a><h4 class="code-header">pub fn <a href="#method.set_broadcast" class="fn">set_broadcast</a>(&self, on: <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.bool.html">bool</a>) -> <a class="type" href="https://doc.rust-lang.org/1.76.0/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.unit.html">()</a>></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">"127.0.0.1:0"</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="toggle method-toggle" open><summary><section id="method.broadcast" class="method"><a class="src rightside" href="../../src/mio/net/udp.rs.html#385-387">source</a><h4 class="code-header">pub fn <a href="#method.broadcast" class="fn">broadcast</a>(&self) -> <a class="type" href="https://doc.rust-lang.org/1.76.0/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.bool.html">bool</a>></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">"127.0.0.1:0"</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="toggle method-toggle" open><summary><section id="method.set_multicast_loop_v4" class="method"><a class="src rightside" href="../../src/mio/net/udp.rs.html#393-395">source</a><h4 class="code-header">pub fn <a href="#method.set_multicast_loop_v4" class="fn">set_multicast_loop_v4</a>(&self, on: <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.bool.html">bool</a>) -> <a class="type" href="https://doc.rust-lang.org/1.76.0/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.unit.html">()</a>></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="toggle method-toggle" open><summary><section id="method.multicast_loop_v4" class="method"><a class="src rightside" href="../../src/mio/net/udp.rs.html#403-405">source</a><h4 class="code-header">pub fn <a href="#method.multicast_loop_v4" class="fn">multicast_loop_v4</a>(&self) -> <a class="type" href="https://doc.rust-lang.org/1.76.0/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.bool.html">bool</a>></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="toggle method-toggle" open><summary><section id="method.set_multicast_ttl_v4" class="method"><a class="src rightside" href="../../src/mio/net/udp.rs.html#414-416">source</a><h4 class="code-header">pub fn <a href="#method.set_multicast_ttl_v4" class="fn">set_multicast_ttl_v4</a>(&self, ttl: <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.u32.html">u32</a>) -> <a class="type" href="https://doc.rust-lang.org/1.76.0/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.unit.html">()</a>></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="toggle method-toggle" open><summary><section id="method.multicast_ttl_v4" class="method"><a class="src rightside" href="../../src/mio/net/udp.rs.html#424-426">source</a><h4 class="code-header">pub fn <a href="#method.multicast_ttl_v4" class="fn">multicast_ttl_v4</a>(&self) -> <a class="type" href="https://doc.rust-lang.org/1.76.0/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.u32.html">u32</a>></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="toggle method-toggle" open><summary><section id="method.set_multicast_loop_v6" class="method"><a class="src rightside" href="../../src/mio/net/udp.rs.html#432-434">source</a><h4 class="code-header">pub fn <a href="#method.set_multicast_loop_v6" class="fn">set_multicast_loop_v6</a>(&self, on: <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.bool.html">bool</a>) -> <a class="type" href="https://doc.rust-lang.org/1.76.0/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.unit.html">()</a>></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="toggle method-toggle" open><summary><section id="method.multicast_loop_v6" class="method"><a class="src rightside" href="../../src/mio/net/udp.rs.html#442-444">source</a><h4 class="code-header">pub fn <a href="#method.multicast_loop_v6" class="fn">multicast_loop_v6</a>(&self) -> <a class="type" href="https://doc.rust-lang.org/1.76.0/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.bool.html">bool</a>></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="toggle method-toggle" open><summary><section id="method.set_ttl" class="method"><a class="src rightside" href="../../src/mio/net/udp.rs.html#470-472">source</a><h4 class="code-header">pub fn <a href="#method.set_ttl" class="fn">set_ttl</a>(&self, ttl: <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.u32.html">u32</a>) -> <a class="type" href="https://doc.rust-lang.org/1.76.0/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.unit.html">()</a>></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">"127.0.0.1:0"</span>.parse()<span class="question-mark">?</span>)<span class="question-mark">?</span>;
|
|
|
<span class="kw">if </span>socket.ttl()<span class="question-mark">? </span>< <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="toggle method-toggle" open><summary><section id="method.ttl" class="method"><a class="src rightside" href="../../src/mio/net/udp.rs.html#497-499">source</a><h4 class="code-header">pub fn <a href="#method.ttl" class="fn">ttl</a>(&self) -> <a class="type" href="https://doc.rust-lang.org/1.76.0/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.u32.html">u32</a>></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">"127.0.0.1:0"</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="toggle method-toggle" open><summary><section id="method.join_multicast_v4" class="method"><a class="src rightside" href="../../src/mio/net/udp.rs.html#509-511">source</a><h4 class="code-header">pub fn <a href="#method.join_multicast_v4" class="fn">join_multicast_v4</a>(
|
|
|
&self,
|
|
|
multiaddr: &<a class="struct" href="https://doc.rust-lang.org/1.76.0/core/net/ip_addr/struct.Ipv4Addr.html" title="struct core::net::ip_addr::Ipv4Addr">Ipv4Addr</a>,
|
|
|
interface: &<a class="struct" href="https://doc.rust-lang.org/1.76.0/core/net/ip_addr/struct.Ipv4Addr.html" title="struct core::net::ip_addr::Ipv4Addr">Ipv4Addr</a>
|
|
|
) -> <a class="type" href="https://doc.rust-lang.org/1.76.0/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.unit.html">()</a>></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="toggle method-toggle" open><summary><section id="method.join_multicast_v6" class="method"><a class="src rightside" href="../../src/mio/net/udp.rs.html#519-521">source</a><h4 class="code-header">pub fn <a href="#method.join_multicast_v6" class="fn">join_multicast_v6</a>(
|
|
|
&self,
|
|
|
multiaddr: &<a class="struct" href="https://doc.rust-lang.org/1.76.0/core/net/ip_addr/struct.Ipv6Addr.html" title="struct core::net::ip_addr::Ipv6Addr">Ipv6Addr</a>,
|
|
|
interface: <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.u32.html">u32</a>
|
|
|
) -> <a class="type" href="https://doc.rust-lang.org/1.76.0/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.unit.html">()</a>></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="toggle method-toggle" open><summary><section id="method.leave_multicast_v4" class="method"><a class="src rightside" href="../../src/mio/net/udp.rs.html#530-532">source</a><h4 class="code-header">pub fn <a href="#method.leave_multicast_v4" class="fn">leave_multicast_v4</a>(
|
|
|
&self,
|
|
|
multiaddr: &<a class="struct" href="https://doc.rust-lang.org/1.76.0/core/net/ip_addr/struct.Ipv4Addr.html" title="struct core::net::ip_addr::Ipv4Addr">Ipv4Addr</a>,
|
|
|
interface: &<a class="struct" href="https://doc.rust-lang.org/1.76.0/core/net/ip_addr/struct.Ipv4Addr.html" title="struct core::net::ip_addr::Ipv4Addr">Ipv4Addr</a>
|
|
|
) -> <a class="type" href="https://doc.rust-lang.org/1.76.0/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.unit.html">()</a>></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="toggle method-toggle" open><summary><section id="method.leave_multicast_v6" class="method"><a class="src rightside" href="../../src/mio/net/udp.rs.html#541-543">source</a><h4 class="code-header">pub fn <a href="#method.leave_multicast_v6" class="fn">leave_multicast_v6</a>(
|
|
|
&self,
|
|
|
multiaddr: &<a class="struct" href="https://doc.rust-lang.org/1.76.0/core/net/ip_addr/struct.Ipv6Addr.html" title="struct core::net::ip_addr::Ipv6Addr">Ipv6Addr</a>,
|
|
|
interface: <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.u32.html">u32</a>
|
|
|
) -> <a class="type" href="https://doc.rust-lang.org/1.76.0/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.unit.html">()</a>></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="toggle method-toggle" open><summary><section id="method.only_v6" class="method"><a class="src rightside" href="../../src/mio/net/udp.rs.html#547-549">source</a><h4 class="code-header">pub fn <a href="#method.only_v6" class="fn">only_v6</a>(&self) -> <a class="type" href="https://doc.rust-lang.org/1.76.0/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.bool.html">bool</a>></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="toggle method-toggle" open><summary><section id="method.take_error" class="method"><a class="src rightside" href="../../src/mio/net/udp.rs.html#556-558">source</a><h4 class="code-header">pub fn <a href="#method.take_error" class="fn">take_error</a>(&self) -> <a class="type" href="https://doc.rust-lang.org/1.76.0/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a><<a class="enum" href="https://doc.rust-lang.org/1.76.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="struct" href="https://doc.rust-lang.org/1.76.0/std/io/error/struct.Error.html" title="struct std::io::error::Error">Error</a>>></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="toggle method-toggle" open><summary><section id="method.try_io" class="method"><a class="src rightside" href="../../src/mio/net/udp.rs.html#611-616">source</a><h4 class="code-header">pub fn <a href="#method.try_io" class="fn">try_io</a><F, T>(&self, f: F) -> <a class="type" href="https://doc.rust-lang.org/1.76.0/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a><T><div class="where">where
|
|
|
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnOnce.html" title="trait core::ops::function::FnOnce">FnOnce</a>() -> <a class="type" href="https://doc.rust-lang.org/1.76.0/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a><T>,</div></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="https://doc.rust-lang.org/1.76.0/std/io/error/enum.ErrorKind.html#variant.WouldBlock" title="variant std::io::error::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="https://doc.rust-lang.org/1.76.0/std/io/error/enum.ErrorKind.html#variant.WouldBlock" title="variant std::io::error::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="attr">#[cfg(any(unix, target_os = <span class="string">"wasi"</span>))]
|
|
|
</span><span class="kw">use </span>std::os::fd::AsRawFd;
|
|
|
<span class="attr">#[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">"127.0.0.1:8080"</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">&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="attr">#[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="attr">#[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">"read {} bytes"</span>, n);</code></pre></div>
|
|
|
</div></details></div></details></div><h2 id="trait-implementations" class="section-header">Trait Implementations<a href="#trait-implementations" class="anchor">§</a></h2><div id="trait-implementations-list"><details class="toggle implementors-toggle" open><summary><section id="impl-AsFd-for-UdpSocket" class="impl"><a class="src rightside" href="../../src/mio/net/udp.rs.html#684-688">source</a><a href="#impl-AsFd-for-UdpSocket" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.76.0/std/os/fd/owned/trait.AsFd.html" title="trait std::os::fd::owned::AsFd">AsFd</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="toggle method-toggle" open><summary><section id="method.as_fd" class="method trait-impl"><a class="src rightside" href="../../src/mio/net/udp.rs.html#685-687">source</a><a href="#method.as_fd" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.76.0/std/os/fd/owned/trait.AsFd.html#tymethod.as_fd" class="fn">as_fd</a>(&self) -> <a class="struct" href="https://doc.rust-lang.org/1.76.0/std/os/fd/owned/struct.BorrowedFd.html" title="struct std::os::fd::owned::BorrowedFd">BorrowedFd</a><'_></h4></section></summary><div class='docblock'>Borrows the file descriptor. <a href="https://doc.rust-lang.org/1.76.0/std/os/fd/owned/trait.AsFd.html#tymethod.as_fd">Read more</a></div></details></div></details><details class="toggle implementors-toggle" open><summary><section id="impl-AsRawFd-for-UdpSocket" class="impl"><a class="src rightside" href="../../src/mio/net/udp.rs.html#657-661">source</a><a href="#impl-AsRawFd-for-UdpSocket" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.76.0/std/os/fd/raw/trait.AsRawFd.html" title="trait std::os::fd::raw::AsRawFd">AsRawFd</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="toggle method-toggle" open><summary><section id="method.as_raw_fd" class="method trait-impl"><a class="src rightside" href="../../src/mio/net/udp.rs.html#658-660">source</a><a href="#method.as_raw_fd" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.76.0/std/os/fd/raw/trait.AsRawFd.html#tymethod.as_raw_fd" class="fn">as_raw_fd</a>(&self) -> <a class="type" href="https://doc.rust-lang.org/1.76.0/std/os/fd/raw/type.RawFd.html" title="type std::os::fd::raw::RawFd">RawFd</a></h4></section></summary><div class='docblock'>Extracts the raw file descriptor. <a href="https://doc.rust-lang.org/1.76.0/std/os/fd/raw/trait.AsRawFd.html#tymethod.as_raw_fd">Read more</a></div></details></div></details><details class="toggle implementors-toggle" open><summary><section id="impl-Debug-for-UdpSocket" class="impl"><a class="src rightside" href="../../src/mio/net/udp.rs.html#643-647">source</a><a href="#impl-Debug-for-UdpSocket" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/fmt/trait.Debug.html" title="trait core::fmt::Debug">Debug</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="toggle method-toggle" open><summary><section id="method.fmt" class="method trait-impl"><a class="src rightside" href="../../src/mio/net/udp.rs.html#644-646">source</a><a href="#method.fmt" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.76.0/core/fmt/trait.Debug.html#tymethod.fmt" class="fn">fmt</a>(&self, f: &mut <a class="struct" href="https://doc.rust-lang.org/1.76.0/core/fmt/struct.Formatter.html" title="struct core::fmt::Formatter">Formatter</a><'_>) -> <a class="type" href="https://doc.rust-lang.org/1.76.0/core/fmt/type.Result.html" title="type core::fmt::Result">Result</a></h4></section></summary><div class='docblock'>Formats the value using the given formatter. <a href="https://doc.rust-lang.org/1.76.0/core/fmt/trait.Debug.html#tymethod.fmt">Read more</a></div></details></div></details><details class="toggle implementors-toggle" open><summary><section id="impl-From%3COwnedFd%3E-for-UdpSocket" class="impl"><a class="src rightside" href="../../src/mio/net/udp.rs.html#691-701">source</a><a href="#impl-From%3COwnedFd%3E-for-UdpSocket" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/convert/trait.From.html" title="trait core::convert::From">From</a><<a class="struct" href="https://doc.rust-lang.org/1.76.0/std/os/fd/owned/struct.OwnedFd.html" title="struct std::os::fd::owned::OwnedFd">OwnedFd</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="toggle method-toggle" open><summary><section id="method.from-2" class="method trait-impl"><a class="src rightside" href="../../src/mio/net/udp.rs.html#698-700">source</a><a href="#method.from-2" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.76.0/core/convert/trait.From.html#tymethod.from" class="fn">from</a>(fd: <a class="struct" href="https://doc.rust-lang.org/1.76.0/std/os/fd/owned/struct.OwnedFd.html" title="struct std::os::fd::owned::OwnedFd">OwnedFd</a>) -> Self</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="toggle implementors-toggle" open><summary><section id="impl-From%3CUdpSocket%3E-for-OwnedFd" class="impl"><a class="src rightside" href="../../src/mio/net/udp.rs.html#677-681">source</a><a href="#impl-From%3CUdpSocket%3E-for-OwnedFd" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/convert/trait.From.html" title="trait core::convert::From">From</a><<a class="struct" href="struct.UdpSocket.html" title="struct mio::net::UdpSocket">UdpSocket</a>> for <a class="struct" href="https://doc.rust-lang.org/1.76.0/std/os/fd/owned/struct.OwnedFd.html" title="struct std::os::fd::owned::OwnedFd">OwnedFd</a></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.from-1" class="method trait-impl"><a class="src rightside" href="../../src/mio/net/udp.rs.html#678-680">source</a><a href="#method.from-1" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.76.0/core/convert/trait.From.html#tymethod.from" class="fn">from</a>(udp_socket: <a class="struct" href="struct.UdpSocket.html" title="struct mio::net::UdpSocket">UdpSocket</a>) -> Self</h4></section></summary><div class='docblock'>Converts to this type from the input type.</div></details></div></details><details class="toggle implementors-toggle" open><summary><section id="impl-From%3CUdpSocket%3E-for-UdpSocket" class="impl"><a class="src rightside" href="../../src/mio/net/udp.rs.html#757-773">source</a><a href="#impl-From%3CUdpSocket%3E-for-UdpSocket" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/convert/trait.From.html" title="trait core::convert::From">From</a><<a class="struct" href="struct.UdpSocket.html" title="struct mio::net::UdpSocket">UdpSocket</a>> for <a class="struct" href="https://doc.rust-lang.org/1.76.0/std/net/udp/struct.UdpSocket.html" title="struct std::net::udp::UdpSocket">UdpSocket</a></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.from" class="method trait-impl"><a class="src rightside" href="../../src/mio/net/udp.rs.html#758-772">source</a><a href="#method.from" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.76.0/core/convert/trait.From.html#tymethod.from" class="fn">from</a>(socket: <a class="struct" href="struct.UdpSocket.html" title="struct mio::net::UdpSocket">UdpSocket</a>) -> Self</h4></section></summary><div class='docblock'>Converts to this type from the input type.</div></details></div></details><details class="toggle implementors-toggle" open><summary><section id="impl-FromRawFd-for-UdpSocket" class="impl"><a class="src rightside" href="../../src/mio/net/udp.rs.html#664-674">source</a><a href="#impl-FromRawFd-for-UdpSocket" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.76.0/std/os/fd/raw/trait.FromRawFd.html" title="trait std::os::fd::raw::FromRawFd">FromRawFd</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="toggle method-toggle" open><summary><section id="method.from_raw_fd" class="method trait-impl"><a class="src rightside" href="../../src/mio/net/udp.rs.html#671-673">source</a><a href="#method.from_raw_fd" class="anchor">§</a><h4 class="code-header">unsafe fn <a href="https://doc.rust-lang.org/1.76.0/std/os/fd/raw/trait.FromRawFd.html#tymethod.from_raw_fd" class="fn">from_raw_fd</a>(fd: <a class="type" href="https://doc.rust-lang.org/1.76.0/std/os/fd/raw/type.RawFd.html" title="type std::os::fd::raw::RawFd">RawFd</a>) -> <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-6"><a href="#notes-6">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="toggle implementors-toggle" open><summary><section id="impl-IntoRawFd-for-UdpSocket" class="impl"><a class="src rightside" href="../../src/mio/net/udp.rs.html#650-654">source</a><a href="#impl-IntoRawFd-for-UdpSocket" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.76.0/std/os/fd/raw/trait.IntoRawFd.html" title="trait std::os::fd::raw::IntoRawFd">IntoRawFd</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="toggle method-toggle" open><summary><section id="method.into_raw_fd" class="method trait-impl"><a class="src rightside" href="../../src/mio/net/udp.rs.html#651-653">source</a><a href="#method.into_raw_fd" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.76.0/std/os/fd/raw/trait.IntoRawFd.html#tymethod.into_raw_fd" class="fn">into_raw_fd</a>(self) -> <a class="type" href="https://doc.rust-lang.org/1.76.0/std/os/fd/raw/type.RawFd.html" title="type std::os::fd::raw::RawFd">RawFd</a></h4></section></summary><div class='docblock'>Consumes this object, returning the raw underlying file descriptor. <a href="https://doc.rust-lang.org/1.76.0/std/os/fd/raw/trait.IntoRawFd.html#tymethod.into_raw_fd">Read more</a></div></details></div></details><details class="toggle implementors-toggle" open><summary><section id="impl-Source-for-UdpSocket" class="impl"><a class="src rightside" href="../../src/mio/net/udp.rs.html#619-641">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="toggle method-toggle" open><summary><section id="method.register" class="method trait-impl"><a class="src rightside" href="../../src/mio/net/udp.rs.html#620-627">source</a><a href="#method.register" class="anchor">§</a><h4 class="code-header">fn <a href="../event/trait.Source.html#tymethod.register" class="fn">register</a>(
|
|
|
&mut self,
|
|
|
registry: &<a class="struct" href="../struct.Registry.html" title="struct mio::Registry">Registry</a>,
|
|
|
token: <a class="struct" href="../struct.Token.html" title="struct mio::Token">Token</a>,
|
|
|
interests: <a class="struct" href="../struct.Interest.html" title="struct mio::Interest">Interest</a>
|
|
|
) -> <a class="type" href="https://doc.rust-lang.org/1.76.0/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.unit.html">()</a>></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="toggle method-toggle" open><summary><section id="method.reregister" class="method trait-impl"><a class="src rightside" href="../../src/mio/net/udp.rs.html#629-636">source</a><a href="#method.reregister" class="anchor">§</a><h4 class="code-header">fn <a href="../event/trait.Source.html#tymethod.reregister" class="fn">reregister</a>(
|
|
|
&mut self,
|
|
|
registry: &<a class="struct" href="../struct.Registry.html" title="struct mio::Registry">Registry</a>,
|
|
|
token: <a class="struct" href="../struct.Token.html" title="struct mio::Token">Token</a>,
|
|
|
interests: <a class="struct" href="../struct.Interest.html" title="struct mio::Interest">Interest</a>
|
|
|
) -> <a class="type" href="https://doc.rust-lang.org/1.76.0/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.unit.html">()</a>></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="toggle method-toggle" open><summary><section id="method.deregister" class="method trait-impl"><a class="src rightside" href="../../src/mio/net/udp.rs.html#638-640">source</a><a href="#method.deregister" class="anchor">§</a><h4 class="code-header">fn <a href="../event/trait.Source.html#tymethod.deregister" class="fn">deregister</a>(&mut self, registry: &<a class="struct" href="../struct.Registry.html" title="struct mio::Registry">Registry</a>) -> <a class="type" href="https://doc.rust-lang.org/1.76.0/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.unit.html">()</a>></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="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"><a href="#impl-RefUnwindSafe-for-UdpSocket" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/panic/unwind_safe/trait.RefUnwindSafe.html" title="trait core::panic::unwind_safe::RefUnwindSafe">RefUnwindSafe</a> 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"><a href="#impl-Send-for-UdpSocket" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> 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"><a href="#impl-Sync-for-UdpSocket" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> 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"><a href="#impl-Unpin-for-UdpSocket" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a> 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"><a href="#impl-UnwindSafe-for-UdpSocket" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/panic/unwind_safe/trait.UnwindSafe.html" title="trait core::panic::unwind_safe::UnwindSafe">UnwindSafe</a> for <a class="struct" href="struct.UdpSocket.html" title="struct mio::net::UdpSocket">UdpSocket</a></h3></section></div><h2 id="blanket-implementations" class="section-header">Blanket Implementations<a href="#blanket-implementations" class="anchor">§</a></h2><div id="blanket-implementations-list"><details class="toggle implementors-toggle"><summary><section id="impl-Any-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.76.0/src/core/any.rs.html#140">source</a><a href="#impl-Any-for-T" class="anchor">§</a><h3 class="code-header">impl<T> <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/any/trait.Any.html" title="trait core::any::Any">Any</a> for T<div class="where">where
|
|
|
T: 'static + ?<a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.type_id" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.76.0/src/core/any.rs.html#141">source</a><a href="#method.type_id" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.76.0/core/any/trait.Any.html#tymethod.type_id" class="fn">type_id</a>(&self) -> <a class="struct" href="https://doc.rust-lang.org/1.76.0/core/any/struct.TypeId.html" title="struct core::any::TypeId">TypeId</a></h4></section></summary><div class='docblock'>Gets the <code>TypeId</code> of <code>self</code>. <a href="https://doc.rust-lang.org/1.76.0/core/any/trait.Any.html#tymethod.type_id">Read more</a></div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-Borrow%3CT%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.76.0/src/core/borrow.rs.html#208">source</a><a href="#impl-Borrow%3CT%3E-for-T" class="anchor">§</a><h3 class="code-header">impl<T> <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/borrow/trait.Borrow.html" title="trait core::borrow::Borrow">Borrow</a><T> for T<div class="where">where
|
|
|
T: ?<a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.borrow" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.76.0/src/core/borrow.rs.html#210">source</a><a href="#method.borrow" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.76.0/core/borrow/trait.Borrow.html#tymethod.borrow" class="fn">borrow</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.reference.html">&T</a></h4></section></summary><div class='docblock'>Immutably borrows from an owned value. <a href="https://doc.rust-lang.org/1.76.0/core/borrow/trait.Borrow.html#tymethod.borrow">Read more</a></div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-BorrowMut%3CT%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.76.0/src/core/borrow.rs.html#216">source</a><a href="#impl-BorrowMut%3CT%3E-for-T" class="anchor">§</a><h3 class="code-header">impl<T> <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/borrow/trait.BorrowMut.html" title="trait core::borrow::BorrowMut">BorrowMut</a><T> for T<div class="where">where
|
|
|
T: ?<a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.borrow_mut" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.76.0/src/core/borrow.rs.html#217">source</a><a href="#method.borrow_mut" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.76.0/core/borrow/trait.BorrowMut.html#tymethod.borrow_mut" class="fn">borrow_mut</a>(&mut self) -> <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.reference.html">&mut T</a></h4></section></summary><div class='docblock'>Mutably borrows from an owned value. <a href="https://doc.rust-lang.org/1.76.0/core/borrow/trait.BorrowMut.html#tymethod.borrow_mut">Read more</a></div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-From%3CT%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.76.0/src/core/convert/mod.rs.html#763">source</a><a href="#impl-From%3CT%3E-for-T" class="anchor">§</a><h3 class="code-header">impl<T> <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/convert/trait.From.html" title="trait core::convert::From">From</a><T> for T</h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.from-3" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.76.0/src/core/convert/mod.rs.html#766">source</a><a href="#method.from-3" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.76.0/core/convert/trait.From.html#tymethod.from" class="fn">from</a>(t: T) -> T</h4></section></summary><div class="docblock"><p>Returns the argument unchanged.</p>
|
|
|
</div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-Into%3CU%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.76.0/src/core/convert/mod.rs.html#747-749">source</a><a href="#impl-Into%3CU%3E-for-T" class="anchor">§</a><h3 class="code-header">impl<T, U> <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a><U> for T<div class="where">where
|
|
|
U: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/convert/trait.From.html" title="trait core::convert::From">From</a><T>,</div></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.into" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.76.0/src/core/convert/mod.rs.html#756">source</a><a href="#method.into" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.76.0/core/convert/trait.Into.html#tymethod.into" class="fn">into</a>(self) -> 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><a href="https://doc.rust-lang.org/1.76.0/core/convert/trait.From.html" title="trait core::convert::From">From</a><T> for U</code> chooses to do.</p>
|
|
|
</div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-TryFrom%3CU%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.76.0/src/core/convert/mod.rs.html#803-805">source</a><a href="#impl-TryFrom%3CU%3E-for-T" class="anchor">§</a><h3 class="code-header">impl<T, U> <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><U> for T<div class="where">where
|
|
|
U: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a><T>,</div></h3></section></summary><div class="impl-items"><details class="toggle" open><summary><section id="associatedtype.Error" class="associatedtype trait-impl"><a href="#associatedtype.Error" class="anchor">§</a><h4 class="code-header">type <a href="https://doc.rust-lang.org/1.76.0/core/convert/trait.TryFrom.html#associatedtype.Error" class="associatedtype">Error</a> = <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/convert/enum.Infallible.html" title="enum core::convert::Infallible">Infallible</a></h4></section></summary><div class='docblock'>The type returned in the event of a conversion error.</div></details><details class="toggle method-toggle" open><summary><section id="method.try_from" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.76.0/src/core/convert/mod.rs.html#810">source</a><a href="#method.try_from" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.76.0/core/convert/trait.TryFrom.html#tymethod.try_from" class="fn">try_from</a>(value: U) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, <T as <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><U>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/convert/trait.TryFrom.html#associatedtype.Error" title="type core::convert::TryFrom::Error">Error</a>></h4></section></summary><div class='docblock'>Performs the conversion.</div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-TryInto%3CU%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.76.0/src/core/convert/mod.rs.html#788-790">source</a><a href="#impl-TryInto%3CU%3E-for-T" class="anchor">§</a><h3 class="code-header">impl<T, U> <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/convert/trait.TryInto.html" title="trait core::convert::TryInto">TryInto</a><U> for T<div class="where">where
|
|
|
U: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><T>,</div></h3></section></summary><div class="impl-items"><details class="toggle" open><summary><section id="associatedtype.Error-1" class="associatedtype trait-impl"><a href="#associatedtype.Error-1" class="anchor">§</a><h4 class="code-header">type <a href="https://doc.rust-lang.org/1.76.0/core/convert/trait.TryInto.html#associatedtype.Error" class="associatedtype">Error</a> = <U as <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><T>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/convert/trait.TryFrom.html#associatedtype.Error" title="type core::convert::TryFrom::Error">Error</a></h4></section></summary><div class='docblock'>The type returned in the event of a conversion error.</div></details><details class="toggle method-toggle" open><summary><section id="method.try_into" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.76.0/src/core/convert/mod.rs.html#795">source</a><a href="#method.try_into" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.76.0/core/convert/trait.TryInto.html#tymethod.try_into" class="fn">try_into</a>(self) -> <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a><U, <U as <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><T>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/convert/trait.TryFrom.html#associatedtype.Error" title="type core::convert::TryFrom::Error">Error</a>></h4></section></summary><div class='docblock'>Performs the conversion.</div></details></div></details></div></section></div></main></body></html> |