Files
google-apis-rs/mio/event/trait.Source.html
2024-03-05 21:06:01 +01:00

101 lines
20 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!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><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 trait"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle">&#9776;</button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../mio/index.html">mio</a><span class="version">0.8.8</span></h2></div><h2 class="location"><a href="#">Source</a></h2><div class="sidebar-elems"><section><h3><a href="#required-methods">Required Methods</a></h3><ul class="block"><li><a href="#tymethod.deregister">deregister</a></li><li><a href="#tymethod.register">register</a></li><li><a href="#tymethod.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">Box&lt;T&gt;</a></li></ul><h3><a href="#implementors">Implementors</a></h3></section><h2><a href="index.html">In mio::event</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>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" 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/event/source.rs.html#75-112">source</a> · <button id="toggle-all-docs" title="collapse all docs">[<span>&#x2212;</span>]</button></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.76.0/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.76.0/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.76.0/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.76.0/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.76.0/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.76.0/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 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"><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"><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>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.76.0/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.76.0/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.76.0/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.76.0/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.76.0/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.76.0/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.76.0/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.76.0/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.76.0/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.76.0/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.76.0/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.76.0/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.76.0/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.76.0/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#139-161">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#318-340">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#615-637">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#184-206">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#52-74">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#193-215">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#463-485">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></section><section id="impl-Source-for-Sender" class="impl"><a class="src rightside" href="../../src/mio/sys/unix/pipe.rs.html#298-320">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></section><section id="impl-Source-for-SourceFd%3C'a%3E" class="impl"><a class="src rightside" href="../../src/mio/sys/unix/sourcefd.rs.html#94-116">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>