<!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 `PermissionsExt` trait in crate `std`."> <meta name="keywords" content="rust, rustlang, rust-lang, PermissionsExt"> <title>std::os::unix::fs::PermissionsExt - 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 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='../../../../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'>Trait PermissionsExt</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.mode">mode</a><a href="#tymethod.set_mode">set_mode</a><a href="#tymethod.from_mode">from_mode</a></div><a class="sidebar-title" href="#implementors">Implementors</a></div><p class='location'><a href='../../../index.html'>std</a>::<wbr><a href='../../index.html'>os</a>::<wbr><a href='../index.html'>unix</a>::<wbr><a href='index.html'>fs</a></p><script>window.sidebarCurrent = {name: 'PermissionsExt', 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"> <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'>Trait <a href='../../../index.html'>std</a>::<wbr><a href='../../index.html'>os</a>::<wbr><a href='../index.html'>unix</a>::<wbr><a href='index.html'>fs</a>::<wbr><a class="trait" href=''>PermissionsExt</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/sys/unix/ext/fs.rs.html#110-166' title='goto source code'>[src]</a></span></h1> <pre class='rust trait'>pub trait PermissionsExt { fn <a href='#tymethod.mode' class='fnname'>mode</a>(&self) -> <a class="primitive" href="../../../primitive.u32.html">u32</a>; <div class='item-spacer'></div> fn <a href='#tymethod.set_mode' class='fnname'>set_mode</a>(&mut self, mode: <a class="primitive" href="../../../primitive.u32.html">u32</a>); <div class='item-spacer'></div> fn <a href='#tymethod.from_mode' class='fnname'>from_mode</a>(mode: <a class="primitive" href="../../../primitive.u32.html">u32</a>) -> Self; }</pre><div class='stability'><div class='stab portability'>This is supported on <strong>Unix</strong> only.</div></div><div class='docblock'><p>Unix-specific extensions to <code>Permissions</code></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.mode' class='method'><span id='mode.v' class='invisible'><code>fn <a href='#tymethod.mode' class='fnname'>mode</a>(&self) -> <a class="primitive" href="../../../primitive.u32.html">u32</a></code></span></h3><div class='stability'><div class='stab portability'>This is supported on <strong>Unix</strong> only.</div></div><div class='docblock'><p>Returns the underlying raw <code>st_mode</code> bits that contain the standard Unix permissions for this file.</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="ident">File</span>; <span class="kw">use</span> <span class="ident">std</span>::<span class="ident">os</span>::<span class="ident">unix</span>::<span class="ident">fs</span>::<span class="ident">PermissionsExt</span>; <span class="kw">let</span> <span class="ident">f</span> <span class="op">=</span> <span class="ident">File</span>::<span class="ident">create</span>(<span class="string">"foo.txt"</span>)<span class="question-mark">?</span>; <span class="kw">let</span> <span class="ident">metadata</span> <span class="op">=</span> <span class="ident">f</span>.<span class="ident">metadata</span>()<span class="question-mark">?</span>; <span class="kw">let</span> <span class="ident">permissions</span> <span class="op">=</span> <span class="ident">metadata</span>.<span class="ident">permissions</span>(); <span class="macro">println</span><span class="macro">!</span>(<span class="string">"permissions: {}"</span>, <span class="ident">permissions</span>.<span class="ident">mode</span>());<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0Afn%20main()%20%7B%0Ause%20std%3A%3Afs%3A%3AFile%3B%0Ause%20std%3A%3Aos%3A%3Aunix%3A%3Afs%3A%3APermissionsExt%3B%0A%0Afn%20run()%20-%3E%20std%3A%3Aio%3A%3AResult%3C()%3E%20%7B%0Alet%20f%20%3D%20File%3A%3Acreate(%22foo.txt%22)%3F%3B%0Alet%20metadata%20%3D%20f.metadata()%3F%3B%0Alet%20permissions%20%3D%20metadata.permissions()%3B%0A%0Aprintln!(%22permissions%3A%20%7B%7D%22%2C%20permissions.mode())%3B%0AOk(())%20%7D%0A%7D">Run</a></pre> </div><h3 id='tymethod.set_mode' class='method'><span id='set_mode.v' class='invisible'><code>fn <a href='#tymethod.set_mode' class='fnname'>set_mode</a>(&mut self, mode: <a class="primitive" href="../../../primitive.u32.html">u32</a>)</code></span></h3><div class='stability'><div class='stab portability'>This is supported on <strong>Unix</strong> only.</div></div><div class='docblock'><p>Sets the underlying raw bits for this set of permissions.</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="ident">File</span>; <span class="kw">use</span> <span class="ident">std</span>::<span class="ident">os</span>::<span class="ident">unix</span>::<span class="ident">fs</span>::<span class="ident">PermissionsExt</span>; <span class="kw">let</span> <span class="ident">f</span> <span class="op">=</span> <span class="ident">File</span>::<span class="ident">create</span>(<span class="string">"foo.txt"</span>)<span class="question-mark">?</span>; <span class="kw">let</span> <span class="ident">metadata</span> <span class="op">=</span> <span class="ident">f</span>.<span class="ident">metadata</span>()<span class="question-mark">?</span>; <span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">permissions</span> <span class="op">=</span> <span class="ident">metadata</span>.<span class="ident">permissions</span>(); <span class="ident">permissions</span>.<span class="ident">set_mode</span>(<span class="number">0o644</span>); <span class="comment">// Read/write for owner and read for others.</span> <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">permissions</span>.<span class="ident">mode</span>(), <span class="number">0o644</span>);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0Afn%20main()%20%7B%0Ause%20std%3A%3Afs%3A%3AFile%3B%0Ause%20std%3A%3Aos%3A%3Aunix%3A%3Afs%3A%3APermissionsExt%3B%0A%0Afn%20run()%20-%3E%20std%3A%3Aio%3A%3AResult%3C()%3E%20%7B%0Alet%20f%20%3D%20File%3A%3Acreate(%22foo.txt%22)%3F%3B%0Alet%20metadata%20%3D%20f.metadata()%3F%3B%0Alet%20mut%20permissions%20%3D%20metadata.permissions()%3B%0A%0Apermissions.set_mode(0o644)%3B%20%2F%2F%20Read%2Fwrite%20for%20owner%20and%20read%20for%20others.%0Aassert_eq!(permissions.mode()%2C%200o644)%3B%0AOk(())%20%7D%0A%7D">Run</a></pre> </div><h3 id='tymethod.from_mode' class='method'><span id='from_mode.v' class='invisible'><code>fn <a href='#tymethod.from_mode' class='fnname'>from_mode</a>(mode: <a class="primitive" href="../../../primitive.u32.html">u32</a>) -> Self</code></span></h3><div class='stability'><div class='stab portability'>This is supported on <strong>Unix</strong> only.</div></div><div class='docblock'><p>Creates a new instance of <code>Permissions</code> from the given set of Unix permission bits.</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="ident">Permissions</span>; <span class="kw">use</span> <span class="ident">std</span>::<span class="ident">os</span>::<span class="ident">unix</span>::<span class="ident">fs</span>::<span class="ident">PermissionsExt</span>; <span class="comment">// Read/write for owner and read for others.</span> <span class="kw">let</span> <span class="ident">permissions</span> <span class="op">=</span> <span class="ident">Permissions</span>::<span class="ident">from_mode</span>(<span class="number">0o644</span>); <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">permissions</span>.<span class="ident">mode</span>(), <span class="number">0o644</span>);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0Afn%20main()%20%7B%0Ause%20std%3A%3Afs%3A%3APermissions%3B%0Ause%20std%3A%3Aos%3A%3Aunix%3A%3Afs%3A%3APermissionsExt%3B%0A%0A%2F%2F%20Read%2Fwrite%20for%20owner%20and%20read%20for%20others.%0Alet%20permissions%20%3D%20Permissions%3A%3Afrom_mode(0o644)%3B%0Aassert_eq!(permissions.mode()%2C%200o644)%3B%0A%7D">Run</a></pre> </div></div> <h2 id='implementors' class='small-section-header'> Implementors<a href='#implementors' class='anchor'></a> </h2> <ul class='item-list' id='implementors-list'> <li><div class='out-of-band'><a class='srclink' href='../../../../src/std/sys/unix/ext/fs.rs.html#169-181' title='goto source code'>[src]</a></div><code>impl PermissionsExt for <a class="struct" href="../../../../std/fs/struct.Permissions.html" title="struct std::fs::Permissions">Permissions</a></code></li> </ul><script type="text/javascript" async src="../../../../implementors/std/os/unix/fs/trait.PermissionsExt.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> </div> </div> </aside> <script> window.rootPath = "../../../../"; window.currentCrate = "std"; </script> <script src="../../../../main.js"></script> <script defer src="../../../../search-index.js"></script> </body> </html>