71 lines
24 KiB
HTML
71 lines
24 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`."><meta name="keywords" content="rust, rustlang, rust-lang, Source"><title>Source in mio::event - Rust</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceSerif4-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../FiraSans-Regular.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../FiraSans-Medium.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceCodePro-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceSerif4-Bold.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceCodePro-Semibold.ttf.woff2"><link rel="stylesheet" type="text/css" href="../../normalize.css"><link rel="stylesheet" type="text/css" href="../../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" type="text/css" href="../../ayu.css" disabled><link rel="stylesheet" type="text/css" href="../../dark.css" disabled><link rel="stylesheet" type="text/css" href="../../light.css" id="themeStyle"><script id="default-settings" ></script><script src="../../storage.js"></script><script src="../../crates.js"></script><script defer src="../../main.js"></script>
|
||
<noscript><link rel="stylesheet" href="../../noscript.css"></noscript><link rel="alternate icon" type="image/png" href="../../favicon-16x16.png"><link rel="alternate icon" type="image/png" href="../../favicon-32x32.png"><link rel="icon" type="image/svg+xml" href="../../favicon.svg"></head><body class="rustdoc trait"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"><div class="sidebar-menu" role="button">☰</div><a class="sidebar-logo" href="../../mio/index.html"><div class="logo-container"><img class="rust-logo" src="../../rust-logo.png" alt="logo"></div>
|
||
</a><h2 class="location">Trait Source</h2><div class="sidebar-elems"><div class="block items"><h3 class="sidebar-title"><a href="#required-methods">Required Methods</a></h3><div class="sidebar-links"><a href="#tymethod.deregister">deregister</a><a href="#tymethod.register">register</a><a href="#tymethod.reregister">reregister</a></div><h3 class="sidebar-title"><a href="#foreign-impls">Implementations on Foreign Types</a></h3><div class="sidebar-links"><a href="#impl-Source-for-Box%3CT%3E">Box<T></a></div><h3 class="sidebar-title"><a href="#implementors">Implementors</a></h3></div><h2 class="location">Other items in<br><a href="../index.html">mio</a>::<wbr><a href="index.html">event</a></h2><div id="sidebar-vars" data-name="Source" data-ty="trait" data-relpath=""></div><script defer src="sidebar-items.js"></script></div></nav><main><div class="width-limiter"><div class="sub-container"><a class="sub-logo-container" href="../../mio/index.html"><img class="rust-logo" src="../../rust-logo.png" alt="logo"></a><nav class="sub"><div class="theme-picker"><button id="theme-picker" aria-label="Pick another theme!" aria-haspopup="menu" title="themes"><img width="18" height="18" alt="Pick another theme!" src="../../brush.svg"></button><div id="theme-choices" role="menu"></div></div><form class="search-form"><div class="search-container"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"></div><button type="button" id="help-button" title="help">?</button><a id="settings-menu" href="../../settings.html" title="settings"><img width="18" height="18" alt="Change settings" src="../../wheel.svg"></a></div></form></nav></div><section id="main-content" class="content"><h1 class="fqn"><span class="in-band">Trait <a href="../index.html">mio</a>::<wbr><a href="index.html">event</a>::<wbr><a class="trait" href="#">Source</a><button id="copy-path" onclick="copy_path(this)" title="Copy item path to clipboard"><img src="../../clipboard.svg" width="19" height="18" alt="Copy item path"></button></span><span class="out-of-band"><span id="render-detail"><a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">−</span>]</a></span><a class="srclink" href="../../src/mio/event/source.rs.html#75-112" title="goto source code">[src]</a></span></h1><div class="docblock item-decl"><pre class="rust trait"><code>pub trait Source {
|
||
fn <a href="#tymethod.register" class="fnname">register</a>(<br> &mut self, <br> registry: &<a class="struct" href="../struct.Registry.html" title="struct mio::Registry">Registry</a>, <br> token: <a class="struct" href="../struct.Token.html" title="struct mio::Token">Token</a>, <br> interests: <a class="struct" href="../struct.Interest.html" title="struct mio::Interest">Interest</a><br> ) -> <a class="type" href="https://doc.rust-lang.org/1.59.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.59.0/std/primitive.unit.html">()</a>>;
|
||
<div class="item-spacer"></div> fn <a href="#tymethod.reregister" class="fnname">reregister</a>(<br> &mut self, <br> registry: &<a class="struct" href="../struct.Registry.html" title="struct mio::Registry">Registry</a>, <br> token: <a class="struct" href="../struct.Token.html" title="struct mio::Token">Token</a>, <br> interests: <a class="struct" href="../struct.Interest.html" title="struct mio::Interest">Interest</a><br> ) -> <a class="type" href="https://doc.rust-lang.org/1.59.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.59.0/std/primitive.unit.html">()</a>>;
|
||
<div class="item-spacer"></div> fn <a href="#tymethod.deregister" class="fnname">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.59.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.59.0/std/primitive.unit.html">()</a>>;
|
||
}</code></pre></div><details class="rustdoc-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" class="section-header"><a href="#implementing-eventsource">Implementing <code>event::Source</code></a></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" class="section-header"><a href="#dropping-eventsources">Dropping <code>event::Source</code>s</a></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" class="section-header"><a href="#examples">Examples</a></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> <span class="ident">mio</span>::{<span class="ident">Interest</span>, <span class="ident">Registry</span>, <span class="ident">Token</span>};
|
||
<span class="kw">use</span> <span class="ident">mio::event::Source</span>;
|
||
<span class="kw">use</span> <span class="ident">mio::net::TcpStream</span>;
|
||
|
||
<span class="kw">use</span> <span class="ident">std::io</span>;
|
||
|
||
<span class="kw">pub</span> <span class="kw">struct</span> <span class="ident">MySource</span> {
|
||
<span class="ident">socket</span>: <span class="ident">TcpStream</span>,
|
||
}
|
||
|
||
<span class="kw">impl</span> <span class="ident">Source</span> <span class="kw">for</span> <span class="ident">MySource</span> {
|
||
<span class="kw">fn</span> <span class="ident">register</span>(<span class="kw-2">&mut</span> <span class="self">self</span>, <span class="ident">registry</span>: <span class="kw-2">&</span><span class="ident">Registry</span>, <span class="ident">token</span>: <span class="ident">Token</span>, <span class="ident">interests</span>: <span class="ident">Interest</span>)
|
||
-> <span class="ident">io::Result</span><span class="op"><</span>()<span class="op">></span>
|
||
{
|
||
<span class="comment">// Delegate the `register` call to `socket`</span>
|
||
<span class="self">self</span>.<span class="ident">socket</span>.<span class="ident">register</span>(<span class="ident">registry</span>, <span class="ident">token</span>, <span class="ident">interests</span>)
|
||
}
|
||
|
||
<span class="kw">fn</span> <span class="ident">reregister</span>(<span class="kw-2">&mut</span> <span class="self">self</span>, <span class="ident">registry</span>: <span class="kw-2">&</span><span class="ident">Registry</span>, <span class="ident">token</span>: <span class="ident">Token</span>, <span class="ident">interests</span>: <span class="ident">Interest</span>)
|
||
-> <span class="ident">io::Result</span><span class="op"><</span>()<span class="op">></span>
|
||
{
|
||
<span class="comment">// Delegate the `reregister` call to `socket`</span>
|
||
<span class="self">self</span>.<span class="ident">socket</span>.<span class="ident">reregister</span>(<span class="ident">registry</span>, <span class="ident">token</span>, <span class="ident">interests</span>)
|
||
}
|
||
|
||
<span class="kw">fn</span> <span class="ident">deregister</span>(<span class="kw-2">&mut</span> <span class="self">self</span>, <span class="ident">registry</span>: <span class="kw-2">&</span><span class="ident">Registry</span>) -> <span class="ident">io::Result</span><span class="op"><</span>()<span class="op">></span> {
|
||
<span class="comment">// Delegate the `deregister` call to `socket`</span>
|
||
<span class="self">self</span>.<span class="ident">socket</span>.<span class="ident">deregister</span>(<span class="ident">registry</span>)
|
||
}
|
||
}</code></pre></div>
|
||
</div></details><h2 id="required-methods" class="small-section-header">Required methods<a href="#required-methods" class="anchor"></a></h2><div class="methods"><details class="rustdoc-toggle" open><summary><div id="tymethod.register" class="method has-srclink"><div class="rightside"><a class="srclink" href="../../src/mio/event/source.rs.html#83-88" title="goto source code">[src]</a></div><h4 class="code-header">fn <a href="#tymethod.register" class="fnname">register</a>(<br> &mut self, <br> registry: &<a class="struct" href="../struct.Registry.html" title="struct mio::Registry">Registry</a>, <br> token: <a class="struct" href="../struct.Token.html" title="struct mio::Token">Token</a>, <br> interests: <a class="struct" href="../struct.Interest.html" title="struct mio::Interest">Interest</a><br>) -> <a class="type" href="https://doc.rust-lang.org/1.59.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.59.0/std/primitive.unit.html">()</a>></h4></div></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="rustdoc-toggle" open><summary><div id="tymethod.reregister" class="method has-srclink"><div class="rightside"><a class="srclink" href="../../src/mio/event/source.rs.html#97-102" title="goto source code">[src]</a></div><h4 class="code-header">fn <a href="#tymethod.reregister" class="fnname">reregister</a>(<br> &mut self, <br> registry: &<a class="struct" href="../struct.Registry.html" title="struct mio::Registry">Registry</a>, <br> token: <a class="struct" href="../struct.Token.html" title="struct mio::Token">Token</a>, <br> interests: <a class="struct" href="../struct.Interest.html" title="struct mio::Interest">Interest</a><br>) -> <a class="type" href="https://doc.rust-lang.org/1.59.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.59.0/std/primitive.unit.html">()</a>></h4></div></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="rustdoc-toggle" open><summary><div id="tymethod.deregister" class="method has-srclink"><div class="rightside"><a class="srclink" href="../../src/mio/event/source.rs.html#111" title="goto source code">[src]</a></div><h4 class="code-header">fn <a href="#tymethod.deregister" class="fnname">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.59.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.59.0/std/primitive.unit.html">()</a>></h4></div></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="small-section-header">Implementations on Foreign Types<a href="#foreign-impls" class="anchor"></a></h2><details class="rustdoc-toggle implementors-toggle"><summary><div id="impl-Source-for-Box%3CT%3E" class="impl has-srclink"><div class="rightside"><a class="srclink" href="../../src/mio/event/source.rs.html#114-139" title="goto source code">[src]</a></div><a href="#impl-Source-for-Box%3CT%3E" class="anchor"></a><h3 class="code-header in-band">impl<T> <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.59.0/alloc/boxed/struct.Box.html" title="struct alloc::boxed::Box">Box</a><T> <span class="where fmt-newline">where<br> 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.59.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>, </span></h3></div></summary><div class="impl-items"><div id="method.register" class="method trait-impl has-srclink"><div class="rightside"><a class="srclink" href="../../src/mio/event/source.rs.html#118-125" title="goto source code">[src]</a></div><a href="#method.register" class="anchor"></a><h4 class="code-header">fn <a href="#tymethod.register" class="fnname">register</a>(<br> &mut self, <br> registry: &<a class="struct" href="../struct.Registry.html" title="struct mio::Registry">Registry</a>, <br> token: <a class="struct" href="../struct.Token.html" title="struct mio::Token">Token</a>, <br> interests: <a class="struct" href="../struct.Interest.html" title="struct mio::Interest">Interest</a><br>) -> <a class="type" href="https://doc.rust-lang.org/1.59.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.59.0/std/primitive.unit.html">()</a>></h4></div><div id="method.reregister" class="method trait-impl has-srclink"><div class="rightside"><a class="srclink" href="../../src/mio/event/source.rs.html#127-134" title="goto source code">[src]</a></div><a href="#method.reregister" class="anchor"></a><h4 class="code-header">fn <a href="#tymethod.reregister" class="fnname">reregister</a>(<br> &mut self, <br> registry: &<a class="struct" href="../struct.Registry.html" title="struct mio::Registry">Registry</a>, <br> token: <a class="struct" href="../struct.Token.html" title="struct mio::Token">Token</a>, <br> interests: <a class="struct" href="../struct.Interest.html" title="struct mio::Interest">Interest</a><br>) -> <a class="type" href="https://doc.rust-lang.org/1.59.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.59.0/std/primitive.unit.html">()</a>></h4></div><div id="method.deregister" class="method trait-impl has-srclink"><div class="rightside"><a class="srclink" href="../../src/mio/event/source.rs.html#136-138" title="goto source code">[src]</a></div><a href="#method.deregister" class="anchor"></a><h4 class="code-header">fn <a href="#tymethod.deregister" class="fnname">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.59.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.59.0/std/primitive.unit.html">()</a>></h4></div></div></details><h2 id="implementors" class="small-section-header">Implementors<a href="#implementors" class="anchor"></a></h2><div class="item-list" id="implementors-list"><div id="impl-Source" class="impl has-srclink"><div class="rightside"><a class="srclink" href="../../src/mio/net/tcp/listener.rs.html#139-161" title="goto source code">[src]</a></div><a href="#impl-Source" class="anchor"></a><h3 class="code-header in-band">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></div><div id="impl-Source-1" class="impl has-srclink"><div class="rightside"><a class="srclink" href="../../src/mio/net/tcp/stream.rs.html#314-336" title="goto source code">[src]</a></div><a href="#impl-Source-1" class="anchor"></a><h3 class="code-header in-band">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></div><div id="impl-Source-2" class="impl has-srclink"><div class="rightside"><a class="srclink" href="../../src/mio/net/udp.rs.html#611-633" title="goto source code">[src]</a></div><a href="#impl-Source-2" class="anchor"></a><h3 class="code-header in-band">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></div><div id="impl-Source-3" class="impl has-srclink"><div class="rightside"><a class="srclink" href="../../src/mio/net/uds/datagram.rs.html#181-203" title="goto source code">[src]</a></div><a href="#impl-Source-3" class="anchor"></a><h3 class="code-header in-band">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></div><div id="impl-Source-4" class="impl has-srclink"><div class="rightside"><a class="srclink" href="../../src/mio/net/uds/listener.rs.html#52-74" title="goto source code">[src]</a></div><a href="#impl-Source-4" class="anchor"></a><h3 class="code-header in-band">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></div><div id="impl-Source-5" class="impl has-srclink"><div class="rightside"><a class="srclink" href="../../src/mio/net/uds/stream.rs.html#190-212" title="goto source code">[src]</a></div><a href="#impl-Source-5" class="anchor"></a><h3 class="code-header in-band">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></div><div id="impl-Source-6" class="impl has-srclink"><div class="rightside"><a class="srclink" href="../../src/mio/sys/unix/pipe.rs.html#455-477" title="goto source code">[src]</a></div><a href="#impl-Source-6" class="anchor"></a><h3 class="code-header in-band">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></div><div id="impl-Source-7" class="impl has-srclink"><div class="rightside"><a class="srclink" href="../../src/mio/sys/unix/pipe.rs.html#290-312" title="goto source code">[src]</a></div><a href="#impl-Source-7" class="anchor"></a><h3 class="code-header in-band">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></div><div id="impl-Source-8" class="impl has-srclink"><div class="rightside"><a class="srclink" href="../../src/mio/sys/unix/sourcefd.rs.html#94-116" title="goto source code">[src]</a></div><a href="#impl-Source-8" class="anchor"></a><h3 class="code-header in-band">impl<'a> <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><'a></h3></div></div><script type="text/javascript" src="../../implementors/mio/event/trait.Source.js" async></script></section><section id="search" class="content hidden"></section></div></main><div id="rustdoc-vars" data-root-path="../../" data-current-crate="mio" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.59.0 (9d1b2106e 2022-02-23)" ></div>
|
||
</body></html> |