<!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 `FileType` struct in crate `std`."> <meta name="keywords" content="rust, rustlang, rust-lang, FileType"> <title>std::fs::FileType - 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="../../main.css" id="themeStyle"> <script src="../../storage.js"></script> <link rel="shortcut icon" href="https://doc.rust-lang.org/favicon.ico"> </head> <body class="rustdoc struct"> <!--[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='../../std/index.html'><img src='https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png' alt='logo' width='100'></a> <p class='location'>Struct FileType</p><div class="sidebar-elems"><div class="block items"><a class="sidebar-title" href="#methods">Methods</a><div class="sidebar-links"><a href="#method.is_dir">is_dir</a><a href="#method.is_file">is_file</a><a href="#method.is_symlink">is_symlink</a></div><a class="sidebar-title" href="#implementations">Trait Implementations</a><div class="sidebar-links"><a href="#impl-Copy">Copy</a><a href="#impl-Clone">Clone</a><a href="#impl-PartialEq">PartialEq</a><a href="#impl-Eq">Eq</a><a href="#impl-Hash">Hash</a><a href="#impl-Debug">Debug</a><a href="#impl-FileTypeExt">FileTypeExt</a></div></div><p class='location'><a href='../index.html'>std</a>::<wbr><a href='index.html'>fs</a></p><script>window.sidebarCurrent = {name: 'FileType', ty: 'struct', 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"> <input class="search-input" name="search" autocomplete="off" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"> </div> </form> </nav> <section id='main' class="content"> <h1 class='fqn'><span class='in-band'>Struct <a href='../index.html'>std</a>::<wbr><a href='index.html'>fs</a>::<wbr><a class="struct" href=''>FileType</a></span><span class='out-of-band'><span class='since' title='Stable since Rust version 1.1.0'>1.1.0</span><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/std/fs.rs.html#202' title='goto source code'>[src]</a></span></h1> <pre class='rust struct'>pub struct FileType(_);</pre><div class='docblock'><p>A structure representing a type of file with accessors for each file type. It is returned by <a href="struct.Metadata.html#method.file_type"><code>Metadata::file_type</code></a> method.</p> </div> <h2 id='methods' class='small-section-header'> Methods<a href='#methods' class='anchor'></a> </h2> <h3 id='impl' class='impl'><span class='in-band'><code>impl <a class="struct" href="../../std/fs/struct.FileType.html" title="struct std::fs::FileType">FileType</a></code><a href='#impl' class='anchor'></a></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/std/fs.rs.html#1131-1196' title='goto source code'>[src]</a></span></h3> <div class='impl-items'><h4 id='method.is_dir' class="method"><span id='is_dir.v' class='invisible'><code>pub fn <a href='#method.is_dir' class='fnname'>is_dir</a>(&self) -> <a class="primitive" href="../primitive.bool.html">bool</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/std/fs.rs.html#1148' title='goto source code'>[src]</a></span></h4> <div class='docblock'><p>Test whether this file type represents a directory.</p> <h1 id="examples" class="section-header"><a href="#examples">Examples</a></h1> <pre class="rust rust-example-rendered"> <span class="kw">use</span> <span class="ident">std</span>::<span class="ident">fs</span>; <span class="kw">let</span> <span class="ident">metadata</span> <span class="op">=</span> <span class="ident">fs</span>::<span class="ident">metadata</span>(<span class="string">"foo.txt"</span>)<span class="question-mark">?</span>; <span class="kw">let</span> <span class="ident">file_type</span> <span class="op">=</span> <span class="ident">metadata</span>.<span class="ident">file_type</span>(); <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">file_type</span>.<span class="ident">is_dir</span>(), <span class="bool-val">false</span>);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0Afn%20main()%20%7B%0Afn%20foo()%20-%3E%20std%3A%3Aio%3A%3AResult%3C()%3E%20%7B%0Ause%20std%3A%3Afs%3B%0A%0Alet%20metadata%20%3D%20fs%3A%3Ametadata(%22foo.txt%22)%3F%3B%0Alet%20file_type%20%3D%20metadata.file_type()%3B%0A%0Aassert_eq!(file_type.is_dir()%2C%20false)%3B%0AOk(())%0A%7D%0A%7D">Run</a></pre> </div><h4 id='method.is_file' class="method"><span id='is_file.v' class='invisible'><code>pub fn <a href='#method.is_file' class='fnname'>is_file</a>(&self) -> <a class="primitive" href="../primitive.bool.html">bool</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/std/fs.rs.html#1166' title='goto source code'>[src]</a></span></h4> <div class='docblock'><p>Test whether this file type represents a regular file.</p> <h1 id="examples-1" class="section-header"><a href="#examples-1">Examples</a></h1> <pre class="rust rust-example-rendered"> <span class="kw">use</span> <span class="ident">std</span>::<span class="ident">fs</span>; <span class="kw">let</span> <span class="ident">metadata</span> <span class="op">=</span> <span class="ident">fs</span>::<span class="ident">metadata</span>(<span class="string">"foo.txt"</span>)<span class="question-mark">?</span>; <span class="kw">let</span> <span class="ident">file_type</span> <span class="op">=</span> <span class="ident">metadata</span>.<span class="ident">file_type</span>(); <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">file_type</span>.<span class="ident">is_file</span>(), <span class="bool-val">true</span>);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0Afn%20main()%20%7B%0Afn%20foo()%20-%3E%20std%3A%3Aio%3A%3AResult%3C()%3E%20%7B%0Ause%20std%3A%3Afs%3B%0A%0Alet%20metadata%20%3D%20fs%3A%3Ametadata(%22foo.txt%22)%3F%3B%0Alet%20file_type%20%3D%20metadata.file_type()%3B%0A%0Aassert_eq!(file_type.is_file()%2C%20true)%3B%0AOk(())%0A%7D%0A%7D">Run</a></pre> </div><h4 id='method.is_symlink' class="method"><span id='is_symlink.v' class='invisible'><code>pub fn <a href='#method.is_symlink' class='fnname'>is_symlink</a>(&self) -> <a class="primitive" href="../primitive.bool.html">bool</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/std/fs.rs.html#1195' title='goto source code'>[src]</a></span></h4> <div class='docblock'><p>Test whether this file type represents a symbolic link.</p> <p>The underlying <a href="struct.Metadata.html"><code>Metadata</code></a> struct needs to be retrieved with the <a href="fn.symlink_metadata.html"><code>fs::symlink_metadata</code></a> function and not the <a href="fn.metadata.html"><code>fs::metadata</code></a> function. The <a href="fn.metadata.html"><code>fs::metadata</code></a> function follows symbolic links, so <a href="struct.FileType.html#method.is_symlink"><code>is_symlink</code></a> would always return false for the target file.</p> <h1 id="examples-2" class="section-header"><a href="#examples-2">Examples</a></h1> <pre class="rust rust-example-rendered"> <span class="kw">use</span> <span class="ident">std</span>::<span class="ident">fs</span>; <span class="kw">let</span> <span class="ident">metadata</span> <span class="op">=</span> <span class="ident">fs</span>::<span class="ident">symlink_metadata</span>(<span class="string">"foo.txt"</span>)<span class="question-mark">?</span>; <span class="kw">let</span> <span class="ident">file_type</span> <span class="op">=</span> <span class="ident">metadata</span>.<span class="ident">file_type</span>(); <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">file_type</span>.<span class="ident">is_symlink</span>(), <span class="bool-val">false</span>);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0Afn%20main()%20%7B%0Afn%20foo()%20-%3E%20std%3A%3Aio%3A%3AResult%3C()%3E%20%7B%0Ause%20std%3A%3Afs%3B%0A%0Alet%20metadata%20%3D%20fs%3A%3Asymlink_metadata(%22foo.txt%22)%3F%3B%0Alet%20file_type%20%3D%20metadata.file_type()%3B%0A%0Aassert_eq!(file_type.is_symlink()%2C%20false)%3B%0AOk(())%0A%7D%0A%7D">Run</a></pre> </div></div> <h2 id='implementations' class='small-section-header'> Trait Implementations<a href='#implementations' class='anchor'></a> </h2> <h3 id='impl-Copy' class='impl'><span class='in-band'><code>impl <a class="trait" href="../../std/marker/trait.Copy.html" title="trait std::marker::Copy">Copy</a> for <a class="struct" href="../../std/fs/struct.FileType.html" title="struct std::fs::FileType">FileType</a></code><a href='#impl-Copy' class='anchor'></a></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/std/fs.rs.html#201' title='goto source code'>[src]</a></span></h3> <div class='impl-items'></div><h3 id='impl-Clone' class='impl'><span class='in-band'><code>impl <a class="trait" href="../../std/clone/trait.Clone.html" title="trait std::clone::Clone">Clone</a> for <a class="struct" href="../../std/fs/struct.FileType.html" title="struct std::fs::FileType">FileType</a></code><a href='#impl-Clone' class='anchor'></a></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/std/fs.rs.html#201' title='goto source code'>[src]</a></span></h3> <div class='impl-items'><h4 id='method.clone' class="method"><span id='clone.v' class='invisible'><code>fn <a href='../../std/clone/trait.Clone.html#tymethod.clone' class='fnname'>clone</a>(&self) -> <a class="struct" href="../../std/fs/struct.FileType.html" title="struct std::fs::FileType">FileType</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/std/fs.rs.html#201' title='goto source code'>[src]</a></span></h4> <div class='docblock'><p>Returns a copy of the value. <a href="../../std/clone/trait.Clone.html#tymethod.clone">Read more</a></p> </div><h4 id='method.clone_from' class="method"><span id='clone_from.v' class='invisible'><code>fn <a href='../../std/clone/trait.Clone.html#method.clone_from' class='fnname'>clone_from</a>(&mut self, source: <a class="primitive" href="../primitive.reference.html">&</a>Self)</code></span><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.0.0'>1.0.0</div><a class='srclink' href='../../src/core/clone.rs.html#112-114' title='goto source code'>[src]</a></span></h4> <div class='docblock'><p>Performs copy-assignment from <code>source</code>. <a href="../../std/clone/trait.Clone.html#method.clone_from">Read more</a></p> </div></div><h3 id='impl-PartialEq' class='impl'><span class='in-band'><code>impl <a class="trait" href="../../std/cmp/trait.PartialEq.html" title="trait std::cmp::PartialEq">PartialEq</a> for <a class="struct" href="../../std/fs/struct.FileType.html" title="struct std::fs::FileType">FileType</a></code><a href='#impl-PartialEq' class='anchor'></a></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/std/fs.rs.html#201' title='goto source code'>[src]</a></span></h3> <div class='impl-items'><h4 id='method.eq' class="method"><span id='eq.v' class='invisible'><code>fn <a href='../../std/cmp/trait.PartialEq.html#tymethod.eq' class='fnname'>eq</a>(&self, __arg_0: &<a class="struct" href="../../std/fs/struct.FileType.html" title="struct std::fs::FileType">FileType</a>) -> <a class="primitive" href="../primitive.bool.html">bool</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/std/fs.rs.html#201' title='goto source code'>[src]</a></span></h4> <div class='docblock'><p>This method tests for <code>self</code> and <code>other</code> values to be equal, and is used by <code>==</code>. <a href="../../std/cmp/trait.PartialEq.html#tymethod.eq">Read more</a></p> </div><h4 id='method.ne' class="method"><span id='ne.v' class='invisible'><code>fn <a href='../../std/cmp/trait.PartialEq.html#method.ne' class='fnname'>ne</a>(&self, __arg_0: &<a class="struct" href="../../std/fs/struct.FileType.html" title="struct std::fs::FileType">FileType</a>) -> <a class="primitive" href="../primitive.bool.html">bool</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/std/fs.rs.html#201' title='goto source code'>[src]</a></span></h4> <div class='docblock'><p>This method tests for <code>!=</code>.</p> </div></div><h3 id='impl-Eq' class='impl'><span class='in-band'><code>impl <a class="trait" href="../../std/cmp/trait.Eq.html" title="trait std::cmp::Eq">Eq</a> for <a class="struct" href="../../std/fs/struct.FileType.html" title="struct std::fs::FileType">FileType</a></code><a href='#impl-Eq' class='anchor'></a></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/std/fs.rs.html#201' title='goto source code'>[src]</a></span></h3> <div class='impl-items'></div><h3 id='impl-Hash' class='impl'><span class='in-band'><code>impl <a class="trait" href="../../std/hash/trait.Hash.html" title="trait std::hash::Hash">Hash</a> for <a class="struct" href="../../std/fs/struct.FileType.html" title="struct std::fs::FileType">FileType</a></code><a href='#impl-Hash' class='anchor'></a></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/std/fs.rs.html#201' title='goto source code'>[src]</a></span></h3> <div class='impl-items'><h4 id='method.hash' class="method"><span id='hash.v' class='invisible'><code>fn <a href='../../std/hash/trait.Hash.html#tymethod.hash' class='fnname'>hash</a><__H: <a class="trait" href="../../std/hash/trait.Hasher.html" title="trait std::hash::Hasher">Hasher</a>>(&self, __arg_0: <a class="primitive" href="../primitive.reference.html">&mut </a>__H)</code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/std/fs.rs.html#201' title='goto source code'>[src]</a></span></h4> <div class='docblock'><p>Feeds this value into the given [<code>Hasher</code>]. <a href="../../std/hash/trait.Hash.html#tymethod.hash">Read more</a></p> </div><h4 id='method.hash_slice' class="method"><span id='hash_slice.v' class='invisible'><code>fn <a href='../../std/hash/trait.Hash.html#method.hash_slice' class='fnname'>hash_slice</a><H>(data: <a class="primitive" href="../primitive.slice.html">&[Self]</a>, state: <a class="primitive" href="../primitive.reference.html">&mut </a>H) <span class="where fmt-newline">where<br> H: <a class="trait" href="../../std/hash/trait.Hasher.html" title="trait std::hash::Hasher">Hasher</a>, </span></code></span><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.3.0'>1.3.0</div><a class='srclink' href='../../src/core/hash/mod.rs.html#202-208' title='goto source code'>[src]</a></span></h4> <div class='docblock'><p>Feeds a slice of this type into the given [<code>Hasher</code>]. <a href="../../std/hash/trait.Hash.html#method.hash_slice">Read more</a></p> </div></div><h3 id='impl-Debug' class='impl'><span class='in-band'><code>impl <a class="trait" href="../../std/fmt/trait.Debug.html" title="trait std::fmt::Debug">Debug</a> for <a class="struct" href="../../std/fs/struct.FileType.html" title="struct std::fs::FileType">FileType</a></code><a href='#impl-Debug' class='anchor'></a></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/std/fs.rs.html#201' title='goto source code'>[src]</a></span></h3> <div class='impl-items'><h4 id='method.fmt' class="method"><span id='fmt.v' class='invisible'><code>fn <a href='../../std/fmt/trait.Debug.html#tymethod.fmt' class='fnname'>fmt</a>(&self, __arg_0: &mut <a class="struct" href="../../std/fmt/struct.Formatter.html" title="struct std::fmt::Formatter">Formatter</a>) -> <a class="type" href="../../std/fmt/type.Result.html" title="type std::fmt::Result">Result</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/std/fs.rs.html#201' title='goto source code'>[src]</a></span></h4> <div class='docblock'><p>Formats the value using the given formatter. <a href="../../std/fmt/trait.Debug.html#tymethod.fmt">Read more</a></p> </div></div><h3 id='impl-FileTypeExt' class='impl'><span class='in-band'><code>impl <a class="trait" href="../../std/os/unix/fs/trait.FileTypeExt.html" title="trait std::os::unix::fs::FileTypeExt">FileTypeExt</a> for <a class="struct" href="../../std/fs/struct.FileType.html" title="struct std::fs::FileType">FileType</a></code><a href='#impl-FileTypeExt' class='anchor'></a></span><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.5.0'>1.5.0</div><a class='srclink' href='../../src/std/sys/unix/ext/fs.rs.html#636-641' title='goto source code'>[src]</a></span></h3> <div class='impl-items'><h4 id='method.is_block_device' class="method"><span id='is_block_device.v' class='invisible'><code>fn <a href='../../std/os/unix/fs/trait.FileTypeExt.html#tymethod.is_block_device' class='fnname'>is_block_device</a>(&self) -> <a class="primitive" href="../primitive.bool.html">bool</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/std/sys/unix/ext/fs.rs.html#637' title='goto source code'>[src]</a></span></h4> <div class='stability'><div class='stab portability'>This is supported on <strong>Unix</strong> only.</div></div><div class='docblock'><p>Returns whether this file type is a block device. <a href="../../std/os/unix/fs/trait.FileTypeExt.html#tymethod.is_block_device">Read more</a></p> </div><h4 id='method.is_char_device' class="method"><span id='is_char_device.v' class='invisible'><code>fn <a href='../../std/os/unix/fs/trait.FileTypeExt.html#tymethod.is_char_device' class='fnname'>is_char_device</a>(&self) -> <a class="primitive" href="../primitive.bool.html">bool</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/std/sys/unix/ext/fs.rs.html#638' title='goto source code'>[src]</a></span></h4> <div class='stability'><div class='stab portability'>This is supported on <strong>Unix</strong> only.</div></div><div class='docblock'><p>Returns whether this file type is a char device. <a href="../../std/os/unix/fs/trait.FileTypeExt.html#tymethod.is_char_device">Read more</a></p> </div><h4 id='method.is_fifo' class="method"><span id='is_fifo.v' class='invisible'><code>fn <a href='../../std/os/unix/fs/trait.FileTypeExt.html#tymethod.is_fifo' class='fnname'>is_fifo</a>(&self) -> <a class="primitive" href="../primitive.bool.html">bool</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/std/sys/unix/ext/fs.rs.html#639' title='goto source code'>[src]</a></span></h4> <div class='stability'><div class='stab portability'>This is supported on <strong>Unix</strong> only.</div></div><div class='docblock'><p>Returns whether this file type is a fifo. <a href="../../std/os/unix/fs/trait.FileTypeExt.html#tymethod.is_fifo">Read more</a></p> </div><h4 id='method.is_socket' class="method"><span id='is_socket.v' class='invisible'><code>fn <a href='../../std/os/unix/fs/trait.FileTypeExt.html#tymethod.is_socket' class='fnname'>is_socket</a>(&self) -> <a class="primitive" href="../primitive.bool.html">bool</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/std/sys/unix/ext/fs.rs.html#640' title='goto source code'>[src]</a></span></h4> <div class='stability'><div class='stab portability'>This is supported on <strong>Unix</strong> only.</div></div><div class='docblock'><p>Returns whether this file type is a socket. <a href="../../std/os/unix/fs/trait.FileTypeExt.html#tymethod.is_socket">Read more</a></p> </div></div></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> </div> </div> </aside> <script> window.rootPath = "../../"; window.currentCrate = "std"; </script> <script src="../../main.js"></script> <script defer src="../../search-index.js"></script> </body> </html>