183 lines
45 KiB
HTML
183 lines
45 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="A builder to create an iterator for recursively walking a directory."><meta name="keywords" content="rust, rustlang, rust-lang, WalkDir"><title>WalkDir in walkdir - 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 struct"><!--[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="../walkdir/index.html"><div class="logo-container"><img class="rust-logo" src="../rust-logo.png" alt="logo"></div>
|
||
</a><h2 class="location">Struct WalkDir</h2><div class="sidebar-elems"><div class="block items"><h3 class="sidebar-title"><a href="#implementations">Methods</a></h3><div class="sidebar-links"><a href="#method.contents_first">contents_first</a><a href="#method.follow_links">follow_links</a><a href="#method.max_depth">max_depth</a><a href="#method.max_open">max_open</a><a href="#method.min_depth">min_depth</a><a href="#method.new">new</a><a href="#method.same_file_system">same_file_system</a><a href="#method.sort_by">sort_by</a><a href="#method.sort_by_file_name">sort_by_file_name</a><a href="#method.sort_by_key">sort_by_key</a></div><h3 class="sidebar-title"><a href="#trait-implementations">Trait Implementations</a></h3><div class="sidebar-links"><a href="#impl-Debug">Debug</a><a href="#impl-IntoIterator">IntoIterator</a></div><h3 class="sidebar-title"><a href="#synthetic-implementations">Auto Trait Implementations</a></h3><div class="sidebar-links"><a href="#impl-RefUnwindSafe">!RefUnwindSafe</a><a href="#impl-Send">Send</a><a href="#impl-Sync">Sync</a><a href="#impl-Unpin">Unpin</a><a href="#impl-UnwindSafe">!UnwindSafe</a></div><h3 class="sidebar-title"><a href="#blanket-implementations">Blanket Implementations</a></h3><div class="sidebar-links"><a href="#impl-Any">Any</a><a href="#impl-Borrow%3CT%3E">Borrow<T></a><a href="#impl-BorrowMut%3CT%3E">BorrowMut<T></a><a href="#impl-From%3CT%3E">From<T></a><a href="#impl-Into%3CU%3E">Into<U></a><a href="#impl-TryFrom%3CU%3E">TryFrom<U></a><a href="#impl-TryInto%3CU%3E">TryInto<U></a></div></div><h2 class="location">Other items in<br><a href="index.html">walkdir</a></h2><div id="sidebar-vars" data-name="WalkDir" data-ty="struct" 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="../walkdir/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">Struct <a href="index.html">walkdir</a>::<wbr><a class="struct" href="#">WalkDir</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/walkdir/lib.rs.html#233-236" title="goto source code">[src]</a></span></h1><div class="docblock item-decl"><pre class="rust struct"><code>pub struct WalkDir { /* fields omitted */ }</code></pre></div><details class="rustdoc-toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>A builder to create an iterator for recursively walking a directory.</p>
|
||
<p>Results are returned in depth first fashion, with directories yielded
|
||
before their contents. If <a href="struct.WalkDir.html#method.contents_first"><code>contents_first</code></a> is true, contents are yielded
|
||
before their directories. The order is unspecified but if <a href="struct.WalkDir.html#method.sort_by"><code>sort_by</code></a> is
|
||
given, directory entries are sorted according to this function. Directory
|
||
entries <code>.</code> and <code>..</code> are always omitted.</p>
|
||
<p>If an error occurs at any point during iteration, then it is returned in
|
||
place of its corresponding directory entry and iteration continues as
|
||
normal. If an error occurs while opening a directory for reading, then it
|
||
is not descended into (but the error is still yielded by the iterator).
|
||
Iteration may be stopped at any time. When the iterator is destroyed, all
|
||
resources associated with it are freed.</p>
|
||
<h2 id="usage" class="section-header"><a href="#usage">Usage</a></h2>
|
||
<p>This type implements <a href="https://doc.rust-lang.org/stable/std/iter/trait.IntoIterator.html"><code>IntoIterator</code></a> so that it may be used as the subject
|
||
of a <code>for</code> loop. You may need to call <a href="https://doc.rust-lang.org/nightly/core/iter/trait.IntoIterator.html#tymethod.into_iter"><code>into_iter</code></a> explicitly if you want
|
||
to use iterator adapters such as <a href="struct.IntoIter.html#method.filter_entry"><code>filter_entry</code></a>.</p>
|
||
<p>Idiomatic use of this type should use method chaining to set desired
|
||
options. For example, this only shows entries with a depth of <code>1</code>, <code>2</code> or
|
||
<code>3</code> (relative to <code>foo</code>):</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use</span> <span class="ident">walkdir::WalkDir</span>;
|
||
|
||
<span class="kw">for</span> <span class="ident">entry</span> <span class="kw">in</span> <span class="ident">WalkDir::new</span>(<span class="string">"foo"</span>).<span class="ident">min_depth</span>(<span class="number">1</span>).<span class="ident">max_depth</span>(<span class="number">3</span>) {
|
||
<span class="macro">println!</span>(<span class="string">"{}"</span>, <span class="ident">entry</span><span class="question-mark">?</span>.<span class="ident">path</span>().<span class="ident">display</span>());
|
||
}</code></pre></div>
|
||
<p>Note that the iterator by default includes the top-most directory. Since
|
||
this is the only directory yielded with depth <code>0</code>, it is easy to ignore it
|
||
with the <a href="struct.WalkDir.html#method.min_depth"><code>min_depth</code></a> setting:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use</span> <span class="ident">walkdir::WalkDir</span>;
|
||
|
||
<span class="kw">for</span> <span class="ident">entry</span> <span class="kw">in</span> <span class="ident">WalkDir::new</span>(<span class="string">"foo"</span>).<span class="ident">min_depth</span>(<span class="number">1</span>) {
|
||
<span class="macro">println!</span>(<span class="string">"{}"</span>, <span class="ident">entry</span><span class="question-mark">?</span>.<span class="ident">path</span>().<span class="ident">display</span>());
|
||
}</code></pre></div>
|
||
<p>This will only return descendents of the <code>foo</code> directory and not <code>foo</code>
|
||
itself.</p>
|
||
<h2 id="loops" class="section-header"><a href="#loops">Loops</a></h2>
|
||
<p>This iterator (like most/all recursive directory iterators) assumes that
|
||
no loops can be made with <em>hard</em> links on your file system. In particular,
|
||
this would require creating a hard link to a directory such that it creates
|
||
a loop. On most platforms, this operation is illegal.</p>
|
||
<p>Note that when following symbolic/soft links, loops are detected and an
|
||
error is reported.</p>
|
||
</div></details><h2 id="implementations" class="small-section-header">Implementations<a href="#implementations" class="anchor"></a></h2><details class="rustdoc-toggle implementors-toggle" open><summary><div id="impl" class="impl has-srclink"><div class="rightside"><a class="srclink" href="../src/walkdir/lib.rs.html#278-511" title="goto source code">[src]</a></div><a href="#impl" class="anchor"></a><h3 class="code-header in-band">impl <a class="struct" href="struct.WalkDir.html" title="struct walkdir::WalkDir">WalkDir</a></h3></div></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><div id="method.new" class="method has-srclink"><div class="rightside"><a class="srclink" href="../src/walkdir/lib.rs.html#286-299" title="goto source code">[src]</a></div><a href="#method.new" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.new" class="fnname">new</a><P: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a><<a class="struct" href="https://doc.rust-lang.org/1.59.0/std/path/struct.Path.html" title="struct std::path::Path">Path</a>>>(root: P) -> Self</h4></div></summary><div class="docblock"><p>Create a builder for a recursive directory iterator starting at the
|
||
file path <code>root</code>. If <code>root</code> is a directory, then it is the first item
|
||
yielded by the iterator. If <code>root</code> is a file, then it is the first
|
||
and only item yielded by the iterator. If <code>root</code> is a symlink, then it
|
||
is always followed for the purposes of directory traversal. (A root
|
||
<code>DirEntry</code> still obeys its documentation with respect to symlinks and
|
||
the <code>follow_links</code> setting.)</p>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.min_depth" class="method has-srclink"><div class="rightside"><a class="srclink" href="../src/walkdir/lib.rs.html#306-312" title="goto source code">[src]</a></div><a href="#method.min_depth" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.min_depth" class="fnname">min_depth</a>(self, depth: <a class="primitive" href="https://doc.rust-lang.org/1.59.0/std/primitive.usize.html">usize</a>) -> Self</h4></div></summary><div class="docblock"><p>Set the minimum depth of entries yielded by the iterator.</p>
|
||
<p>The smallest depth is <code>0</code> and always corresponds to the path given
|
||
to the <code>new</code> function on this type. Its direct descendents have depth
|
||
<code>1</code>, and their descendents have depth <code>2</code>, and so on.</p>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.max_depth" class="method has-srclink"><div class="rightside"><a class="srclink" href="../src/walkdir/lib.rs.html#323-329" title="goto source code">[src]</a></div><a href="#method.max_depth" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.max_depth" class="fnname">max_depth</a>(self, depth: <a class="primitive" href="https://doc.rust-lang.org/1.59.0/std/primitive.usize.html">usize</a>) -> Self</h4></div></summary><div class="docblock"><p>Set the maximum depth of entries yield by the iterator.</p>
|
||
<p>The smallest depth is <code>0</code> and always corresponds to the path given
|
||
to the <code>new</code> function on this type. Its direct descendents have depth
|
||
<code>1</code>, and their descendents have depth <code>2</code>, and so on.</p>
|
||
<p>Note that this will not simply filter the entries of the iterator, but
|
||
it will actually avoid descending into directories when the depth is
|
||
exceeded.</p>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.follow_links" class="method has-srclink"><div class="rightside"><a class="srclink" href="../src/walkdir/lib.rs.html#342-345" title="goto source code">[src]</a></div><a href="#method.follow_links" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.follow_links" class="fnname">follow_links</a>(self, yes: <a class="primitive" href="https://doc.rust-lang.org/1.59.0/std/primitive.bool.html">bool</a>) -> Self</h4></div></summary><div class="docblock"><p>Follow symbolic links. By default, this is disabled.</p>
|
||
<p>When <code>yes</code> is <code>true</code>, symbolic links are followed as if they were
|
||
normal directories and files. If a symbolic link is broken or is
|
||
involved in a loop, an error is yielded.</p>
|
||
<p>When enabled, the yielded <a href="struct.DirEntry.html"><code>DirEntry</code></a> values represent the target of
|
||
the link while the path corresponds to the link. See the <a href="struct.DirEntry.html"><code>DirEntry</code></a>
|
||
type for more details.</p>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.max_open" class="method has-srclink"><div class="rightside"><a class="srclink" href="../src/walkdir/lib.rs.html#372-378" title="goto source code">[src]</a></div><a href="#method.max_open" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.max_open" class="fnname">max_open</a>(self, n: <a class="primitive" href="https://doc.rust-lang.org/1.59.0/std/primitive.usize.html">usize</a>) -> Self</h4></div></summary><div class="docblock"><p>Set the maximum number of simultaneously open file descriptors used
|
||
by the iterator.</p>
|
||
<p><code>n</code> must be greater than or equal to <code>1</code>. If <code>n</code> is <code>0</code>, then it is set
|
||
to <code>1</code> automatically. If this is not set, then it defaults to some
|
||
reasonably low number.</p>
|
||
<p>This setting has no impact on the results yielded by the iterator
|
||
(even when <code>n</code> is <code>1</code>). Instead, this setting represents a trade off
|
||
between scarce resources (file descriptors) and memory. Namely, when
|
||
the maximum number of file descriptors is reached and a new directory
|
||
needs to be opened to continue iteration, then a previous directory
|
||
handle is closed and has its unyielded entries stored in memory. In
|
||
practice, this is a satisfying trade off because it scales with respect
|
||
to the <em>depth</em> of your file tree. Therefore, low values (even <code>1</code>) are
|
||
acceptable.</p>
|
||
<p>Note that this value does not impact the number of system calls made by
|
||
an exhausted iterator.</p>
|
||
<h5 id="platform-behavior" class="section-header"><a href="#platform-behavior">Platform behavior</a></h5>
|
||
<p>On Windows, if <code>follow_links</code> is enabled, then this limit is not
|
||
respected. In particular, the maximum number of file descriptors opened
|
||
is proportional to the depth of the directory tree traversed.</p>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.sort_by" class="method has-srclink"><div class="rightside"><a class="srclink" href="../src/walkdir/lib.rs.html#394-400" title="goto source code">[src]</a></div><a href="#method.sort_by" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.sort_by" class="fnname">sort_by</a><F>(self, cmp: F) -> Self <span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&<a class="struct" href="struct.DirEntry.html" title="struct walkdir::DirEntry">DirEntry</a>, &<a class="struct" href="struct.DirEntry.html" title="struct walkdir::DirEntry">DirEntry</a>) -> <a class="enum" href="https://doc.rust-lang.org/1.59.0/core/cmp/enum.Ordering.html" title="enum core::cmp::Ordering">Ordering</a> + <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> + <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + 'static, </span></h4></div></summary><div class="docblock"><p>Set a function for sorting directory entries with a comparator
|
||
function.</p>
|
||
<p>If a compare function is set, the resulting iterator will return all
|
||
paths in sorted order. The compare function will be called to compare
|
||
entries from the same directory.</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use</span> <span class="ident">std::cmp</span>;
|
||
<span class="kw">use</span> <span class="ident">std::ffi::OsString</span>;
|
||
<span class="kw">use</span> <span class="ident">walkdir::WalkDir</span>;
|
||
|
||
<span class="ident">WalkDir::new</span>(<span class="string">"foo"</span>).<span class="ident">sort_by</span>(<span class="op">|</span><span class="ident">a</span>,<span class="ident">b</span><span class="op">|</span> <span class="ident">a</span>.<span class="ident">file_name</span>().<span class="ident">cmp</span>(<span class="ident">b</span>.<span class="ident">file_name</span>()));</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.sort_by_key" class="method has-srclink"><div class="rightside"><a class="srclink" href="../src/walkdir/lib.rs.html#416-422" title="goto source code">[src]</a></div><a href="#method.sort_by_key" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.sort_by_key" class="fnname">sort_by_key</a><K, F>(self, cmp: F) -> Self <span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&<a class="struct" href="struct.DirEntry.html" title="struct walkdir::DirEntry">DirEntry</a>) -> K + <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> + <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + 'static,<br> K: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/cmp/trait.Ord.html" title="trait core::cmp::Ord">Ord</a>, </span></h4></div></summary><div class="docblock"><p>Set a function for sorting directory entries with a key extraction
|
||
function.</p>
|
||
<p>If a compare function is set, the resulting iterator will return all
|
||
paths in sorted order. The compare function will be called to compare
|
||
entries from the same directory.</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use</span> <span class="ident">std::cmp</span>;
|
||
<span class="kw">use</span> <span class="ident">std::ffi::OsString</span>;
|
||
<span class="kw">use</span> <span class="ident">walkdir::WalkDir</span>;
|
||
|
||
<span class="ident">WalkDir::new</span>(<span class="string">"foo"</span>).<span class="ident">sort_by_key</span>(<span class="op">|</span><span class="ident">a</span><span class="op">|</span> <span class="ident">a</span>.<span class="ident">file_name</span>().<span class="ident">to_owned</span>());</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.sort_by_file_name" class="method has-srclink"><div class="rightside"><a class="srclink" href="../src/walkdir/lib.rs.html#433-435" title="goto source code">[src]</a></div><a href="#method.sort_by_file_name" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.sort_by_file_name" class="fnname">sort_by_file_name</a>(self) -> Self</h4></div></summary><div class="docblock"><p>Sort directory entries by file name, to ensure a deterministic order.</p>
|
||
<p>This is a convenience function for calling <code>Self::sort_by()</code>.</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use</span> <span class="ident">walkdir::WalkDir</span>;
|
||
|
||
<span class="ident">WalkDir::new</span>(<span class="string">"foo"</span>).<span class="ident">sort_by_file_name</span>();</code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.contents_first" class="method has-srclink"><div class="rightside"><a class="srclink" href="../src/walkdir/lib.rs.html#494-497" title="goto source code">[src]</a></div><a href="#method.contents_first" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.contents_first" class="fnname">contents_first</a>(self, yes: <a class="primitive" href="https://doc.rust-lang.org/1.59.0/std/primitive.bool.html">bool</a>) -> Self</h4></div></summary><div class="docblock"><p>Yield a directory’s contents before the directory itself. By default,
|
||
this is disabled.</p>
|
||
<p>When <code>yes</code> is <code>false</code> (as is the default), the directory is yielded
|
||
before its contents are read. This is useful when, e.g. you want to
|
||
skip processing of some directories.</p>
|
||
<p>When <code>yes</code> is <code>true</code>, the iterator yields the contents of a directory
|
||
before yielding the directory itself. This is useful when, e.g. you
|
||
want to recursively delete a directory.</p>
|
||
<h5 id="example" class="section-header"><a href="#example">Example</a></h5>
|
||
<p>Assume the following directory tree:</p>
|
||
<div class="example-wrap"><pre class="language-text"><code>foo/
|
||
abc/
|
||
qrs
|
||
tuv
|
||
def/</code></pre></div>
|
||
<p>With contents_first disabled (the default), the following code visits
|
||
the directory tree in depth-first order:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use</span> <span class="ident">walkdir::WalkDir</span>;
|
||
|
||
<span class="kw">for</span> <span class="ident">entry</span> <span class="kw">in</span> <span class="ident">WalkDir::new</span>(<span class="string">"foo"</span>) {
|
||
<span class="kw">let</span> <span class="ident">entry</span> <span class="op">=</span> <span class="ident">entry</span>.<span class="ident">unwrap</span>();
|
||
<span class="macro">println!</span>(<span class="string">"{}"</span>, <span class="ident">entry</span>.<span class="ident">path</span>().<span class="ident">display</span>());
|
||
}
|
||
|
||
<span class="comment">// foo</span>
|
||
<span class="comment">// foo/abc</span>
|
||
<span class="comment">// foo/abc/qrs</span>
|
||
<span class="comment">// foo/abc/tuv</span>
|
||
<span class="comment">// foo/def</span></code></pre></div>
|
||
<p>With contents_first enabled:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use</span> <span class="ident">walkdir::WalkDir</span>;
|
||
|
||
<span class="kw">for</span> <span class="ident">entry</span> <span class="kw">in</span> <span class="ident">WalkDir::new</span>(<span class="string">"foo"</span>).<span class="ident">contents_first</span>(<span class="bool-val">true</span>) {
|
||
<span class="kw">let</span> <span class="ident">entry</span> <span class="op">=</span> <span class="ident">entry</span>.<span class="ident">unwrap</span>();
|
||
<span class="macro">println!</span>(<span class="string">"{}"</span>, <span class="ident">entry</span>.<span class="ident">path</span>().<span class="ident">display</span>());
|
||
}
|
||
|
||
<span class="comment">// foo/abc/qrs</span>
|
||
<span class="comment">// foo/abc/tuv</span>
|
||
<span class="comment">// foo/abc</span>
|
||
<span class="comment">// foo/def</span>
|
||
<span class="comment">// foo</span></code></pre></div>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.same_file_system" class="method has-srclink"><div class="rightside"><a class="srclink" href="../src/walkdir/lib.rs.html#507-510" title="goto source code">[src]</a></div><a href="#method.same_file_system" class="anchor"></a><h4 class="code-header">pub fn <a href="#method.same_file_system" class="fnname">same_file_system</a>(self, yes: <a class="primitive" href="https://doc.rust-lang.org/1.59.0/std/primitive.bool.html">bool</a>) -> Self</h4></div></summary><div class="docblock"><p>Do not cross file system boundaries.</p>
|
||
<p>When this option is enabled, directory traversal will not descend into
|
||
directories that are on a different file system from the root path.</p>
|
||
<p>Currently, this option is only supported on Unix and Windows. If this
|
||
option is used on an unsupported platform, then directory traversal
|
||
will immediately return an error and will not yield any entries.</p>
|
||
</div></details></div></details><h2 id="trait-implementations" class="small-section-header">Trait Implementations<a href="#trait-implementations" class="anchor"></a></h2><div id="trait-implementations-list"><details class="rustdoc-toggle implementors-toggle" open><summary><div id="impl-Debug" class="impl has-srclink"><div class="rightside"><a class="srclink" href="../src/walkdir/lib.rs.html#232" title="goto source code">[src]</a></div><a href="#impl-Debug" class="anchor"></a><h3 class="code-header in-band">impl <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/fmt/trait.Debug.html" title="trait core::fmt::Debug">Debug</a> for <a class="struct" href="struct.WalkDir.html" title="struct walkdir::WalkDir">WalkDir</a></h3></div></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><div id="method.fmt" class="method trait-impl has-srclink"><div class="rightside"><a class="srclink" href="../src/walkdir/lib.rs.html#232" title="goto source code">[src]</a></div><a href="#method.fmt" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.59.0/core/fmt/trait.Debug.html#tymethod.fmt" class="fnname">fmt</a>(&self, f: &mut <a class="struct" href="https://doc.rust-lang.org/1.59.0/core/fmt/struct.Formatter.html" title="struct core::fmt::Formatter">Formatter</a><'_>) -> <a class="type" href="https://doc.rust-lang.org/1.59.0/core/fmt/type.Result.html" title="type core::fmt::Result">Result</a></h4></div></summary><div class='docblock'><p>Formats the value using the given formatter. <a href="https://doc.rust-lang.org/1.59.0/core/fmt/trait.Debug.html#tymethod.fmt">Read more</a></p>
|
||
</div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><div id="impl-IntoIterator" class="impl has-srclink"><div class="rightside"><a class="srclink" href="../src/walkdir/lib.rs.html#513-529" title="goto source code">[src]</a></div><a href="#impl-IntoIterator" class="anchor"></a><h3 class="code-header in-band">impl <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a> for <a class="struct" href="struct.WalkDir.html" title="struct walkdir::WalkDir">WalkDir</a></h3></div></summary><div class="impl-items"><details class="rustdoc-toggle" open><summary><div id="associatedtype.Item" class="type trait-impl has-srclink"><a href="#associatedtype.Item" class="anchor"></a><h4 class="code-header">type <a href="https://doc.rust-lang.org/1.59.0/core/iter/traits/collect/trait.IntoIterator.html#associatedtype.Item" class="associatedtype">Item</a> = <a class="type" href="type.Result.html" title="type walkdir::Result">Result</a><<a class="struct" href="struct.DirEntry.html" title="struct walkdir::DirEntry">DirEntry</a>></h4></div></summary><div class='docblock'><p>The type of the elements being iterated over.</p>
|
||
</div></details><details class="rustdoc-toggle" open><summary><div id="associatedtype.IntoIter" class="type trait-impl has-srclink"><a href="#associatedtype.IntoIter" class="anchor"></a><h4 class="code-header">type <a href="https://doc.rust-lang.org/1.59.0/core/iter/traits/collect/trait.IntoIterator.html#associatedtype.IntoIter" class="associatedtype">IntoIter</a> = <a class="struct" href="struct.IntoIter.html" title="struct walkdir::IntoIter">IntoIter</a></h4></div></summary><div class='docblock'><p>Which kind of iterator are we turning this into?</p>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.into_iter" class="method trait-impl has-srclink"><div class="rightside"><a class="srclink" href="../src/walkdir/lib.rs.html#517-528" title="goto source code">[src]</a></div><a href="#method.into_iter" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.59.0/core/iter/traits/collect/trait.IntoIterator.html#tymethod.into_iter" class="fnname">into_iter</a>(self) -> <a class="struct" href="struct.IntoIter.html" title="struct walkdir::IntoIter">IntoIter</a><span class="notable-traits"><span class="notable-traits-tooltip">ⓘ<div class="notable-traits-tooltiptext"><span class="docblock"><div class="notable">Notable traits for <a class="struct" href="struct.IntoIter.html" title="struct walkdir::IntoIter">IntoIter</a></div><code class="content"><span class="where fmt-newline">impl <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/iter/traits/iterator/trait.Iterator.html" title="trait core::iter::traits::iterator::Iterator">Iterator</a> for <a class="struct" href="struct.IntoIter.html" title="struct walkdir::IntoIter">IntoIter</a></span><span class="where fmt-newline"> type <a href="https://doc.rust-lang.org/1.59.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" class="associatedtype">Item</a> = <a class="type" href="type.Result.html" title="type walkdir::Result">Result</a><<a class="struct" href="struct.DirEntry.html" title="struct walkdir::DirEntry">DirEntry</a>>;</span></code></span></div></span></span></h4></div></summary><div class='docblock'><p>Creates an iterator from a value. <a href="https://doc.rust-lang.org/1.59.0/core/iter/traits/collect/trait.IntoIterator.html#tymethod.into_iter">Read more</a></p>
|
||
</div></details></div></details></div><h2 id="synthetic-implementations" class="small-section-header">Auto Trait Implementations<a href="#synthetic-implementations" class="anchor"></a></h2><div id="synthetic-implementations-list"><div id="impl-RefUnwindSafe" class="impl has-srclink"><div class="rightside"></div><a href="#impl-RefUnwindSafe" class="anchor"></a><h3 class="code-header in-band">impl !<a class="trait" href="https://doc.rust-lang.org/1.59.0/core/panic/unwind_safe/trait.RefUnwindSafe.html" title="trait core::panic::unwind_safe::RefUnwindSafe">RefUnwindSafe</a> for <a class="struct" href="struct.WalkDir.html" title="struct walkdir::WalkDir">WalkDir</a></h3></div><div id="impl-Send" class="impl has-srclink"><div class="rightside"></div><a href="#impl-Send" class="anchor"></a><h3 class="code-header in-band">impl <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> for <a class="struct" href="struct.WalkDir.html" title="struct walkdir::WalkDir">WalkDir</a></h3></div><div id="impl-Sync" class="impl has-srclink"><div class="rightside"></div><a href="#impl-Sync" class="anchor"></a><h3 class="code-header in-band">impl <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> for <a class="struct" href="struct.WalkDir.html" title="struct walkdir::WalkDir">WalkDir</a></h3></div><div id="impl-Unpin" class="impl has-srclink"><div class="rightside"></div><a href="#impl-Unpin" class="anchor"></a><h3 class="code-header in-band">impl <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a> for <a class="struct" href="struct.WalkDir.html" title="struct walkdir::WalkDir">WalkDir</a></h3></div><div id="impl-UnwindSafe" class="impl has-srclink"><div class="rightside"></div><a href="#impl-UnwindSafe" class="anchor"></a><h3 class="code-header in-band">impl !<a class="trait" href="https://doc.rust-lang.org/1.59.0/core/panic/unwind_safe/trait.UnwindSafe.html" title="trait core::panic::unwind_safe::UnwindSafe">UnwindSafe</a> for <a class="struct" href="struct.WalkDir.html" title="struct walkdir::WalkDir">WalkDir</a></h3></div></div><h2 id="blanket-implementations" class="small-section-header">Blanket Implementations<a href="#blanket-implementations" class="anchor"></a></h2><div id="blanket-implementations-list"><details class="rustdoc-toggle implementors-toggle" open><summary><div id="impl-Any" class="impl has-srclink"><div class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/core/any.rs.html#132-136" title="goto source code">[src]</a></div><a href="#impl-Any" class="anchor"></a><h3 class="code-header in-band">impl<T> <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/any/trait.Any.html" title="trait core::any::Any">Any</a> for T <span class="where fmt-newline">where<br> T: 'static + ?<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"><details class="rustdoc-toggle method-toggle" open><summary><div id="method.type_id" class="method trait-impl has-srclink"><div class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/core/any.rs.html#133" title="goto source code">[src]</a></div><a href="#method.type_id" class="anchor"></a><h4 class="code-header">pub fn <a href="https://doc.rust-lang.org/1.59.0/core/any/trait.Any.html#tymethod.type_id" class="fnname">type_id</a>(&self) -> <a class="struct" href="https://doc.rust-lang.org/1.59.0/core/any/struct.TypeId.html" title="struct core::any::TypeId">TypeId</a></h4></div></summary><div class='docblock'><p>Gets the <code>TypeId</code> of <code>self</code>. <a href="https://doc.rust-lang.org/1.59.0/core/any/trait.Any.html#tymethod.type_id">Read more</a></p>
|
||
</div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><div id="impl-Borrow%3CT%3E" class="impl has-srclink"><div class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/core/borrow.rs.html#209-214" title="goto source code">[src]</a></div><a href="#impl-Borrow%3CT%3E" class="anchor"></a><h3 class="code-header in-band">impl<T> <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/borrow/trait.Borrow.html" title="trait core::borrow::Borrow">Borrow</a><T> for T <span class="where fmt-newline">where<br> T: ?<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"><details class="rustdoc-toggle method-toggle" open><summary><div id="method.borrow" class="method trait-impl has-srclink"><div class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/core/borrow.rs.html#211" title="goto source code">[src]</a></div><a href="#method.borrow" class="anchor"></a><h4 class="code-header">pub fn <a href="https://doc.rust-lang.org/1.59.0/core/borrow/trait.Borrow.html#tymethod.borrow" class="fnname">borrow</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/1.59.0/std/primitive.reference.html">&</a>T</h4></div></summary><div class='docblock'><p>Immutably borrows from an owned value. <a href="https://doc.rust-lang.org/1.59.0/core/borrow/trait.Borrow.html#tymethod.borrow">Read more</a></p>
|
||
</div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><div id="impl-BorrowMut%3CT%3E" class="impl has-srclink"><div class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/core/borrow.rs.html#218-222" title="goto source code">[src]</a></div><a href="#impl-BorrowMut%3CT%3E" class="anchor"></a><h3 class="code-header in-band">impl<T> <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/borrow/trait.BorrowMut.html" title="trait core::borrow::BorrowMut">BorrowMut</a><T> for T <span class="where fmt-newline">where<br> T: ?<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"><details class="rustdoc-toggle method-toggle" open><summary><div id="method.borrow_mut" class="method trait-impl has-srclink"><div class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/core/borrow.rs.html#219" title="goto source code">[src]</a></div><a href="#method.borrow_mut" class="anchor"></a><h4 class="code-header">pub fn <a href="https://doc.rust-lang.org/1.59.0/core/borrow/trait.BorrowMut.html#tymethod.borrow_mut" class="fnname">borrow_mut</a>(&mut self) -> <a class="primitive" href="https://doc.rust-lang.org/1.59.0/std/primitive.reference.html">&mut </a>T</h4></div></summary><div class='docblock'><p>Mutably borrows from an owned value. <a href="https://doc.rust-lang.org/1.59.0/core/borrow/trait.BorrowMut.html#tymethod.borrow_mut">Read more</a></p>
|
||
</div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><div id="impl-From%3CT%3E" class="impl has-srclink"><div class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/core/convert/mod.rs.html#550-554" title="goto source code">[src]</a></div><a href="#impl-From%3CT%3E" class="anchor"></a><h3 class="code-header in-band">impl<T> <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/convert/trait.From.html" title="trait core::convert::From">From</a><T> for T</h3></div></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><div id="method.from" class="method trait-impl has-srclink"><div class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/core/convert/mod.rs.html#551" title="goto source code">[src]</a></div><a href="#method.from" class="anchor"></a><h4 class="code-header">pub fn <a href="https://doc.rust-lang.org/1.59.0/core/convert/trait.From.html#tymethod.from" class="fnname">from</a>(t: T) -> T</h4></div></summary><div class='docblock'><p>Performs the conversion.</p>
|
||
</div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><div id="impl-Into%3CU%3E" class="impl has-srclink"><div class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/core/convert/mod.rs.html#538-545" title="goto source code">[src]</a></div><a href="#impl-Into%3CU%3E" class="anchor"></a><h3 class="code-header in-band">impl<T, U> <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a><U> for T <span class="where fmt-newline">where<br> U: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/convert/trait.From.html" title="trait core::convert::From">From</a><T>, </span></h3></div></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><div id="method.into" class="method trait-impl has-srclink"><div class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/core/convert/mod.rs.html#542" title="goto source code">[src]</a></div><a href="#method.into" class="anchor"></a><h4 class="code-header">pub fn <a href="https://doc.rust-lang.org/1.59.0/core/convert/trait.Into.html#tymethod.into" class="fnname">into</a>(self) -> U</h4></div></summary><div class='docblock'><p>Performs the conversion.</p>
|
||
</div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><div id="impl-TryFrom%3CU%3E" class="impl has-srclink"><div class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/core/convert/mod.rs.html#588-597" title="goto source code">[src]</a></div><a href="#impl-TryFrom%3CU%3E" class="anchor"></a><h3 class="code-header in-band">impl<T, U> <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><U> for T <span class="where fmt-newline">where<br> U: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a><T>, </span></h3></div></summary><div class="impl-items"><details class="rustdoc-toggle" open><summary><div id="associatedtype.Error-1" class="type trait-impl has-srclink"><a href="#associatedtype.Error-1" class="anchor"></a><h4 class="code-header">type <a href="https://doc.rust-lang.org/1.59.0/core/convert/trait.TryFrom.html#associatedtype.Error" class="associatedtype">Error</a> = <a class="enum" href="https://doc.rust-lang.org/1.59.0/core/convert/enum.Infallible.html" title="enum core::convert::Infallible">Infallible</a></h4></div></summary><div class='docblock'><p>The type returned in the event of a conversion error.</p>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.try_from" class="method trait-impl has-srclink"><div class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/core/convert/mod.rs.html#594" title="goto source code">[src]</a></div><a href="#method.try_from" class="anchor"></a><h4 class="code-header">pub fn <a href="https://doc.rust-lang.org/1.59.0/core/convert/trait.TryFrom.html#tymethod.try_from" class="fnname">try_from</a>(value: U) -> <a class="enum" href="https://doc.rust-lang.org/1.59.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.59.0/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><U>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.59.0/core/convert/trait.TryFrom.html#associatedtype.Error" title="type core::convert::TryFrom::Error">Error</a>></h4></div></summary><div class='docblock'><p>Performs the conversion.</p>
|
||
</div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><div id="impl-TryInto%3CU%3E" class="impl has-srclink"><div class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/core/convert/mod.rs.html#574-583" title="goto source code">[src]</a></div><a href="#impl-TryInto%3CU%3E" class="anchor"></a><h3 class="code-header in-band">impl<T, U> <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/convert/trait.TryInto.html" title="trait core::convert::TryInto">TryInto</a><U> for T <span class="where fmt-newline">where<br> U: <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><T>, </span></h3></div></summary><div class="impl-items"><details class="rustdoc-toggle" open><summary><div id="associatedtype.Error" class="type trait-impl has-srclink"><a href="#associatedtype.Error" class="anchor"></a><h4 class="code-header">type <a href="https://doc.rust-lang.org/1.59.0/core/convert/trait.TryInto.html#associatedtype.Error" class="associatedtype">Error</a> = <U as <a class="trait" href="https://doc.rust-lang.org/1.59.0/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><T>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.59.0/core/convert/trait.TryFrom.html#associatedtype.Error" title="type core::convert::TryFrom::Error">Error</a></h4></div></summary><div class='docblock'><p>The type returned in the event of a conversion error.</p>
|
||
</div></details><details class="rustdoc-toggle method-toggle" open><summary><div id="method.try_into" class="method trait-impl has-srclink"><div class="rightside"><a class="srclink" href="https://doc.rust-lang.org/1.59.0/src/core/convert/mod.rs.html#580" title="goto source code">[src]</a></div><a href="#method.try_into" class="anchor"></a><h4 class="code-header">pub fn <a href="https://doc.rust-lang.org/1.59.0/core/convert/trait.TryInto.html#tymethod.try_into" class="fnname">try_into</a>(self) -> <a class="enum" href="https://doc.rust-lang.org/1.59.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.59.0/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><T>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.59.0/core/convert/trait.TryFrom.html#associatedtype.Error" title="type core::convert::TryFrom::Error">Error</a>></h4></div></summary><div class='docblock'><p>Performs the conversion.</p>
|
||
</div></details></div></details></div></section><section id="search" class="content hidden"></section></div></main><div id="rustdoc-vars" data-root-path="../" data-current-crate="walkdir" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.59.0 (9d1b2106e 2022-02-23)" ></div>
|
||
</body></html> |