270 lines
57 KiB
HTML
270 lines
57 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="Options and flags which can be used to configure how a file is opened."><title>OpenOptions in tokio::fs - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Italic-81dc35de.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-MediumItalic-ccf7e434.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2"href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../static.files/rustdoc-ca0dd0c4.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="tokio" data-themes="" data-resource-suffix="" data-rustdoc-version="1.93.1 (01f6ddf75 2026-02-11) (Arch Linux rust 1:1.93.1-1)" data-channel="1.93.1" data-search-js="search-9e2438ea.js" data-stringdex-js="stringdex-a3946164.js" data-settings-js="settings-c38705f0.js" ><script src="../../static.files/storage-e2aeef58.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../static.files/main-a410ff4d.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-263c88ec.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-eab170b8.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-044be391.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]--><rustdoc-topbar><h2><a href="#">OpenOptions</a></h2></rustdoc-topbar><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../tokio/index.html">tokio</a><span class="version">1.49.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Open<wbr>Options</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#examples" title="Examples">Examples</a></li></ul><h3><a href="#implementations">Methods</a></h3><ul class="block method"><li><a href="#method.append" title="append">append</a></li><li><a href="#method.create" title="create">create</a></li><li><a href="#method.create_new" title="create_new">create_new</a></li><li><a href="#method.custom_flags" title="custom_flags">custom_flags</a></li><li><a href="#method.mode" title="mode">mode</a></li><li><a href="#method.new" title="new">new</a></li><li><a href="#method.open" title="open">open</a></li><li><a href="#method.read" title="read">read</a></li><li><a href="#method.truncate" title="truncate">truncate</a></li><li><a href="#method.write" title="write">write</a></li></ul><h3><a href="#trait-implementations">Trait Implementations</a></h3><ul class="block trait-implementation"><li><a href="#impl-Clone-for-OpenOptions" title="Clone">Clone</a></li><li><a href="#impl-Debug-for-OpenOptions" title="Debug">Debug</a></li><li><a href="#impl-Default-for-OpenOptions" title="Default">Default</a></li><li><a href="#impl-From%3COpenOptions%3E-for-OpenOptions" title="From<OpenOptions>">From<OpenOptions></a></li></ul><h3><a href="#synthetic-implementations">Auto Trait Implementations</a></h3><ul class="block synthetic-implementation"><li><a href="#impl-Freeze-for-OpenOptions" title="Freeze">Freeze</a></li><li><a href="#impl-RefUnwindSafe-for-OpenOptions" title="RefUnwindSafe">RefUnwindSafe</a></li><li><a href="#impl-Send-for-OpenOptions" title="Send">Send</a></li><li><a href="#impl-Sync-for-OpenOptions" title="Sync">Sync</a></li><li><a href="#impl-Unpin-for-OpenOptions" title="Unpin">Unpin</a></li><li><a href="#impl-UnwindSafe-for-OpenOptions" title="UnwindSafe">UnwindSafe</a></li></ul><h3><a href="#blanket-implementations">Blanket Implementations</a></h3><ul class="block blanket-implementation"><li><a href="#impl-Any-for-T" title="Any">Any</a></li><li><a href="#impl-Borrow%3CT%3E-for-T" title="Borrow<T>">Borrow<T></a></li><li><a href="#impl-BorrowMut%3CT%3E-for-T" title="BorrowMut<T>">BorrowMut<T></a></li><li><a href="#impl-CloneToUninit-for-T" title="CloneToUninit">CloneToUninit</a></li><li><a href="#impl-From%3CT%3E-for-T" title="From<T>">From<T></a></li><li><a href="#impl-Into%3CU%3E-for-T" title="Into<U>">Into<U></a></li><li><a href="#impl-ToOwned-for-T" title="ToOwned">ToOwned</a></li><li><a href="#impl-TryFrom%3CU%3E-for-T" title="TryFrom<U>">TryFrom<U></a></li><li><a href="#impl-TryInto%3CU%3E-for-T" title="TryInto<U>">TryInto<U></a></li></ul></section><div id="rustdoc-modnav"><h2><a href="index.html">In tokio::<wbr>fs</a></h2></div></div></nav><div class="sidebar-resizer" title="Drag to resize sidebar"></div><main><div class="width-limiter"><section id="main-content" class="content"><div class="main-heading"><div class="rustdoc-breadcrumbs"><a href="../index.html">tokio</a>::<wbr><a href="index.html">fs</a></div><h1>Struct <span class="struct">Open<wbr>Options</span> <button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../src/tokio/fs/open_options.rs.html#88-90">Source</a> </span></div><pre class="rust item-decl"><code>pub struct OpenOptions { <span class="comment">/* private fields */</span> }</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><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" title="struct tokio::fs::File"><code>File</code></a> is opened and
|
||
what operations are permitted on the open file. The <a href="struct.File.html#method.open" title="associated function tokio::fs::File::open"><code>File::open</code></a> and
|
||
<a href="struct.File.html#method.create" title="associated function tokio::fs::File::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" title="associated function tokio::fs::OpenOptions::new"><code>new</code></a>,
|
||
then chain calls to methods to set each option, then call <a href="struct.OpenOptions.html#method.open" title="method tokio::fs::OpenOptions::open"><code>open</code></a>, passing
|
||
the path of the file you’re trying to open. This will give you a
|
||
<a href="https://doc.rust-lang.org/1.93.1/std/io/error/type.Result.html" title="type std::io::error::Result"><code>io::Result</code></a> with a <a href="struct.File.html" title="struct tokio::fs::File"><code>File</code></a> inside that you can further operate
|
||
on.</p>
|
||
<p>This is a specialized version of <a href="https://doc.rust-lang.org/1.93.1/std/fs/struct.OpenOptions.html" title="struct std::fs::OpenOptions"><code>std::fs::OpenOptions</code></a> for usage from
|
||
the Tokio runtime.</p>
|
||
<p><code>From<std::fs::OpenOptions></code> is implemented for more advanced configuration
|
||
than the methods provided here.</p>
|
||
<h2 id="examples"><a class="doc-anchor" href="#examples">§</a>Examples</h2>
|
||
<p>Opening a file to read:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::fs::OpenOptions;
|
||
<span class="kw">use </span>std::io;
|
||
|
||
<span class="attr">#[tokio::main]
|
||
</span><span class="kw">async fn </span>main() -> io::Result<()> {
|
||
<span class="kw">let </span>file = OpenOptions::new()
|
||
.read(<span class="bool-val">true</span>)
|
||
.open(<span class="string">"foo.txt"</span>)
|
||
.<span class="kw">await</span><span class="question-mark">?</span>;
|
||
|
||
<span class="prelude-val">Ok</span>(())
|
||
}</code></pre></div>
|
||
<p>Opening a file for both reading and writing, as well as creating it if it
|
||
doesn’t exist:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::fs::OpenOptions;
|
||
<span class="kw">use </span>std::io;
|
||
|
||
<span class="attr">#[tokio::main]
|
||
</span><span class="kw">async fn </span>main() -> io::Result<()> {
|
||
<span class="kw">let </span>file = OpenOptions::new()
|
||
.read(<span class="bool-val">true</span>)
|
||
.write(<span class="bool-val">true</span>)
|
||
.create(<span class="bool-val">true</span>)
|
||
.open(<span class="string">"foo.txt"</span>)
|
||
.<span class="kw">await</span><span class="question-mark">?</span>;
|
||
|
||
<span class="prelude-val">Ok</span>(())
|
||
}</code></pre></div></div></details><h2 id="implementations" class="section-header">Implementations<a href="#implementations" class="anchor">§</a></h2><div id="implementations-list"><details class="toggle implementors-toggle" open><summary><section id="impl-OpenOptions" class="impl"><a class="src rightside" href="../../src/tokio/fs/open_options.rs.html#105-558">Source</a><a href="#impl-OpenOptions" class="anchor">§</a><h3 class="code-header">impl <a class="struct" href="struct.OpenOptions.html" title="struct tokio::fs::OpenOptions">OpenOptions</a></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.new" class="method"><a class="src rightside" href="../../src/tokio/fs/open_options.rs.html#122-141">Source</a><h4 class="code-header">pub fn <a href="#method.new" class="fn">new</a>() -> <a class="struct" href="struct.OpenOptions.html" title="struct tokio::fs::OpenOptions">OpenOptions</a></h4></section></summary><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>
|
||
<p>This is an async version of <a href="https://doc.rust-lang.org/1.93.1/std/fs/struct.OpenOptions.html#method.new" title="associated function std::fs::OpenOptions::new"><code>std::fs::OpenOptions::new</code></a></p>
|
||
<h5 id="examples-1"><a class="doc-anchor" href="#examples-1">§</a>Examples</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::fs::OpenOptions;
|
||
|
||
<span class="kw">let </span><span class="kw-2">mut </span>options = OpenOptions::new();
|
||
<span class="kw">let </span>future = options.read(<span class="bool-val">true</span>).open(<span class="string">"foo.txt"</span>);</code></pre></div></div></details><details class="toggle method-toggle" open><summary><section id="method.read" class="method"><a class="src rightside" href="../../src/tokio/fs/open_options.rs.html#168-185">Source</a><h4 class="code-header">pub fn <a href="#method.read" class="fn">read</a>(&mut self, read: <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.bool.html">bool</a>) -> &mut <a class="struct" href="struct.OpenOptions.html" title="struct tokio::fs::OpenOptions">OpenOptions</a></h4></section></summary><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>
|
||
<p>This is an async version of <a href="https://doc.rust-lang.org/1.93.1/std/fs/struct.OpenOptions.html#method.read" title="method std::fs::OpenOptions::read"><code>std::fs::OpenOptions::read</code></a></p>
|
||
<h5 id="examples-2"><a class="doc-anchor" href="#examples-2">§</a>Examples</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::fs::OpenOptions;
|
||
<span class="kw">use </span>std::io;
|
||
|
||
<span class="attr">#[tokio::main]
|
||
</span><span class="kw">async fn </span>main() -> io::Result<()> {
|
||
<span class="kw">let </span>file = OpenOptions::new()
|
||
.read(<span class="bool-val">true</span>)
|
||
.open(<span class="string">"foo.txt"</span>)
|
||
.<span class="kw">await</span><span class="question-mark">?</span>;
|
||
|
||
<span class="prelude-val">Ok</span>(())
|
||
}</code></pre></div></div></details><details class="toggle method-toggle" open><summary><section id="method.write" class="method"><a class="src rightside" href="../../src/tokio/fs/open_options.rs.html#212-229">Source</a><h4 class="code-header">pub fn <a href="#method.write" class="fn">write</a>(&mut self, write: <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.bool.html">bool</a>) -> &mut <a class="struct" href="struct.OpenOptions.html" title="struct tokio::fs::OpenOptions">OpenOptions</a></h4></section></summary><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>This is an async version of <a href="https://doc.rust-lang.org/1.93.1/std/fs/struct.OpenOptions.html#method.write" title="method std::fs::OpenOptions::write"><code>std::fs::OpenOptions::write</code></a></p>
|
||
<h5 id="examples-3"><a class="doc-anchor" href="#examples-3">§</a>Examples</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::fs::OpenOptions;
|
||
<span class="kw">use </span>std::io;
|
||
|
||
<span class="attr">#[tokio::main]
|
||
</span><span class="kw">async fn </span>main() -> io::Result<()> {
|
||
<span class="kw">let </span>file = OpenOptions::new()
|
||
.write(<span class="bool-val">true</span>)
|
||
.open(<span class="string">"foo.txt"</span>)
|
||
.<span class="kw">await</span><span class="question-mark">?</span>;
|
||
|
||
<span class="prelude-val">Ok</span>(())
|
||
}</code></pre></div></div></details><details class="toggle method-toggle" open><summary><section id="method.append" class="method"><a class="src rightside" href="../../src/tokio/fs/open_options.rs.html#285-302">Source</a><h4 class="code-header">pub fn <a href="#method.append" class="fn">append</a>(&mut self, append: <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.bool.html">bool</a>) -> &mut <a class="struct" href="struct.OpenOptions.html" title="struct tokio::fs::OpenOptions">OpenOptions</a></h4></section></summary><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="../io/trait.AsyncWriteExt.html#method.write" title="method tokio::io::AsyncWriteExt::write"><code>write()</code></a>,
|
||
or using a buffered writer (with a buffer of adequate size),
|
||
and calling <a href="../io/trait.AsyncWriteExt.html#method.flush" title="method tokio::io::AsyncWriteExt::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="../io/trait.AsyncSeekExt.html#method.seek" title="method tokio::io::AsyncSeekExt::seek"><code>seek</code></a><code>(</code><a href="https://doc.rust-lang.org/1.93.1/std/io/enum.SeekFrom.html" title="enum std::io::SeekFrom"><code>SeekFrom</code></a><code>::</code><a href="https://doc.rust-lang.org/1.93.1/std/io/enum.SeekFrom.html#variant.Current" title="variant std::io::SeekFrom::Current"><code>Current</code></a><code>(0))</code>), and restore it before the next read.</p>
|
||
<p>This is an async version of <a href="https://doc.rust-lang.org/1.93.1/std/fs/struct.OpenOptions.html#method.append" title="method std::fs::OpenOptions::append"><code>std::fs::OpenOptions::append</code></a></p>
|
||
<h6 id="note"><a class="doc-anchor" href="#note">§</a>Note</h6>
|
||
<p>This function doesn’t create the file if it doesn’t exist. Use the <a href="struct.OpenOptions.html#method.create" title="method tokio::fs::OpenOptions::create"><code>create</code></a>
|
||
method to do so.</p>
|
||
<h5 id="examples-4"><a class="doc-anchor" href="#examples-4">§</a>Examples</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::fs::OpenOptions;
|
||
<span class="kw">use </span>std::io;
|
||
|
||
<span class="attr">#[tokio::main]
|
||
</span><span class="kw">async fn </span>main() -> io::Result<()> {
|
||
<span class="kw">let </span>file = OpenOptions::new()
|
||
.append(<span class="bool-val">true</span>)
|
||
.open(<span class="string">"foo.txt"</span>)
|
||
.<span class="kw">await</span><span class="question-mark">?</span>;
|
||
|
||
<span class="prelude-val">Ok</span>(())
|
||
}</code></pre></div></div></details><details class="toggle method-toggle" open><summary><section id="method.truncate" class="method"><a class="src rightside" href="../../src/tokio/fs/open_options.rs.html#332-349">Source</a><h4 class="code-header">pub fn <a href="#method.truncate" class="fn">truncate</a>(&mut self, truncate: <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.bool.html">bool</a>) -> &mut <a class="struct" href="struct.OpenOptions.html" title="struct tokio::fs::OpenOptions">OpenOptions</a></h4></section></summary><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>
|
||
<p>This is an async version of <a href="https://doc.rust-lang.org/1.93.1/std/fs/struct.OpenOptions.html#method.truncate" title="method std::fs::OpenOptions::truncate"><code>std::fs::OpenOptions::truncate</code></a></p>
|
||
<h5 id="examples-5"><a class="doc-anchor" href="#examples-5">§</a>Examples</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::fs::OpenOptions;
|
||
<span class="kw">use </span>std::io;
|
||
|
||
<span class="attr">#[tokio::main]
|
||
</span><span class="kw">async fn </span>main() -> io::Result<()> {
|
||
<span class="kw">let </span>file = OpenOptions::new()
|
||
.write(<span class="bool-val">true</span>)
|
||
.truncate(<span class="bool-val">true</span>)
|
||
.open(<span class="string">"foo.txt"</span>)
|
||
.<span class="kw">await</span><span class="question-mark">?</span>;
|
||
|
||
<span class="prelude-val">Ok</span>(())
|
||
}</code></pre></div></div></details><details class="toggle method-toggle" open><summary><section id="method.create" class="method"><a class="src rightside" href="../../src/tokio/fs/open_options.rs.html#382-399">Source</a><h4 class="code-header">pub fn <a href="#method.create" class="fn">create</a>(&mut self, create: <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.bool.html">bool</a>) -> &mut <a class="struct" href="struct.OpenOptions.html" title="struct tokio::fs::OpenOptions">OpenOptions</a></h4></section></summary><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="struct.OpenOptions.html#method.write" title="method tokio::fs::OpenOptions::write"><code>write</code></a> or <a href="struct.OpenOptions.html#method.append" title="method tokio::fs::OpenOptions::append"><code>append</code></a> access must
|
||
be used.</p>
|
||
<p>This is an async version of <a href="https://doc.rust-lang.org/1.93.1/std/fs/struct.OpenOptions.html#method.create" title="method std::fs::OpenOptions::create"><code>std::fs::OpenOptions::create</code></a></p>
|
||
<h5 id="examples-6"><a class="doc-anchor" href="#examples-6">§</a>Examples</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::fs::OpenOptions;
|
||
<span class="kw">use </span>std::io;
|
||
|
||
<span class="attr">#[tokio::main]
|
||
</span><span class="kw">async fn </span>main() -> io::Result<()> {
|
||
<span class="kw">let </span>file = OpenOptions::new()
|
||
.write(<span class="bool-val">true</span>)
|
||
.create(<span class="bool-val">true</span>)
|
||
.open(<span class="string">"foo.txt"</span>)
|
||
.<span class="kw">await</span><span class="question-mark">?</span>;
|
||
|
||
<span class="prelude-val">Ok</span>(())
|
||
}</code></pre></div></div></details><details class="toggle method-toggle" open><summary><section id="method.create_new" class="method"><a class="src rightside" href="../../src/tokio/fs/open_options.rs.html#439-456">Source</a><h4 class="code-header">pub fn <a href="#method.create_new" class="fn">create_new</a>(&mut self, create_new: <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.bool.html">bool</a>) -> &mut <a class="struct" href="struct.OpenOptions.html" title="struct tokio::fs::OpenOptions">OpenOptions</a></h4></section></summary><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="struct.OpenOptions.html#method.create" title="method tokio::fs::OpenOptions::create"><code>.create()</code></a> and <a href="struct.OpenOptions.html#method.truncate" title="method tokio::fs::OpenOptions::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>
|
||
<p>This is an async version of <a href="https://doc.rust-lang.org/1.93.1/std/fs/struct.OpenOptions.html#method.create_new" title="method std::fs::OpenOptions::create_new"><code>std::fs::OpenOptions::create_new</code></a></p>
|
||
<h5 id="examples-7"><a class="doc-anchor" href="#examples-7">§</a>Examples</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::fs::OpenOptions;
|
||
<span class="kw">use </span>std::io;
|
||
|
||
<span class="attr">#[tokio::main]
|
||
</span><span class="kw">async fn </span>main() -> io::Result<()> {
|
||
<span class="kw">let </span>file = OpenOptions::new()
|
||
.write(<span class="bool-val">true</span>)
|
||
.create_new(<span class="bool-val">true</span>)
|
||
.open(<span class="string">"foo.txt"</span>)
|
||
.<span class="kw">await</span><span class="question-mark">?</span>;
|
||
|
||
<span class="prelude-val">Ok</span>(())
|
||
}</code></pre></div></div></details><details class="toggle method-toggle" open><summary><section id="method.open" class="method"><a class="src rightside" href="../../src/tokio/fs/open_options.rs.html#520-542">Source</a><h4 class="code-header">pub async fn <a href="#method.open" class="fn">open</a>(&self, path: impl <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a><<a class="struct" href="https://doc.rust-lang.org/1.93.1/std/path/struct.Path.html" title="struct std::path::Path">Path</a>>) -> <a class="type" href="https://doc.rust-lang.org/1.93.1/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a><<a class="struct" href="struct.File.html" title="struct tokio::fs::File">File</a>></h4></section></summary><div class="docblock"><p>Opens a file at <code>path</code> with the options specified by <code>self</code>.</p>
|
||
<p>This is an async version of <a href="https://doc.rust-lang.org/1.93.1/std/fs/struct.OpenOptions.html#method.open" title="method std::fs::OpenOptions::open"><code>std::fs::OpenOptions::open</code></a></p>
|
||
<h5 id="errors"><a class="doc-anchor" href="#errors">§</a>Errors</h5>
|
||
<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="https://doc.rust-lang.org/1.93.1/std/io/error/enum.ErrorKind.html" title="enum std::io::error::ErrorKind"><code>ErrorKind</code></a>. The mapping to <a href="https://doc.rust-lang.org/1.93.1/std/io/error/enum.ErrorKind.html" title="enum std::io::error::ErrorKind"><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="https://doc.rust-lang.org/1.93.1/std/io/error/enum.ErrorKind.html#variant.NotFound" title="variant std::io::error::ErrorKind::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="https://doc.rust-lang.org/1.93.1/std/io/error/enum.ErrorKind.html#variant.NotFound" title="variant std::io::error::ErrorKind::NotFound"><code>NotFound</code></a>: One of the directory components of the file path does
|
||
not exist.</li>
|
||
<li><a href="https://doc.rust-lang.org/1.93.1/std/io/error/enum.ErrorKind.html#variant.PermissionDenied" title="variant std::io::error::ErrorKind::PermissionDenied"><code>PermissionDenied</code></a>: The user lacks permission to get the specified
|
||
access rights for the file.</li>
|
||
<li><a href="https://doc.rust-lang.org/1.93.1/std/io/error/enum.ErrorKind.html#variant.PermissionDenied" title="variant std::io::error::ErrorKind::PermissionDenied"><code>PermissionDenied</code></a>: The user lacks permission to open one of the
|
||
directory components of the specified path.</li>
|
||
<li><a href="https://doc.rust-lang.org/1.93.1/std/io/error/enum.ErrorKind.html#variant.AlreadyExists" title="variant std::io::error::ErrorKind::AlreadyExists"><code>AlreadyExists</code></a>: <code>create_new</code> was specified and the file already
|
||
exists.</li>
|
||
<li><a href="https://doc.rust-lang.org/1.93.1/std/io/error/enum.ErrorKind.html#variant.InvalidInput" title="variant std::io::error::ErrorKind::InvalidInput"><code>InvalidInput</code></a>: Invalid combinations of open options (truncate
|
||
without write access, no access mode set, etc.).</li>
|
||
<li><a href="https://doc.rust-lang.org/1.93.1/std/io/error/enum.ErrorKind.html#variant.Other" title="variant std::io::error::ErrorKind::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="https://doc.rust-lang.org/1.93.1/std/io/error/enum.ErrorKind.html#variant.Other" title="variant std::io::error::ErrorKind::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>
|
||
<h5 id="io_uring-support"><a class="doc-anchor" href="#io_uring-support">§</a>io_uring support</h5>
|
||
<p>On Linux, you can also use <code>io_uring</code> for executing system calls.
|
||
To enable <code>io_uring</code>, you need to specify the <code>--cfg tokio_unstable</code>
|
||
flag at compile time, enable the <code>io-uring</code> cargo feature, and set the
|
||
<code>Builder::enable_io_uring</code> runtime option.</p>
|
||
<p>Support for <code>io_uring</code> is currently experimental, so its behavior may
|
||
change or it may be removed in future versions.</p>
|
||
<h5 id="examples-8"><a class="doc-anchor" href="#examples-8">§</a>Examples</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::fs::OpenOptions;
|
||
<span class="kw">use </span>std::io;
|
||
|
||
<span class="attr">#[tokio::main]
|
||
</span><span class="kw">async fn </span>main() -> io::Result<()> {
|
||
<span class="kw">let </span>file = OpenOptions::new().open(<span class="string">"foo.txt"</span>).<span class="kw">await</span><span class="question-mark">?</span>;
|
||
<span class="prelude-val">Ok</span>(())
|
||
}</code></pre></div></div></details></div></details><details class="toggle implementors-toggle" open><summary><section id="impl-OpenOptions-1" class="impl"><a class="src rightside" href="../../src/tokio/fs/open_options.rs.html#563-650">Source</a><a href="#impl-OpenOptions-1" class="anchor">§</a><h3 class="code-header">impl <a class="struct" href="struct.OpenOptions.html" title="struct tokio::fs::OpenOptions">OpenOptions</a></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.mode" class="method"><a class="src rightside" href="../../src/tokio/fs/open_options.rs.html#587-604">Source</a><h4 class="code-header">pub fn <a href="#method.mode" class="fn">mode</a>(&mut self, mode: <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.u32.html">u32</a>) -> &mut <a class="struct" href="struct.OpenOptions.html" title="struct tokio::fs::OpenOptions">OpenOptions</a></h4></section></summary><div class="docblock"><p>Sets the mode bits that a new file will be created with.</p>
|
||
<p>If a new file is created as part of an <code>OpenOptions::open</code> call then this
|
||
specified <code>mode</code> will be used as the permission bits for the new file.
|
||
If no <code>mode</code> is set, the default of <code>0o666</code> will be used.
|
||
The operating system masks out bits with the system’s <code>umask</code>, to produce
|
||
the final permissions.</p>
|
||
<h5 id="examples-9"><a class="doc-anchor" href="#examples-9">§</a>Examples</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::fs::OpenOptions;
|
||
<span class="kw">use </span>std::io;
|
||
|
||
<span class="attr">#[tokio::main]
|
||
</span><span class="kw">async fn </span>main() -> io::Result<()> {
|
||
<span class="kw">let </span><span class="kw-2">mut </span>options = OpenOptions::new();
|
||
options.mode(<span class="number">0o644</span>); <span class="comment">// Give read/write for owner and read for others.
|
||
</span><span class="kw">let </span>file = options.open(<span class="string">"foo.txt"</span>).<span class="kw">await</span><span class="question-mark">?</span>;
|
||
|
||
<span class="prelude-val">Ok</span>(())
|
||
}</code></pre></div></div></details><details class="toggle method-toggle" open><summary><section id="method.custom_flags" class="method"><a class="src rightside" href="../../src/tokio/fs/open_options.rs.html#632-649">Source</a><h4 class="code-header">pub fn <a href="#method.custom_flags" class="fn">custom_flags</a>(&mut self, flags: <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.i32.html">i32</a>) -> &mut <a class="struct" href="struct.OpenOptions.html" title="struct tokio::fs::OpenOptions">OpenOptions</a></h4></section></summary><div class="docblock"><p>Passes custom flags to the <code>flags</code> argument of <code>open</code>.</p>
|
||
<p>The bits that define the access mode are masked out with <code>O_ACCMODE</code>, to
|
||
ensure they do not interfere with the access mode set by Rusts options.</p>
|
||
<p>Custom flags can only set flags, not remove flags set by Rusts options.
|
||
This options overwrites any previously set custom flags.</p>
|
||
<h5 id="examples-10"><a class="doc-anchor" href="#examples-10">§</a>Examples</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::fs::OpenOptions;
|
||
<span class="kw">use </span>std::io;
|
||
|
||
<span class="attr">#[tokio::main]
|
||
</span><span class="kw">async fn </span>main() -> io::Result<()> {
|
||
<span class="kw">let </span><span class="kw-2">mut </span>options = OpenOptions::new();
|
||
options.write(<span class="bool-val">true</span>);
|
||
<span class="kw">if </span><span class="macro">cfg!</span>(unix) {
|
||
options.custom_flags(libc::O_NOFOLLOW);
|
||
}
|
||
<span class="kw">let </span>file = options.open(<span class="string">"foo.txt"</span>).<span class="kw">await</span><span class="question-mark">?</span>;
|
||
|
||
<span class="prelude-val">Ok</span>(())
|
||
}</code></pre></div></div></details></div></details></div><h2 id="trait-implementations" class="section-header">Trait Implementations<a href="#trait-implementations" class="anchor">§</a></h2><div id="trait-implementations-list"><details class="toggle implementors-toggle" open><summary><section id="impl-Clone-for-OpenOptions" class="impl"><a class="src rightside" href="../../src/tokio/fs/open_options.rs.html#87">Source</a><a href="#impl-Clone-for-OpenOptions" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a> for <a class="struct" href="struct.OpenOptions.html" title="struct tokio::fs::OpenOptions">OpenOptions</a></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.clone" class="method trait-impl"><a class="src rightside" href="../../src/tokio/fs/open_options.rs.html#87">Source</a><a href="#method.clone" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.93.1/core/clone/trait.Clone.html#tymethod.clone" class="fn">clone</a>(&self) -> <a class="struct" href="struct.OpenOptions.html" title="struct tokio::fs::OpenOptions">OpenOptions</a></h4></section></summary><div class='docblock'>Returns a duplicate of the value. <a href="https://doc.rust-lang.org/1.93.1/core/clone/trait.Clone.html#tymethod.clone">Read more</a></div></details><details class="toggle method-toggle" open><summary><section id="method.clone_from" class="method trait-impl"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="src" href="https://doc.rust-lang.org/1.93.1/src/core/clone.rs.html#245-247">Source</a></span><a href="#method.clone_from" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.93.1/core/clone/trait.Clone.html#method.clone_from" class="fn">clone_from</a>(&mut self, source: &Self)</h4></section></summary><div class='docblock'>Performs copy-assignment from <code>source</code>. <a href="https://doc.rust-lang.org/1.93.1/core/clone/trait.Clone.html#method.clone_from">Read more</a></div></details></div></details><details class="toggle implementors-toggle" open><summary><section id="impl-Debug-for-OpenOptions" class="impl"><a class="src rightside" href="../../src/tokio/fs/open_options.rs.html#87">Source</a><a href="#impl-Debug-for-OpenOptions" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/fmt/trait.Debug.html" title="trait core::fmt::Debug">Debug</a> for <a class="struct" href="struct.OpenOptions.html" title="struct tokio::fs::OpenOptions">OpenOptions</a></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.fmt" class="method trait-impl"><a class="src rightside" href="../../src/tokio/fs/open_options.rs.html#87">Source</a><a href="#method.fmt" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.93.1/core/fmt/trait.Debug.html#tymethod.fmt" class="fn">fmt</a>(&self, f: &mut <a class="struct" href="https://doc.rust-lang.org/1.93.1/core/fmt/struct.Formatter.html" title="struct core::fmt::Formatter">Formatter</a><'_>) -> <a class="type" href="https://doc.rust-lang.org/1.93.1/core/fmt/type.Result.html" title="type core::fmt::Result">Result</a></h4></section></summary><div class='docblock'>Formats the value using the given formatter. <a href="https://doc.rust-lang.org/1.93.1/core/fmt/trait.Debug.html#tymethod.fmt">Read more</a></div></details></div></details><details class="toggle implementors-toggle" open><summary><section id="impl-Default-for-OpenOptions" class="impl"><a class="src rightside" href="../../src/tokio/fs/open_options.rs.html#849-853">Source</a><a href="#impl-Default-for-OpenOptions" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/default/trait.Default.html" title="trait core::default::Default">Default</a> for <a class="struct" href="struct.OpenOptions.html" title="struct tokio::fs::OpenOptions">OpenOptions</a></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.default" class="method trait-impl"><a class="src rightside" href="../../src/tokio/fs/open_options.rs.html#850-852">Source</a><a href="#method.default" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.93.1/core/default/trait.Default.html#tymethod.default" class="fn">default</a>() -> Self</h4></section></summary><div class='docblock'>Returns the “default value” for a type. <a href="https://doc.rust-lang.org/1.93.1/core/default/trait.Default.html#tymethod.default">Read more</a></div></details></div></details><details class="toggle implementors-toggle" open><summary><section id="impl-From%3COpenOptions%3E-for-OpenOptions" class="impl"><a class="src rightside" href="../../src/tokio/fs/open_options.rs.html#837-847">Source</a><a href="#impl-From%3COpenOptions%3E-for-OpenOptions" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/convert/trait.From.html" title="trait core::convert::From">From</a><<a class="struct" href="https://doc.rust-lang.org/1.93.1/std/fs/struct.OpenOptions.html" title="struct std::fs::OpenOptions">OpenOptions</a>> for <a class="struct" href="struct.OpenOptions.html" title="struct tokio::fs::OpenOptions">OpenOptions</a></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.from" class="method trait-impl"><a class="src rightside" href="../../src/tokio/fs/open_options.rs.html#838-846">Source</a><a href="#method.from" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.93.1/core/convert/trait.From.html#tymethod.from" class="fn">from</a>(options: <a class="struct" href="https://doc.rust-lang.org/1.93.1/std/fs/struct.OpenOptions.html" title="struct std::fs::OpenOptions">StdOpenOptions</a>) -> <a class="struct" href="struct.OpenOptions.html" title="struct tokio::fs::OpenOptions">OpenOptions</a></h4></section></summary><div class='docblock'>Converts to this type from the input type.</div></details></div></details></div><h2 id="synthetic-implementations" class="section-header">Auto Trait Implementations<a href="#synthetic-implementations" class="anchor">§</a></h2><div id="synthetic-implementations-list"><section id="impl-Freeze-for-OpenOptions" class="impl"><a href="#impl-Freeze-for-OpenOptions" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Freeze.html" title="trait core::marker::Freeze">Freeze</a> for <a class="struct" href="struct.OpenOptions.html" title="struct tokio::fs::OpenOptions">OpenOptions</a></h3></section><section id="impl-RefUnwindSafe-for-OpenOptions" class="impl"><a href="#impl-RefUnwindSafe-for-OpenOptions" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/panic/unwind_safe/trait.RefUnwindSafe.html" title="trait core::panic::unwind_safe::RefUnwindSafe">RefUnwindSafe</a> for <a class="struct" href="struct.OpenOptions.html" title="struct tokio::fs::OpenOptions">OpenOptions</a></h3></section><section id="impl-Send-for-OpenOptions" class="impl"><a href="#impl-Send-for-OpenOptions" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> for <a class="struct" href="struct.OpenOptions.html" title="struct tokio::fs::OpenOptions">OpenOptions</a></h3></section><section id="impl-Sync-for-OpenOptions" class="impl"><a href="#impl-Sync-for-OpenOptions" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> for <a class="struct" href="struct.OpenOptions.html" title="struct tokio::fs::OpenOptions">OpenOptions</a></h3></section><section id="impl-Unpin-for-OpenOptions" class="impl"><a href="#impl-Unpin-for-OpenOptions" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a> for <a class="struct" href="struct.OpenOptions.html" title="struct tokio::fs::OpenOptions">OpenOptions</a></h3></section><section id="impl-UnwindSafe-for-OpenOptions" class="impl"><a href="#impl-UnwindSafe-for-OpenOptions" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/panic/unwind_safe/trait.UnwindSafe.html" title="trait core::panic::unwind_safe::UnwindSafe">UnwindSafe</a> for <a class="struct" href="struct.OpenOptions.html" title="struct tokio::fs::OpenOptions">OpenOptions</a></h3></section></div><h2 id="blanket-implementations" class="section-header">Blanket Implementations<a href="#blanket-implementations" class="anchor">§</a></h2><div id="blanket-implementations-list"><details class="toggle implementors-toggle"><summary><section id="impl-Any-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.93.1/src/core/any.rs.html#138">Source</a><a href="#impl-Any-for-T" class="anchor">§</a><h3 class="code-header">impl<T> <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/any/trait.Any.html" title="trait core::any::Any">Any</a> for T<div class="where">where
|
||
T: 'static + ?<a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.type_id" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.93.1/src/core/any.rs.html#139">Source</a><a href="#method.type_id" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.93.1/core/any/trait.Any.html#tymethod.type_id" class="fn">type_id</a>(&self) -> <a class="struct" href="https://doc.rust-lang.org/1.93.1/core/any/struct.TypeId.html" title="struct core::any::TypeId">TypeId</a></h4></section></summary><div class='docblock'>Gets the <code>TypeId</code> of <code>self</code>. <a href="https://doc.rust-lang.org/1.93.1/core/any/trait.Any.html#tymethod.type_id">Read more</a></div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-Borrow%3CT%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.93.1/src/core/borrow.rs.html#212">Source</a><a href="#impl-Borrow%3CT%3E-for-T" class="anchor">§</a><h3 class="code-header">impl<T> <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/borrow/trait.Borrow.html" title="trait core::borrow::Borrow">Borrow</a><T> for T<div class="where">where
|
||
T: ?<a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.borrow" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.93.1/src/core/borrow.rs.html#214">Source</a><a href="#method.borrow" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.93.1/core/borrow/trait.Borrow.html#tymethod.borrow" class="fn">borrow</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.reference.html">&T</a></h4></section></summary><div class='docblock'>Immutably borrows from an owned value. <a href="https://doc.rust-lang.org/1.93.1/core/borrow/trait.Borrow.html#tymethod.borrow">Read more</a></div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-BorrowMut%3CT%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.93.1/src/core/borrow.rs.html#221">Source</a><a href="#impl-BorrowMut%3CT%3E-for-T" class="anchor">§</a><h3 class="code-header">impl<T> <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/borrow/trait.BorrowMut.html" title="trait core::borrow::BorrowMut">BorrowMut</a><T> for T<div class="where">where
|
||
T: ?<a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.borrow_mut" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.93.1/src/core/borrow.rs.html#222">Source</a><a href="#method.borrow_mut" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.93.1/core/borrow/trait.BorrowMut.html#tymethod.borrow_mut" class="fn">borrow_mut</a>(&mut self) -> <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.reference.html">&mut T</a></h4></section></summary><div class='docblock'>Mutably borrows from an owned value. <a href="https://doc.rust-lang.org/1.93.1/core/borrow/trait.BorrowMut.html#tymethod.borrow_mut">Read more</a></div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-CloneToUninit-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.93.1/src/core/clone.rs.html#547">Source</a><a href="#impl-CloneToUninit-for-T" class="anchor">§</a><h3 class="code-header">impl<T> <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/clone/trait.CloneToUninit.html" title="trait core::clone::CloneToUninit">CloneToUninit</a> for T<div class="where">where
|
||
T: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>,</div></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.clone_to_uninit" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.93.1/src/core/clone.rs.html#549">Source</a><a href="#method.clone_to_uninit" class="anchor">§</a><h4 class="code-header">unsafe fn <a href="https://doc.rust-lang.org/1.93.1/core/clone/trait.CloneToUninit.html#tymethod.clone_to_uninit" class="fn">clone_to_uninit</a>(&self, dest: <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.pointer.html">*mut </a><a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.u8.html">u8</a>)</h4></section></summary><span class="item-info"><div class="stab unstable"><span class="emoji">🔬</span><span>This is a nightly-only experimental API. (<code>clone_to_uninit</code>)</span></div></span><div class='docblock'>Performs copy-assignment from <code>self</code> to <code>dest</code>. <a href="https://doc.rust-lang.org/1.93.1/core/clone/trait.CloneToUninit.html#tymethod.clone_to_uninit">Read more</a></div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-From%3CT%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.93.1/src/core/convert/mod.rs.html#785">Source</a><a href="#impl-From%3CT%3E-for-T" class="anchor">§</a><h3 class="code-header">impl<T> <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/convert/trait.From.html" title="trait core::convert::From">From</a><T> for T</h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.from-1" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.93.1/src/core/convert/mod.rs.html#788">Source</a><a href="#method.from-1" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.93.1/core/convert/trait.From.html#tymethod.from" class="fn">from</a>(t: T) -> T</h4></section></summary><div class="docblock"><p>Returns the argument unchanged.</p>
|
||
</div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-Into%3CU%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.93.1/src/core/convert/mod.rs.html#767-769">Source</a><a href="#impl-Into%3CU%3E-for-T" class="anchor">§</a><h3 class="code-header">impl<T, U> <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a><U> for T<div class="where">where
|
||
U: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/convert/trait.From.html" title="trait core::convert::From">From</a><T>,</div></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.into" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.93.1/src/core/convert/mod.rs.html#777">Source</a><a href="#method.into" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.93.1/core/convert/trait.Into.html#tymethod.into" class="fn">into</a>(self) -> U</h4></section></summary><div class="docblock"><p>Calls <code>U::from(self)</code>.</p>
|
||
<p>That is, this conversion is whatever the implementation of
|
||
<code><a href="https://doc.rust-lang.org/1.93.1/core/convert/trait.From.html" title="trait core::convert::From">From</a><T> for U</code> chooses to do.</p>
|
||
</div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-ToOwned-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.93.1/src/alloc/borrow.rs.html#85-87">Source</a><a href="#impl-ToOwned-for-T" class="anchor">§</a><h3 class="code-header">impl<T> <a class="trait" href="https://doc.rust-lang.org/1.93.1/alloc/borrow/trait.ToOwned.html" title="trait alloc::borrow::ToOwned">ToOwned</a> for T<div class="where">where
|
||
T: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>,</div></h3></section></summary><div class="impl-items"><details class="toggle" open><summary><section id="associatedtype.Owned" class="associatedtype trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.93.1/src/alloc/borrow.rs.html#89">Source</a><a href="#associatedtype.Owned" class="anchor">§</a><h4 class="code-header">type <a href="https://doc.rust-lang.org/1.93.1/alloc/borrow/trait.ToOwned.html#associatedtype.Owned" class="associatedtype">Owned</a> = T</h4></section></summary><div class='docblock'>The resulting type after obtaining ownership.</div></details><details class="toggle method-toggle" open><summary><section id="method.to_owned" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.93.1/src/alloc/borrow.rs.html#90">Source</a><a href="#method.to_owned" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.93.1/alloc/borrow/trait.ToOwned.html#tymethod.to_owned" class="fn">to_owned</a>(&self) -> T</h4></section></summary><div class='docblock'>Creates owned data from borrowed data, usually by cloning. <a href="https://doc.rust-lang.org/1.93.1/alloc/borrow/trait.ToOwned.html#tymethod.to_owned">Read more</a></div></details><details class="toggle method-toggle" open><summary><section id="method.clone_into" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.93.1/src/alloc/borrow.rs.html#94">Source</a><a href="#method.clone_into" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.93.1/alloc/borrow/trait.ToOwned.html#method.clone_into" class="fn">clone_into</a>(&self, target: <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.reference.html">&mut T</a>)</h4></section></summary><div class='docblock'>Uses borrowed data to replace owned data, usually by cloning. <a href="https://doc.rust-lang.org/1.93.1/alloc/borrow/trait.ToOwned.html#method.clone_into">Read more</a></div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-TryFrom%3CU%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.93.1/src/core/convert/mod.rs.html#827-829">Source</a><a href="#impl-TryFrom%3CU%3E-for-T" class="anchor">§</a><h3 class="code-header">impl<T, U> <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><U> for T<div class="where">where
|
||
U: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a><T>,</div></h3></section></summary><div class="impl-items"><details class="toggle" open><summary><section id="associatedtype.Error-1" class="associatedtype trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.93.1/src/core/convert/mod.rs.html#831">Source</a><a href="#associatedtype.Error-1" class="anchor">§</a><h4 class="code-header">type <a href="https://doc.rust-lang.org/1.93.1/core/convert/trait.TryFrom.html#associatedtype.Error" class="associatedtype">Error</a> = <a class="enum" href="https://doc.rust-lang.org/1.93.1/core/convert/enum.Infallible.html" title="enum core::convert::Infallible">Infallible</a></h4></section></summary><div class='docblock'>The type returned in the event of a conversion error.</div></details><details class="toggle method-toggle" open><summary><section id="method.try_from" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.93.1/src/core/convert/mod.rs.html#834">Source</a><a href="#method.try_from" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.93.1/core/convert/trait.TryFrom.html#tymethod.try_from" class="fn">try_from</a>(value: U) -> <a class="enum" href="https://doc.rust-lang.org/1.93.1/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.93.1/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><U>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.93.1/core/convert/trait.TryFrom.html#associatedtype.Error" title="type core::convert::TryFrom::Error">Error</a>></h4></section></summary><div class='docblock'>Performs the conversion.</div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-TryInto%3CU%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.93.1/src/core/convert/mod.rs.html#811-813">Source</a><a href="#impl-TryInto%3CU%3E-for-T" class="anchor">§</a><h3 class="code-header">impl<T, U> <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/convert/trait.TryInto.html" title="trait core::convert::TryInto">TryInto</a><U> for T<div class="where">where
|
||
U: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><T>,</div></h3></section></summary><div class="impl-items"><details class="toggle" open><summary><section id="associatedtype.Error" class="associatedtype trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.93.1/src/core/convert/mod.rs.html#815">Source</a><a href="#associatedtype.Error" class="anchor">§</a><h4 class="code-header">type <a href="https://doc.rust-lang.org/1.93.1/core/convert/trait.TryInto.html#associatedtype.Error" class="associatedtype">Error</a> = <U as <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><T>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.93.1/core/convert/trait.TryFrom.html#associatedtype.Error" title="type core::convert::TryFrom::Error">Error</a></h4></section></summary><div class='docblock'>The type returned in the event of a conversion error.</div></details><details class="toggle method-toggle" open><summary><section id="method.try_into" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.93.1/src/core/convert/mod.rs.html#818">Source</a><a href="#method.try_into" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.93.1/core/convert/trait.TryInto.html#tymethod.try_into" class="fn">try_into</a>(self) -> <a class="enum" href="https://doc.rust-lang.org/1.93.1/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.93.1/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><T>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.93.1/core/convert/trait.TryFrom.html#associatedtype.Error" title="type core::convert::TryFrom::Error">Error</a>></h4></section></summary><div class='docblock'>Performs the conversion.</div></details></div></details></div></section></div></main></body></html> |