Files
GopherGate/target/doc/mio/event/trait.Source.html
2026-02-26 12:00:21 -05:00

99 lines
20 KiB
HTML

<!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="An event source that may be registered with `Registry`."><title>Source in mio::event - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Italic-81dc35de.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-MediumItalic-ccf7e434.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2"href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../static.files/rustdoc-ca0dd0c4.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.93.1 (01f6ddf75 2026-02-11) (Arch Linux rust 1:1.93.1-1)" data-channel="1.93.1" data-search-js="search-9e2438ea.js" data-stringdex-js="stringdex-a3946164.js" data-settings-js="settings-c38705f0.js" ><script src="../../static.files/storage-e2aeef58.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../static.files/main-a410ff4d.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-263c88ec.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-eab170b8.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-044be391.svg"></head><body class="rustdoc trait"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><rustdoc-topbar><h2><a href="#">Source</a></h2></rustdoc-topbar><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../mio/index.html">mio</a><span class="version">1.1.1</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Source</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#implementing-eventsource" title="Implementing `event::Source`">Implementing <code>event::Source</code></a></li><li><a href="#dropping-eventsources" title="Dropping `event::Source`s">Dropping <code>event::Source</code>s</a></li><li><a href="#examples" title="Examples">Examples</a></li></ul><h3><a href="#required-methods">Required Methods</a></h3><ul class="block"><li><a href="#tymethod.deregister" title="deregister">deregister</a></li><li><a href="#tymethod.register" title="register">register</a></li><li><a href="#tymethod.reregister" title="reregister">reregister</a></li></ul><h3><a href="#foreign-impls">Implementations on Foreign Types</a></h3><ul class="block"><li><a href="#impl-Source-for-Box%3CT%3E" title="Box&#60;T&#62;">Box&#60;T&#62;</a></li></ul><h3><a href="#implementors">Implementors</a></h3></section><div id="rustdoc-modnav"><h2><a href="index.html">In mio::<wbr>event</a></h2></div></div></nav><div class="sidebar-resizer" title="Drag to resize sidebar"></div><main><div class="width-limiter"><section id="main-content" class="content"><div class="main-heading"><div class="rustdoc-breadcrumbs"><a href="../index.html">mio</a>::<wbr><a href="index.html">event</a></div><h1>Trait <span class="trait">Source</span>&nbsp;<button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../src/mio/event/source.rs.html#75-112">Source</a> </span></div><pre class="rust item-decl"><code>pub trait Source {
// Required methods
fn <a href="#tymethod.register" class="fn">register</a>(
&amp;mut self,
registry: &amp;<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>,
) -&gt; <a class="type" href="https://doc.rust-lang.org/1.93.1/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.unit.html">()</a>&gt;;
<span class="item-spacer"></span> fn <a href="#tymethod.reregister" class="fn">reregister</a>(
&amp;mut self,
registry: &amp;<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>,
) -&gt; <a class="type" href="https://doc.rust-lang.org/1.93.1/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.unit.html">()</a>&gt;;
<span class="item-spacer"></span> fn <a href="#tymethod.deregister" class="fn">deregister</a>(&amp;mut self, registry: &amp;<a class="struct" href="../struct.Registry.html" title="struct mio::Registry">Registry</a>) -&gt; <a class="type" href="https://doc.rust-lang.org/1.93.1/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.unit.html">()</a>&gt;;
}</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>An event source that may be registered with <a href="../struct.Registry.html"><code>Registry</code></a>.</p>
<p>Types that implement <code>event::Source</code> can be registered with
<code>Registry</code>. Users of Mio <strong>should not</strong> use the <code>event::Source</code> trait
functions directly. Instead, the equivalent functions on <code>Registry</code> should
be used.</p>
<p>See <a href="../struct.Registry.html"><code>Registry</code></a> for more details.</p>
<h2 id="implementing-eventsource"><a class="doc-anchor" href="#implementing-eventsource">§</a>Implementing <code>event::Source</code></h2>
<p>Event sources are always backed by system handles, such as sockets or other
system handles. These <code>event::Source</code>s will be monitored by the system
selector. An implementation of <code>Source</code> will almost always delegates to a
lower level handle. Examples of this are <a href="../net/struct.TcpStream.html"><code>TcpStream</code></a>s, or the <em>unix only</em>
<a href="../unix/struct.SourceFd.html"><code>SourceFd</code></a>.</p>
<h2 id="dropping-eventsources"><a class="doc-anchor" href="#dropping-eventsources">§</a>Dropping <code>event::Source</code>s</h2>
<p>All <code>event::Source</code>s, unless otherwise specified, need to be <a href="../struct.Registry.html#method.deregister">deregistered</a>
before being dropped for them to not leak resources. This goes against the
normal drop behaviour of types in Rust which cleanup after themselves, e.g.
a <code>File</code> will close itself. However since deregistering needs access to
<a href="../struct.Registry.html"><code>Registry</code></a> this cannot be done while being dropped.</p>
<h2 id="examples"><a class="doc-anchor" href="#examples">§</a>Examples</h2>
<p>Implementing <code>Source</code> on a struct containing a socket:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>mio::{Interest, Registry, Token};
<span class="kw">use </span>mio::event::Source;
<span class="kw">use </span>mio::net::TcpStream;
<span class="kw">use </span>std::io;
<span class="kw">pub struct </span>MySource {
socket: TcpStream,
}
<span class="kw">impl </span>Source <span class="kw">for </span>MySource {
<span class="kw">fn </span>register(<span class="kw-2">&amp;mut </span><span class="self">self</span>, registry: <span class="kw-2">&amp;</span>Registry, token: Token, interests: Interest)
-&gt; io::Result&lt;()&gt;
{
<span class="comment">// Delegate the `register` call to `socket`
</span><span class="self">self</span>.socket.register(registry, token, interests)
}
<span class="kw">fn </span>reregister(<span class="kw-2">&amp;mut </span><span class="self">self</span>, registry: <span class="kw-2">&amp;</span>Registry, token: Token, interests: Interest)
-&gt; io::Result&lt;()&gt;
{
<span class="comment">// Delegate the `reregister` call to `socket`
</span><span class="self">self</span>.socket.reregister(registry, token, interests)
}
<span class="kw">fn </span>deregister(<span class="kw-2">&amp;mut </span><span class="self">self</span>, registry: <span class="kw-2">&amp;</span>Registry) -&gt; io::Result&lt;()&gt; {
<span class="comment">// Delegate the `deregister` call to `socket`
</span><span class="self">self</span>.socket.deregister(registry)
}
}</code></pre></div></div></details><h2 id="required-methods" class="section-header">Required Methods<a href="#required-methods" class="anchor">§</a></h2><div class="methods"><details class="toggle method-toggle" open><summary><section id="tymethod.register" class="method"><a class="src rightside" href="../../src/mio/event/source.rs.html#83-88">Source</a><h4 class="code-header">fn <a href="#tymethod.register" class="fn">register</a>(
&amp;mut self,
registry: &amp;<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>,
) -&gt; <a class="type" href="https://doc.rust-lang.org/1.93.1/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.unit.html">()</a>&gt;</h4></section></summary><div class="docblock"><p>Register <code>self</code> with the given <code>Registry</code> instance.</p>
<p>This function should not be called directly. Use <a href="../struct.Registry.html#method.register"><code>Registry::register</code></a>
instead. Implementors should handle registration by delegating the call
to another <code>Source</code> type.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.reregister" class="method"><a class="src rightside" href="../../src/mio/event/source.rs.html#97-102">Source</a><h4 class="code-header">fn <a href="#tymethod.reregister" class="fn">reregister</a>(
&amp;mut self,
registry: &amp;<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>,
) -&gt; <a class="type" href="https://doc.rust-lang.org/1.93.1/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.unit.html">()</a>&gt;</h4></section></summary><div class="docblock"><p>Re-register <code>self</code> with the given <code>Registry</code> instance.</p>
<p>This function should not be called directly. Use
<a href="../struct.Registry.html#method.reregister"><code>Registry::reregister</code></a> instead. Implementors should handle
re-registration by either delegating the call to another <code>Source</code> type.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.deregister" class="method"><a class="src rightside" href="../../src/mio/event/source.rs.html#111">Source</a><h4 class="code-header">fn <a href="#tymethod.deregister" class="fn">deregister</a>(&amp;mut self, registry: &amp;<a class="struct" href="../struct.Registry.html" title="struct mio::Registry">Registry</a>) -&gt; <a class="type" href="https://doc.rust-lang.org/1.93.1/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.unit.html">()</a>&gt;</h4></section></summary><div class="docblock"><p>Deregister <code>self</code> from the given <code>Registry</code> instance.</p>
<p>This function should not be called directly. Use
<a href="../struct.Registry.html#method.deregister"><code>Registry::deregister</code></a> instead. Implementors should handle
deregistration by delegating the call to another <code>Source</code> type.</p>
</div></details></div><h2 id="foreign-impls" class="section-header">Implementations on Foreign Types<a href="#foreign-impls" class="anchor">§</a></h2><details class="toggle implementors-toggle"><summary><section id="impl-Source-for-Box%3CT%3E" class="impl"><a class="src rightside" href="../../src/mio/event/source.rs.html#114-139">Source</a><a href="#impl-Source-for-Box%3CT%3E" class="anchor">§</a><h3 class="code-header">impl&lt;T&gt; <a class="trait" href="trait.Source.html" title="trait mio::event::Source">Source</a> for <a class="struct" href="https://doc.rust-lang.org/1.93.1/alloc/boxed/struct.Box.html" title="struct alloc::boxed::Box">Box</a>&lt;T&gt;<div class="where">where
T: <a class="trait" href="trait.Source.html" title="trait mio::event::Source">Source</a> + ?<a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h3></section></summary><div class="impl-items"><section id="method.register" class="method trait-impl"><a class="src rightside" href="../../src/mio/event/source.rs.html#118-125">Source</a><a href="#method.register" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.register" class="fn">register</a>(
&amp;mut self,
registry: &amp;<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>,
) -&gt; <a class="type" href="https://doc.rust-lang.org/1.93.1/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.unit.html">()</a>&gt;</h4></section><section id="method.reregister" class="method trait-impl"><a class="src rightside" href="../../src/mio/event/source.rs.html#127-134">Source</a><a href="#method.reregister" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.reregister" class="fn">reregister</a>(
&amp;mut self,
registry: &amp;<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>,
) -&gt; <a class="type" href="https://doc.rust-lang.org/1.93.1/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.unit.html">()</a>&gt;</h4></section><section id="method.deregister" class="method trait-impl"><a class="src rightside" href="../../src/mio/event/source.rs.html#136-138">Source</a><a href="#method.deregister" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.deregister" class="fn">deregister</a>(&amp;mut self, registry: &amp;<a class="struct" href="../struct.Registry.html" title="struct mio::Registry">Registry</a>) -&gt; <a class="type" href="https://doc.rust-lang.org/1.93.1/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.unit.html">()</a>&gt;</h4></section></div></details><h2 id="implementors" class="section-header">Implementors<a href="#implementors" class="anchor">§</a></h2><div id="implementors-list"><section id="impl-Source-for-TcpListener" class="impl"><a class="src rightside" href="../../src/mio/net/tcp/listener.rs.html#146-168">Source</a><a href="#impl-Source-for-TcpListener" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="trait.Source.html" title="trait mio::event::Source">Source</a> for <a class="struct" href="../net/struct.TcpListener.html" title="struct mio::net::TcpListener">TcpListener</a></h3></section><section id="impl-Source-for-TcpStream" class="impl"><a class="src rightside" href="../../src/mio/net/tcp/stream.rs.html#327-349">Source</a><a href="#impl-Source-for-TcpStream" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="trait.Source.html" title="trait mio::event::Source">Source</a> for <a class="struct" href="../net/struct.TcpStream.html" title="struct mio::net::TcpStream">TcpStream</a></h3></section><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="trait.Source.html" title="trait mio::event::Source">Source</a> for <a class="struct" href="../net/struct.UdpSocket.html" title="struct mio::net::UdpSocket">UdpSocket</a></h3></section><section id="impl-Source-for-UnixDatagram" class="impl"><a class="src rightside" href="../../src/mio/net/uds/datagram.rs.html#189-211">Source</a><a href="#impl-Source-for-UnixDatagram" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="trait.Source.html" title="trait mio::event::Source">Source</a> for <a class="struct" href="../net/struct.UnixDatagram.html" title="struct mio::net::UnixDatagram">UnixDatagram</a></h3></section><section id="impl-Source-for-UnixListener" class="impl"><a class="src rightside" href="../../src/mio/net/uds/listener.rs.html#58-80">Source</a><a href="#impl-Source-for-UnixListener" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="trait.Source.html" title="trait mio::event::Source">Source</a> for <a class="struct" href="../net/struct.UnixListener.html" title="struct mio::net::UnixListener">UnixListener</a></h3></section><section id="impl-Source-for-UnixStream" class="impl"><a class="src rightside" href="../../src/mio/net/uds/stream.rs.html#202-224">Source</a><a href="#impl-Source-for-UnixStream" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="trait.Source.html" title="trait mio::event::Source">Source</a> for <a class="struct" href="../net/struct.UnixStream.html" title="struct mio::net::UnixStream">UnixStream</a></h3></section><section id="impl-Source-for-Receiver" class="impl"><a class="src rightside" href="../../src/mio/sys/unix/pipe.rs.html#485-507">Source</a><a href="#impl-Source-for-Receiver" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="trait.Source.html" title="trait mio::event::Source">Source</a> for <a class="struct" href="../unix/pipe/struct.Receiver.html" title="struct mio::unix::pipe::Receiver">Receiver</a></h3><span class="item-info"><div class="stab portability">Available on <strong>crate feature <code>os-ext</code></strong> only.</div></span></section><section id="impl-Source-for-Sender" class="impl"><a class="src rightside" href="../../src/mio/sys/unix/pipe.rs.html#300-322">Source</a><a href="#impl-Source-for-Sender" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="trait.Source.html" title="trait mio::event::Source">Source</a> for <a class="struct" href="../unix/pipe/struct.Sender.html" title="struct mio::unix::pipe::Sender">Sender</a></h3><span class="item-info"><div class="stab portability">Available on <strong>crate feature <code>os-ext</code></strong> only.</div></span></section><section id="impl-Source-for-SourceFd%3C'a%3E" class="impl"><a class="src rightside" href="../../src/mio/sys/unix/sourcefd.rs.html#99-121">Source</a><a href="#impl-Source-for-SourceFd%3C'a%3E" class="anchor">§</a><h3 class="code-header">impl&lt;'a&gt; <a class="trait" href="trait.Source.html" title="trait mio::event::Source">Source</a> for <a class="struct" href="../unix/struct.SourceFd.html" title="struct mio::unix::SourceFd">SourceFd</a>&lt;'a&gt;</h3></section></div><script src="../../trait.impl/mio/event/source/trait.Source.js" data-ignore-extern-crates="alloc" async></script></section></div></main></body></html>