|
|
|
|
<!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="API documentation for the Rust `Watcher` trait in crate `notify`."><meta name="keywords" content="rust, rustlang, rust-lang, Watcher"><title>notify::Watcher - Rust</title><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="../dark.css"><link rel="stylesheet" type="text/css" href="../light.css" id="themeStyle"><script src="../storage.js"></script><noscript><link rel="stylesheet" href="../noscript.css"></noscript><link rel="shortcut icon" href="../favicon.ico"><style type="text/css">#crate-search{background-image:url("../down-arrow.svg");}</style></head><body class="rustdoc trait"><!--[if lte IE 8]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"><div class="sidebar-menu">☰</div><a href='../notify/index.html'><div class='logo-container'><img src='../rust-logo.png' alt='logo'></div></a><p class='location'>Trait Watcher</p><div class="sidebar-elems"><div class="block items"><a class="sidebar-title" href="#required-methods">Required Methods</a><div class="sidebar-links"><a href="#tymethod.new">new</a><a href="#tymethod.new_raw">new_raw</a><a href="#tymethod.unwatch">unwatch</a><a href="#tymethod.watch">watch</a></div><a class="sidebar-title" href="#implementors">Implementors</a></div><p class='location'><a href='index.html'>notify</a></p><script>window.sidebarCurrent = {name: 'Watcher', ty: 'trait', relpath: ''};</script><script defer src="sidebar-items.js"></script></div></nav><div class="theme-picker"><button id="theme-picker" aria-label="Pick another theme!"><img src="../brush.svg" width="18" alt="Pick another theme!"></button><div id="theme-choices"></div></div><script src="../theme.js"></script><nav class="sub"><form class="search-form js-only"><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><a id="settings-menu" href="../settings.html"><img src="../wheel.svg" width="18" alt="Change settings"></a></div></form></nav><section id="main" class="content"><h1 class='fqn'><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/notify/lib.rs.html#551-614' title='goto source code'>[src]</a></span><span class='in-band'>Trait <a href='index.html'>notify</a>::<wbr><a class="trait" href=''>Watcher</a></span></h1><div class="docblock type-decl hidden-by-usual-hider"><pre class='rust trait'>pub trait Watcher: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> {
|
|
|
|
|
fn <a href='#tymethod.new_raw' class='fnname'>new_raw</a>(tx: <a class="struct" href="https://doc.rust-lang.org/nightly/std/sync/mpsc/struct.Sender.html" title="struct std::sync::mpsc::Sender">Sender</a><<a class="struct" href="../notify/struct.RawEvent.html" title="struct notify::RawEvent">RawEvent</a>>) -> <a class="type" href="../notify/type.Result.html" title="type notify::Result">Result</a><Self>;
|
|
|
|
|
<div class='item-spacer'></div> fn <a href='#tymethod.new' class='fnname'>new</a>(tx: <a class="struct" href="https://doc.rust-lang.org/nightly/std/sync/mpsc/struct.Sender.html" title="struct std::sync::mpsc::Sender">Sender</a><<a class="enum" href="../notify/enum.DebouncedEvent.html" title="enum notify::DebouncedEvent">DebouncedEvent</a>>, delay: <a class="struct" href="https://doc.rust-lang.org/nightly/core/time/struct.Duration.html" title="struct core::time::Duration">Duration</a>) -> <a class="type" href="../notify/type.Result.html" title="type notify::Result">Result</a><Self>;
|
|
|
|
|
<div class='item-spacer'></div> fn <a href='#tymethod.watch' class='fnname'>watch</a><P: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a><<a class="struct" href="https://doc.rust-lang.org/nightly/std/path/struct.Path.html" title="struct std::path::Path">Path</a>>>(<br> &mut self, <br> path: P, <br> recursive_mode: <a class="enum" href="../notify/enum.RecursiveMode.html" title="enum notify::RecursiveMode">RecursiveMode</a><br> ) -> <a class="type" href="../notify/type.Result.html" title="type notify::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>>;
|
|
|
|
|
<div class='item-spacer'></div> fn <a href='#tymethod.unwatch' class='fnname'>unwatch</a><P: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a><<a class="struct" href="https://doc.rust-lang.org/nightly/std/path/struct.Path.html" title="struct std::path::Path">Path</a>>>(&mut self, path: P) -> <a class="type" href="../notify/type.Result.html" title="type notify::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>>;
|
|
|
|
|
}</pre></div><div class='docblock'><p>Type that can deliver file activity notifications</p>
|
|
|
|
|
<p>Watcher is implemented per platform using the best implementation available on that platform.
|
|
|
|
|
In addition to such event driven implementations, a polling implementation is also provided
|
|
|
|
|
that should work on any platform.</p>
|
|
|
|
|
</div>
|
|
|
|
|
<h2 id='required-methods' class='small-section-header'>Required methods<a href='#required-methods' class='anchor'></a></h2><div class='methods'><h3 id='tymethod.new_raw' class='method'><code id='new_raw.v'>fn <a href='#tymethod.new_raw' class='fnname'>new_raw</a>(tx: <a class="struct" href="https://doc.rust-lang.org/nightly/std/sync/mpsc/struct.Sender.html" title="struct std::sync::mpsc::Sender">Sender</a><<a class="struct" href="../notify/struct.RawEvent.html" title="struct notify::RawEvent">RawEvent</a>>) -> <a class="type" href="../notify/type.Result.html" title="type notify::Result">Result</a><Self></code></h3><div class='docblock'><p>Create a new watcher in <em>raw</em> mode.</p>
|
|
|
|
|
<p>Events will be sent using the provided <code>tx</code> immediately after they occurred.</p>
|
|
|
|
|
</div><h3 id='tymethod.new' class='method'><code id='new.v'>fn <a href='#tymethod.new' class='fnname'>new</a>(tx: <a class="struct" href="https://doc.rust-lang.org/nightly/std/sync/mpsc/struct.Sender.html" title="struct std::sync::mpsc::Sender">Sender</a><<a class="enum" href="../notify/enum.DebouncedEvent.html" title="enum notify::DebouncedEvent">DebouncedEvent</a>>, delay: <a class="struct" href="https://doc.rust-lang.org/nightly/core/time/struct.Duration.html" title="struct core::time::Duration">Duration</a>) -> <a class="type" href="../notify/type.Result.html" title="type notify::Result">Result</a><Self></code></h3><div class='docblock'><p>Create a new <em>debounced</em> watcher with a <code>delay</code>.</p>
|
|
|
|
|
<p>Events won't be sent immediately but after the specified delay.</p>
|
|
|
|
|
<h1 id="advantages" class="section-header"><a href="#advantages">Advantages</a></h1>
|
|
|
|
|
<p>This has the advantage that a lot of logic can be offloaded to <code>notify</code>.</p>
|
|
|
|
|
<p>For example you won't have to handle <code>RENAME</code> events yourself by piecing the two parts of
|
|
|
|
|
rename events together. Instead you will just receive a <code>Rename{from: PathBuf, to: PathBuf}</code> event.</p>
|
|
|
|
|
<p>Also <code>notify</code> will detect the beginning and the end of write operations. As soon as
|
|
|
|
|
something is written to a file, a <code>NoticeWrite</code> event is emitted. If no new event arrived
|
|
|
|
|
until after the specified <code>delay</code>, a <code>Write</code> event is emitted.</p>
|
|
|
|
|
<p>A practical example would be the safe-saving of a file, where a temporary file is created
|
|
|
|
|
and written to, then only when everything has been written to that file is it renamed to
|
|
|
|
|
overwrite the file that was meant to be saved. Instead of receiving a <code>CREATE</code> event for
|
|
|
|
|
the temporary file, <code>WRITE</code> events to that file and a <code>RENAME</code> event from the temporary
|
|
|
|
|
file to the file being saved, you will just receive a single <code>Write</code> event.</p>
|
|
|
|
|
<p>If you use a delay of more than 30 seconds, you can avoid receiving repetitions of previous
|
|
|
|
|
events on macOS.</p>
|
|
|
|
|
<h1 id="disadvantages" class="section-header"><a href="#disadvantages">Disadvantages</a></h1>
|
|
|
|
|
<p>Your application might not feel as responsive.</p>
|
|
|
|
|
<p>If a file is saved very slowly, you might receive a <code>Write</code> event even though the file is
|
|
|
|
|
still being written to.</p>
|
|
|
|
|
</div><h3 id='tymethod.watch' class='method'><code id='watch.v'>fn <a href='#tymethod.watch' class='fnname'>watch</a><P: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a><<a class="struct" href="https://doc.rust-lang.org/nightly/std/path/struct.Path.html" title="struct std::path::Path">Path</a>>>(<br> &mut self, <br> path: P, <br> recursive_mode: <a class="enum" href="../notify/enum.RecursiveMode.html" title="enum notify::RecursiveMode">RecursiveMode</a><br>) -> <a class="type" href="../notify/type.Result.html" title="type notify::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>></code></h3><div class='docblock'><p>Begin watching a new path.</p>
|
|
|
|
|
<p>If the <code>path</code> is a directory, <code>recursive_mode</code> will be evaluated. If <code>recursive_mode</code> is
|
|
|
|
|
<code>RecursiveMode::Recursive</code> events will be delivered for all files in that tree. Otherwise
|
|
|
|
|
only the directory and its immediate children will be watched.</p>
|
|
|
|
|
<p>If the <code>path</code> is a file, <code>recursive_mode</code> will be ignored and events will be delivered only
|
|
|
|
|
for the file.</p>
|
|
|
|
|
<p>On some platforms, if the <code>path</code> is renamed or removed while being watched, behaviour may
|
|
|
|
|
be unexpected. See discussions in <a href="https://github.com/passcod/notify/issues/165">#165</a> and <a href="https://github.com/passcod/notify/issues/166">#166</a>. If less surprising behaviour is wanted
|
|
|
|
|
one may non-recursively watch the <em>parent</em> directory as well and manage related events.</p>
|
|
|
|
|
</div><h3 id='tymethod.unwatch' class='method'><code id='unwatch.v'>fn <a href='#tymethod.unwatch' class='fnname'>unwatch</a><P: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a><<a class="struct" href="https://doc.rust-lang.org/nightly/std/path/struct.Path.html" title="struct std::path::Path">Path</a>>>(&mut self, path: P) -> <a class="type" href="../notify/type.Result.html" title="type notify::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>></code></h3><div class='docblock'><p>Stop watching a path.</p>
|
|
|
|
|
<h1 id="errors" class="section-header"><a href="#errors">Errors</a></h1>
|
|
|
|
|
<p>Returns an error in the case that <code>path</code> has not been watched or if removing the watch
|
|
|
|
|
fails.</p>
|
|
|
|
|
</div></div><span class='loading-content'>Loading content...</span>
|
|
|
|
|
<h2 id='implementors' class='small-section-header'>Implementors<a href='#implementors' class='anchor'></a></h2><div class='item-list' id='implementors-list'><h3 id='impl-Watcher' class='impl'><code class='in-band'>impl Watcher for <a class="struct" href="../notify/inotify/struct.INotifyWatcher.html" title="struct notify::inotify::INotifyWatcher">INotifyWatcher</a></code><a href='#impl-Watcher' class='anchor'></a><a class='srclink' href='../src/notify/inotify.rs.html#438-489' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.new_raw' class="method hidden"><code id='new_raw.v-1'>fn <a href='#method.new_raw' class='fnname'>new_raw</a>(tx: <a class="struct" href="https://doc.rust-lang.org/nightly/std/sync/mpsc/struct.Sender.html" title="struct std::sync::mpsc::Sender">Sender</a><<a class="struct" href="../notify/struct.RawEvent.html" title="struct notify::RawEvent">RawEvent</a>>) -> <a class="type" href="../notify/type.Result.html" title="type notify::Result">Result</a><<a class="struct" href="../notify/inotify/struct.INotifyWatcher.html" title="struct notify::inotify::INotifyWatcher">INotifyWatcher</a>></code><a class='srclink' href='../src/notify/inotify.rs.html#439-446' title='goto source code'>[src]</a></h4><h4 id='method.new' class="method hidden"><code id='new.v-1'>fn <a href='#method.new' class='fnname'>new</a>(tx: <a class="struct" href="https://doc.rust-lang.org/nightly/std/sync/mpsc/struct.Sender.html" title="struct std::sync::mpsc::Sender">Sender</a><<a class="enum" href="../notify/enum.DebouncedEvent.html" title="enum notify::DebouncedEvent">DebouncedEvent</a>>, delay: <a class="struct" href="https://doc.rust-lang.org/nightly/core/time/struct.Duration.html" title="struct core::time::Duration">Duration</a>) -> <a class="type" href="../notify/type.Result.html" title="type notify::Result">Result</a><<a class="struct" href="../notify/inotify/struct.INotifyWatcher.html" title="struct notify::inotify::INotifyWatcher">INotifyWatcher</a>></code><a class='srclink' href='../src/notify/inotify.rs.html#448-458' title='goto source code'>[src]</a></h4><h4 id='method.watch' class="method hidden"><code id='watch.v-1'>fn <a href='#method.watch' class='fnname'>watch</a><P: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a><<a class="struct" href="https://doc.rust-lang.org/nightly/std/path/struct.Path.html" title="struct std::path::Path">Path</a>>>(<br> &mut self, <br> path: P, <br> recursive_mode: <a class="enum" href="../notify/enum.RecursiveMode.html" title="enum notify::RecursiveMode">RecursiveMode</a><br>) -> <a class="type" href="../notify/type.Result.html" title="type notify::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>></code><a class='srclink' href='../src/notify/inotify.rs.html#460-473' title='goto source code'>[src]</a></h4><h4 id='method.unwatch' class="method hidden"><code id='unwatch.v-1'>fn <a href='#method.unwatch' class='fnname'>unwatch</a><P: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a><<a class="struct" href="https://doc.rust-lang.org/nightly/std/path/struct.Path.html" title="struct std::path::Path">Path</a>>>(&mut self, path: P) -> <a class="type" href="../notify/type.Result.html" title="type notify::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>></code><a class='srclink' href='../src/notify/inotify.rs.html#475-488' title='goto source code'>[src]</a></h4></div><h3 id='impl-Watcher-1' class='impl'><code class='in-band'>impl Watcher for <a class="struct" href="../notify/null/struct.NullWatcher.html" title="struct notify::null::NullWatcher">NullWatcher</a></code><a href='#impl-Watcher-1' class='anchor'></a><a class='srclin
|
|
|
|
|
src="../implementors/notify/trait.Watcher.js">
|
|
|
|
|
</script></section><section id="search" class="content hidden"></section><section class="footer"></section><aside id="help" class="hidden"><div><h1 class="hidden">Help</h1><div class="shortcuts"><h2>Keyboard Shortcuts</h2><dl><dt><kbd>?</kbd></dt><dd>Show this help dialog</dd><dt><kbd>S</kbd></dt><dd>Focus the search field</dd><dt><kbd>↑</kbd></dt><dd>Move up in search results</dd><dt><kbd>↓</kbd></dt><dd>Move down in search results</dd><dt><kbd>↹</kbd></dt><dd>Switch tab</dd><dt><kbd>⏎</kbd></dt><dd>Go to active search result</dd><dt><kbd>+</kbd></dt><dd>Expand all sections</dd><dt><kbd>-</kbd></dt><dd>Collapse all sections</dd></dl></div><div class="infos"><h2>Search Tricks</h2><p>Prefix searches with a type followed by a colon (e.g., <code>fn:</code>) to restrict the search to a given type.</p><p>Accepted types are: <code>fn</code>, <code>mod</code>, <code>struct</code>, <code>enum</code>, <code>trait</code>, <code>type</code>, <code>macro</code>, and <code>const</code>.</p><p>Search functions by type signature (e.g., <code>vec -> usize</code> or <code>* -> vec</code>)</p><p>Search multiple things at once by splitting your query with comma (e.g., <code>str,u8</code> or <code>String,struct:Vec,test</code>)</p></div></div></aside><script>window.rootPath = "../";window.currentCrate = "notify";</script><script src="../aliases.js"></script><script src="../main.js"></script><script defer src="../search-index.js"></script></body></html>
|