Sophie

Sophie

distrib > Mageia > 6 > x86_64 > media > core-updates > by-pkgid > fdedb3cf2140df9b6d419a2338ab1caa > files > 4159

rust-doc-1.25.0-1.mga6.x86_64.rpm

<!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 `OpenOptions` struct in crate `std`.">
    <meta name="keywords" content="rust, rustlang, rust-lang, OpenOptions">

    <title>std::fs::OpenOptions - 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">&#9776;</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 OpenOptions</p><div class="sidebar-elems"><div class="block items"><a class="sidebar-title" href="#methods">Methods</a><div class="sidebar-links"><a href="#method.new">new</a><a href="#method.read">read</a><a href="#method.write">write</a><a href="#method.append">append</a><a href="#method.truncate">truncate</a><a href="#method.create">create</a><a href="#method.create_new">create_new</a><a href="#method.open">open</a></div><a class="sidebar-title" href="#implementations">Trait Implementations</a><div class="sidebar-links"><a href="#impl-Clone">Clone</a><a href="#impl-Debug">Debug</a><a href="#impl-OpenOptionsExt">OpenOptionsExt</a></div></div><p class='location'><a href='../index.html'>std</a>::<wbr><a href='index.html'>fs</a></p><script>window.sidebarCurrent = {name: 'OpenOptions', 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=''>OpenOptions</a></span><span class='out-of-band'><span class='since' title='Stable since Rust version 1.0.0'>1.0.0</span><span id='render-detail'>
                   <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">
                       [<span class='inner'>&#x2212;</span>]
                   </a>
               </span><a class='srclink' href='../../src/std/fs.rs.html#182' title='goto source code'>[src]</a></span></h1>
<pre class='rust struct'>pub struct OpenOptions(_);</pre><div class='docblock'><p>Options and flags which can be used to configure how a file is opened.</p>
<p>This builder exposes the ability to configure how a <a href="struct.File.html"><code>File</code></a> is opened and
what operations are permitted on the open file. The <a href="struct.File.html#method.open"><code>File::open</code></a> and
<a href="struct.File.html#method.create"><code>File::create</code></a> methods are aliases for commonly used options using this
builder.</p>
<p>Generally speaking, when using <code>OpenOptions</code>, you'll first call <a href="struct.OpenOptions.html#method.new"><code>new</code></a>,
then chain calls to methods to set each option, then call <a href="struct.OpenOptions.html#method.open"><code>open</code></a>,
passing the path of the file you're trying to open. This will give you a
<a href="../io/type.Result.html"><code>io::Result</code></a> with a <a href="struct.File.html"><code>File</code></a> inside that you can further
operate on.</p>
<h1 id="examples" class="section-header"><a href="#examples">Examples</a></h1>
<p>Opening a file to read:</p>

<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">fs</span>::<span class="ident">OpenOptions</span>;

<span class="kw">let</span> <span class="ident">file</span> <span class="op">=</span> <span class="ident">OpenOptions</span>::<span class="ident">new</span>().<span class="ident">read</span>(<span class="bool-val">true</span>).<span class="ident">open</span>(<span class="string">&quot;foo.txt&quot;</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%3AOpenOptions%3B%0A%0Alet%20file%20%3D%20OpenOptions%3A%3Anew().read(true).open(%22foo.txt%22)%3B%0A%7D">Run</a></pre>
<p>Opening a file for both reading and writing, as well as creating it if it
doesn't exist:</p>

<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">fs</span>::<span class="ident">OpenOptions</span>;

<span class="kw">let</span> <span class="ident">file</span> <span class="op">=</span> <span class="ident">OpenOptions</span>::<span class="ident">new</span>()
            .<span class="ident">read</span>(<span class="bool-val">true</span>)
            .<span class="ident">write</span>(<span class="bool-val">true</span>)
            .<span class="ident">create</span>(<span class="bool-val">true</span>)
            .<span class="ident">open</span>(<span class="string">&quot;foo.txt&quot;</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%3AOpenOptions%3B%0A%0Alet%20file%20%3D%20OpenOptions%3A%3Anew()%0A%20%20%20%20%20%20%20%20%20%20%20%20.read(true)%0A%20%20%20%20%20%20%20%20%20%20%20%20.write(true)%0A%20%20%20%20%20%20%20%20%20%20%20%20.create(true)%0A%20%20%20%20%20%20%20%20%20%20%20%20.open(%22foo.txt%22)%3B%0A%7D">Run</a></pre>
</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.OpenOptions.html" title="struct std::fs::OpenOptions">OpenOptions</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#636-864' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.new' class="method"><span id='new.v' class='invisible'><code>pub fn <a href='#method.new' class='fnname'>new</a>() -&gt; <a class="struct" href="../../std/fs/struct.OpenOptions.html" title="struct std::fs::OpenOptions">OpenOptions</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/std/fs.rs.html#650-652' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>Creates a blank new set of options ready for configuration.</p>
<p>All options are initially set to <code>false</code>.</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">OpenOptions</span>;

<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">options</span> <span class="op">=</span> <span class="ident">OpenOptions</span>::<span class="ident">new</span>();
<span class="kw">let</span> <span class="ident">file</span> <span class="op">=</span> <span class="ident">options</span>.<span class="ident">read</span>(<span class="bool-val">true</span>).<span class="ident">open</span>(<span class="string">&quot;foo.txt&quot;</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%3AOpenOptions%3B%0A%0Alet%20mut%20options%20%3D%20OpenOptions%3A%3Anew()%3B%0Alet%20file%20%3D%20options.read(true).open(%22foo.txt%22)%3B%0A%7D">Run</a></pre>
</div><h4 id='method.read' class="method"><span id='read.v' class='invisible'><code>pub fn <a href='#method.read' class='fnname'>read</a>(&amp;mut self, read: <a class="primitive" href="../primitive.bool.html">bool</a>) -&gt; &amp;mut <a class="struct" href="../../std/fs/struct.OpenOptions.html" title="struct std::fs::OpenOptions">OpenOptions</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/std/fs.rs.html#667-669' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>Sets the option for read access.</p>
<p>This option, when true, will indicate that the file should be
<code>read</code>-able if opened.</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">OpenOptions</span>;

<span class="kw">let</span> <span class="ident">file</span> <span class="op">=</span> <span class="ident">OpenOptions</span>::<span class="ident">new</span>().<span class="ident">read</span>(<span class="bool-val">true</span>).<span class="ident">open</span>(<span class="string">&quot;foo.txt&quot;</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%3AOpenOptions%3B%0A%0Alet%20file%20%3D%20OpenOptions%3A%3Anew().read(true).open(%22foo.txt%22)%3B%0A%7D">Run</a></pre>
</div><h4 id='method.write' class="method"><span id='write.v' class='invisible'><code>pub fn <a href='#method.write' class='fnname'>write</a>(&amp;mut self, write: <a class="primitive" href="../primitive.bool.html">bool</a>) -&gt; &amp;mut <a class="struct" href="../../std/fs/struct.OpenOptions.html" title="struct std::fs::OpenOptions">OpenOptions</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/std/fs.rs.html#687-689' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>Sets the option for write access.</p>
<p>This option, when true, will indicate that the file should be
<code>write</code>-able if opened.</p>
<p>If the file already exists, any write calls on it will overwrite its
contents, without truncating it.</p>
<h1 id="examples-3" class="section-header"><a href="#examples-3">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">OpenOptions</span>;

<span class="kw">let</span> <span class="ident">file</span> <span class="op">=</span> <span class="ident">OpenOptions</span>::<span class="ident">new</span>().<span class="ident">write</span>(<span class="bool-val">true</span>).<span class="ident">open</span>(<span class="string">&quot;foo.txt&quot;</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%3AOpenOptions%3B%0A%0Alet%20file%20%3D%20OpenOptions%3A%3Anew().write(true).open(%22foo.txt%22)%3B%0A%7D">Run</a></pre>
</div><h4 id='method.append' class="method"><span id='append.v' class='invisible'><code>pub fn <a href='#method.append' class='fnname'>append</a>(&amp;mut self, append: <a class="primitive" href="../primitive.bool.html">bool</a>) -&gt; &amp;mut <a class="struct" href="../../std/fs/struct.OpenOptions.html" title="struct std::fs::OpenOptions">OpenOptions</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/std/fs.rs.html#733-735' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>Sets the option for the append mode.</p>
<p>This option, when true, means that writes will append to a file instead
of overwriting previous contents.
Note that setting <code>.write(true).append(true)</code> has the same effect as
setting only <code>.append(true)</code>.</p>
<p>For most filesystems, the operating system guarantees that all writes are
atomic: no writes get mangled because another process writes at the same
time.</p>
<p>One maybe obvious note when using append-mode: make sure that all data
that belongs together is written to the file in one operation. This
can be done by concatenating strings before passing them to <a href="../../std/fs/struct.File.html#method.write"><code>write()</code></a>,
or using a buffered writer (with a buffer of adequate size),
and calling <a href="../../std/fs/struct.File.html#method.flush"><code>flush()</code></a> when the message is complete.</p>
<p>If a file is opened with both read and append access, beware that after
opening, and after every write, the position for reading may be set at the
end of the file. So, before writing, save the current position (using
<a href="../../std/fs/struct.File.html#method.seek"><code>seek</code></a><code>(</code><a href="../../std/io/enum.SeekFrom.html"><code>SeekFrom</code></a><code>::</code><a href="../../std/io/enum.SeekFrom.html#variant.Current"><code>Current</code></a><code>(0))</code>, and restore it before the next read.</p>
<h2 id="note" class="section-header"><a href="#note">Note</a></h2>
<p>This function doesn't create the file if it doesn't exist. Use the <a href="#method.create"><code>create</code></a>
method to do so.</p>
<h1 id="examples-4" class="section-header"><a href="#examples-4">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">OpenOptions</span>;

<span class="kw">let</span> <span class="ident">file</span> <span class="op">=</span> <span class="ident">OpenOptions</span>::<span class="ident">new</span>().<span class="ident">append</span>(<span class="bool-val">true</span>).<span class="ident">open</span>(<span class="string">&quot;foo.txt&quot;</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%3AOpenOptions%3B%0A%0Alet%20file%20%3D%20OpenOptions%3A%3Anew().append(true).open(%22foo.txt%22)%3B%0A%7D">Run</a></pre>
</div><h4 id='method.truncate' class="method"><span id='truncate.v' class='invisible'><code>pub fn <a href='#method.truncate' class='fnname'>truncate</a>(&amp;mut self, truncate: <a class="primitive" href="../primitive.bool.html">bool</a>) -&gt; &amp;mut <a class="struct" href="../../std/fs/struct.OpenOptions.html" title="struct std::fs::OpenOptions">OpenOptions</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/std/fs.rs.html#752-754' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>Sets the option for truncating a previous file.</p>
<p>If a file is successfully opened with this option set it will truncate
the file to 0 length if it already exists.</p>
<p>The file must be opened with write access for truncate to work.</p>
<h1 id="examples-5" class="section-header"><a href="#examples-5">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">OpenOptions</span>;

<span class="kw">let</span> <span class="ident">file</span> <span class="op">=</span> <span class="ident">OpenOptions</span>::<span class="ident">new</span>().<span class="ident">write</span>(<span class="bool-val">true</span>).<span class="ident">truncate</span>(<span class="bool-val">true</span>).<span class="ident">open</span>(<span class="string">&quot;foo.txt&quot;</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%3AOpenOptions%3B%0A%0Alet%20file%20%3D%20OpenOptions%3A%3Anew().write(true).truncate(true).open(%22foo.txt%22)%3B%0A%7D">Run</a></pre>
</div><h4 id='method.create' class="method"><span id='create.v' class='invisible'><code>pub fn <a href='#method.create' class='fnname'>create</a>(&amp;mut self, create: <a class="primitive" href="../primitive.bool.html">bool</a>) -&gt; &amp;mut <a class="struct" href="../../std/fs/struct.OpenOptions.html" title="struct std::fs::OpenOptions">OpenOptions</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/std/fs.rs.html#775-777' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>Sets the option for creating a new file.</p>
<p>This option indicates whether a new file will be created if the file
does not yet already exist.</p>
<p>In order for the file to be created, <a href="#method.write"><code>write</code></a> or <a href="#method.append"><code>append</code></a> access must
be used.</p>
<h1 id="examples-6" class="section-header"><a href="#examples-6">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">OpenOptions</span>;

<span class="kw">let</span> <span class="ident">file</span> <span class="op">=</span> <span class="ident">OpenOptions</span>::<span class="ident">new</span>().<span class="ident">write</span>(<span class="bool-val">true</span>).<span class="ident">create</span>(<span class="bool-val">true</span>).<span class="ident">open</span>(<span class="string">&quot;foo.txt&quot;</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%3AOpenOptions%3B%0A%0Alet%20file%20%3D%20OpenOptions%3A%3Anew().write(true).create(true).open(%22foo.txt%22)%3B%0A%7D">Run</a></pre>
</div><h4 id='method.create_new' class="method"><span id='create_new.v' class='invisible'><code>pub fn <a href='#method.create_new' class='fnname'>create_new</a>(&amp;mut self, create_new: <a class="primitive" href="../primitive.bool.html">bool</a>) -&gt; &amp;mut <a class="struct" href="../../std/fs/struct.OpenOptions.html" title="struct std::fs::OpenOptions">OpenOptions</a></code></span><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.9.0'>1.9.0</div><a class='srclink' href='../../src/std/fs.rs.html#808-810' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>Sets the option to always create a new file.</p>
<p>This option indicates whether a new file will be created.
No file is allowed to exist at the target location, also no (dangling)
symlink.</p>
<p>This option is useful because it is atomic. Otherwise between checking
whether a file exists and creating a new one, the file may have been
created by another process (a TOCTOU race condition / attack).</p>
<p>If <code>.create_new(true)</code> is set, <a href="#method.create"><code>.create()</code></a> and <a href="#method.truncate"><code>.truncate()</code></a> are
ignored.</p>
<p>The file must be opened with write or append access in order to create
a new file.</p>
<h1 id="examples-7" class="section-header"><a href="#examples-7">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">OpenOptions</span>;

<span class="kw">let</span> <span class="ident">file</span> <span class="op">=</span> <span class="ident">OpenOptions</span>::<span class="ident">new</span>().<span class="ident">write</span>(<span class="bool-val">true</span>)
                             .<span class="ident">create_new</span>(<span class="bool-val">true</span>)
                             .<span class="ident">open</span>(<span class="string">&quot;foo.txt&quot;</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%3AOpenOptions%3B%0A%0Alet%20file%20%3D%20OpenOptions%3A%3Anew().write(true)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20.create_new(true)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20.open(%22foo.txt%22)%3B%0A%7D">Run</a></pre>
</div><h4 id='method.open' class="method"><span id='open.v' class='invisible'><code>pub fn <a href='#method.open' class='fnname'>open</a>&lt;P:&nbsp;<a class="trait" href="../../std/convert/trait.AsRef.html" title="trait std::convert::AsRef">AsRef</a>&lt;<a class="struct" href="../../std/path/struct.Path.html" title="struct std::path::Path">Path</a>&gt;&gt;(&amp;self, path: P) -&gt; <a class="type" href="../../std/io/type.Result.html" title="type std::io::Result">Result</a>&lt;<a class="struct" href="../../std/fs/struct.File.html" title="struct std::fs::File">File</a>&gt;</code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/std/fs.rs.html#856-858' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>Opens a file at <code>path</code> with the options specified by <code>self</code>.</p>
<h1 id="errors" class="section-header"><a href="#errors">Errors</a></h1>
<p>This function will return an error under a number of different
circumstances. Some of these error conditions are listed here, together
with their <a href="../io/enum.ErrorKind.html"><code>ErrorKind</code></a>. The mapping to <a href="../io/enum.ErrorKind.html"><code>ErrorKind</code></a>s is not part of
the compatibility contract of the function, especially the <code>Other</code> kind
might change to more specific kinds in the future.</p>
<ul>
<li><a href="../io/enum.ErrorKind.html#variant.NotFound"><code>NotFound</code></a>: The specified file does not exist and neither <code>create</code>
or <code>create_new</code> is set.</li>
<li><a href="../io/enum.ErrorKind.html#variant.NotFound"><code>NotFound</code></a>: One of the directory components of the file path does
not exist.</li>
<li><a href="../io/enum.ErrorKind.html#variant.PermissionDenied"><code>PermissionDenied</code></a>: The user lacks permission to get the specified
access rights for the file.</li>
<li><a href="../io/enum.ErrorKind.html#variant.PermissionDenied"><code>PermissionDenied</code></a>: The user lacks permission to open one of the
directory components of the specified path.</li>
<li><a href="../io/enum.ErrorKind.html#variant.AlreadyExists"><code>AlreadyExists</code></a>: <code>create_new</code> was specified and the file already
exists.</li>
<li><a href="../io/enum.ErrorKind.html#variant.InvalidInput"><code>InvalidInput</code></a>: Invalid combinations of open options (truncate
without write access, no access mode set, etc.).</li>
<li><a href="../io/enum.ErrorKind.html#variant.Other"><code>Other</code></a>: One of the directory components of the specified file path
was not, in fact, a directory.</li>
<li><a href="../io/enum.ErrorKind.html#variant.Other"><code>Other</code></a>: Filesystem-level errors: full disk, write permission
requested on a read-only file system, exceeded disk quota, too many
open files, too long filename, too many symbolic links in the
specified path (Unix-like systems only), etc.</li>
</ul>
<h1 id="examples-8" class="section-header"><a href="#examples-8">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">OpenOptions</span>;

<span class="kw">let</span> <span class="ident">file</span> <span class="op">=</span> <span class="ident">OpenOptions</span>::<span class="ident">new</span>().<span class="ident">open</span>(<span class="string">&quot;foo.txt&quot;</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%3AOpenOptions%3B%0A%0Alet%20file%20%3D%20OpenOptions%3A%3Anew().open(%22foo.txt%22)%3B%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-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.OpenOptions.html" title="struct std::fs::OpenOptions">OpenOptions</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#180' 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>(&amp;self) -&gt; <a class="struct" href="../../std/fs/struct.OpenOptions.html" title="struct std::fs::OpenOptions">OpenOptions</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/std/fs.rs.html#180' 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>(&amp;mut self, source: <a class="primitive" href="../primitive.reference.html">&amp;</a>Self)</code></span><span class='out-of-band'><div class='ghost'></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-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.OpenOptions.html" title="struct std::fs::OpenOptions">OpenOptions</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#180' 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>(&amp;self, __arg_0: &amp;mut <a class="struct" href="../../std/fmt/struct.Formatter.html" title="struct std::fmt::Formatter">Formatter</a>) -&gt; <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#180' 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-OpenOptionsExt' class='impl'><span class='in-band'><code>impl <a class="trait" href="../../std/os/unix/fs/trait.OpenOptionsExt.html" title="trait std::os::unix::fs::OpenOptionsExt">OpenOptionsExt</a> for <a class="struct" href="../../std/fs/struct.OpenOptions.html" title="struct std::fs::OpenOptions">OpenOptions</a></code><a href='#impl-OpenOptionsExt' class='anchor'></a></span><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.1.0'>1.1.0</div><a class='srclink' href='../../src/std/sys/unix/ext/fs.rs.html#239-247' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.mode' class="method"><span id='mode.v' class='invisible'><code>fn <a href='../../std/os/unix/fs/trait.OpenOptionsExt.html#tymethod.mode' class='fnname'>mode</a>(&amp;mut self, mode: <a class="primitive" href="../primitive.u32.html">u32</a>) -&gt; &amp;mut <a class="struct" href="../../std/fs/struct.OpenOptions.html" title="struct std::fs::OpenOptions">OpenOptions</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/std/sys/unix/ext/fs.rs.html#240-242' 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>Sets the mode bits that a new file will be created with. <a href="../../std/os/unix/fs/trait.OpenOptionsExt.html#tymethod.mode">Read more</a></p>
</div><h4 id='method.custom_flags' class="method"><span id='custom_flags.v' class='invisible'><code>fn <a href='../../std/os/unix/fs/trait.OpenOptionsExt.html#tymethod.custom_flags' class='fnname'>custom_flags</a>(&amp;mut self, flags: <a class="primitive" href="../primitive.i32.html">i32</a>) -&gt; &amp;mut <a class="struct" href="../../std/fs/struct.OpenOptions.html" title="struct std::fs::OpenOptions">OpenOptions</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/std/sys/unix/ext/fs.rs.html#244-246' 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>Pass custom flags to the <code>flags</code> argument of <code>open</code>. <a href="../../std/os/unix/fs/trait.OpenOptionsExt.html#tymethod.custom_flags">Read more</a></p>
</div></div><h3 id='impl-OpenOptionsExt-1' class='impl'><span class='in-band'><code>impl <a class="trait" href="../../std/os/windows/fs/trait.OpenOptionsExt.html" title="trait std::os::windows::fs::OpenOptionsExt">OpenOptionsExt</a> for <a class="struct" href="../../std/fs/struct.OpenOptions.html" title="struct std::fs::OpenOptions">OpenOptions</a></code><a href='#impl-OpenOptionsExt-1' class='anchor'></a></span><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.10.0'>1.10.0</div><a class='srclink' href='../../src/std/sys/windows/ext/fs.rs.html#262-282' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.access_mode' class="method"><span id='access_mode.v' class='invisible'><code>fn <a href='../../std/os/windows/fs/trait.OpenOptionsExt.html#tymethod.access_mode' class='fnname'>access_mode</a>(&amp;mut self, access: <a class="primitive" href="../primitive.u32.html">u32</a>) -&gt; &amp;mut <a class="struct" href="../../std/fs/struct.OpenOptions.html" title="struct std::fs::OpenOptions">OpenOptions</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/std/sys/windows/ext/fs.rs.html#263-265' title='goto source code'>[src]</a></span></h4>
<div class='stability'><div class='stab portability'>This is supported on <strong>Windows</strong> only.</div></div><div class='docblock'><p>Overrides the <code>dwDesiredAccess</code> argument to the call to [<code>CreateFile</code>] with the specified value. <a href="../../std/os/windows/fs/trait.OpenOptionsExt.html#tymethod.access_mode">Read more</a></p>
</div><h4 id='method.share_mode' class="method"><span id='share_mode.v' class='invisible'><code>fn <a href='../../std/os/windows/fs/trait.OpenOptionsExt.html#tymethod.share_mode' class='fnname'>share_mode</a>(&amp;mut self, share: <a class="primitive" href="../primitive.u32.html">u32</a>) -&gt; &amp;mut <a class="struct" href="../../std/fs/struct.OpenOptions.html" title="struct std::fs::OpenOptions">OpenOptions</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/std/sys/windows/ext/fs.rs.html#267-269' title='goto source code'>[src]</a></span></h4>
<div class='stability'><div class='stab portability'>This is supported on <strong>Windows</strong> only.</div></div><div class='docblock'><p>Overrides the <code>dwShareMode</code> argument to the call to [<code>CreateFile</code>] with the specified value. <a href="../../std/os/windows/fs/trait.OpenOptionsExt.html#tymethod.share_mode">Read more</a></p>
</div><h4 id='method.custom_flags-1' class="method"><span id='custom_flags.v-1' class='invisible'><code>fn <a href='../../std/os/windows/fs/trait.OpenOptionsExt.html#tymethod.custom_flags' class='fnname'>custom_flags</a>(&amp;mut self, flags: <a class="primitive" href="../primitive.u32.html">u32</a>) -&gt; &amp;mut <a class="struct" href="../../std/fs/struct.OpenOptions.html" title="struct std::fs::OpenOptions">OpenOptions</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/std/sys/windows/ext/fs.rs.html#271-273' title='goto source code'>[src]</a></span></h4>
<div class='stability'><div class='stab portability'>This is supported on <strong>Windows</strong> only.</div></div><div class='docblock'><p>Sets extra flags for the <code>dwFileFlags</code> argument to the call to [<code>CreateFile2</code>] to the specified value (or combines it with <code>attributes</code> and <code>security_qos_flags</code> to set the <code>dwFlagsAndAttributes</code> for [<code>CreateFile</code>]). <a href="../../std/os/windows/fs/trait.OpenOptionsExt.html#tymethod.custom_flags">Read more</a></p>
</div><h4 id='method.attributes' class="method"><span id='attributes.v' class='invisible'><code>fn <a href='../../std/os/windows/fs/trait.OpenOptionsExt.html#tymethod.attributes' class='fnname'>attributes</a>(&amp;mut self, attributes: <a class="primitive" href="../primitive.u32.html">u32</a>) -&gt; &amp;mut <a class="struct" href="../../std/fs/struct.OpenOptions.html" title="struct std::fs::OpenOptions">OpenOptions</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/std/sys/windows/ext/fs.rs.html#275-277' title='goto source code'>[src]</a></span></h4>
<div class='stability'><div class='stab portability'>This is supported on <strong>Windows</strong> only.</div></div><div class='docblock'><p>Sets the <code>dwFileAttributes</code> argument to the call to [<code>CreateFile2</code>] to the specified value (or combines it with <code>custom_flags</code> and <code>security_qos_flags</code> to set the <code>dwFlagsAndAttributes</code> for [<code>CreateFile</code>]). <a href="../../std/os/windows/fs/trait.OpenOptionsExt.html#tymethod.attributes">Read more</a></p>
</div><h4 id='method.security_qos_flags' class="method"><span id='security_qos_flags.v' class='invisible'><code>fn <a href='../../std/os/windows/fs/trait.OpenOptionsExt.html#tymethod.security_qos_flags' class='fnname'>security_qos_flags</a>(&amp;mut self, flags: <a class="primitive" href="../primitive.u32.html">u32</a>) -&gt; &amp;mut <a class="struct" href="../../std/fs/struct.OpenOptions.html" title="struct std::fs::OpenOptions">OpenOptions</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/std/sys/windows/ext/fs.rs.html#279-281' title='goto source code'>[src]</a></span></h4>
<div class='stability'><div class='stab portability'>This is supported on <strong>Windows</strong> only.</div></div><div class='docblock'><p>Sets the <code>dwSecurityQosFlags</code> argument to the call to [<code>CreateFile2</code>] to the specified value (or combines it with <code>custom_flags</code> and <code>attributes</code> to set the <code>dwFlagsAndAttributes</code> for [<code>CreateFile</code>]). <a href="../../std/os/windows/fs/trait.OpenOptionsExt.html#tymethod.security_qos_flags">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>&#9166;</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>