blob: 5022b847c3ea0e0902701f7eaebfdfc13191d4ee [file] [log] [blame]
<!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="An asynchronous reader-writer lock."><meta name="keywords" content="rust, rustlang, rust-lang, RwLock"><title>RwLock in tokio::sync - Rust</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceSerif4-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../FiraSans-Regular.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../FiraSans-Medium.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceCodePro-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceSerif4-Bold.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceCodePro-Semibold.ttf.woff2"><link rel="stylesheet" href="../../normalize.css"><link rel="stylesheet" href="../../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" href="../../ayu.css" disabled><link rel="stylesheet" href="../../dark.css" disabled><link rel="stylesheet" href="../../light.css" id="themeStyle"><script id="default-settings" ></script><script src="../../storage.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../main.js"></script><noscript><link rel="stylesheet" href="../../noscript.css"></noscript><link rel="alternate icon" type="image/png" href="../../favicon-16x16.png"><link rel="alternate icon" type="image/png" href="../../favicon-32x32.png"><link rel="icon" type="image/svg+xml" href="../../favicon.svg"></head><body class="rustdoc struct"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle">&#9776;</button><a class="sidebar-logo" href="../../tokio/index.html"><div class="logo-container"><img class="rust-logo" src="../../rust-logo.svg" alt="logo"></div></a><h2></h2></nav><nav class="sidebar"><a class="sidebar-logo" href="../../tokio/index.html"><div class="logo-container"><img class="rust-logo" src="../../rust-logo.svg" alt="logo"></div></a><h2 class="location"><a href="#">RwLock</a></h2><div class="sidebar-elems"><section><h3><a href="#implementations">Methods</a></h3><ul class="block"><li><a href="#method.blocking_read">blocking_read</a></li><li><a href="#method.blocking_write">blocking_write</a></li><li><a href="#method.get_mut">get_mut</a></li><li><a href="#method.into_inner">into_inner</a></li><li><a href="#method.new">new</a></li><li><a href="#method.read">read</a></li><li><a href="#method.read_owned">read_owned</a></li><li><a href="#method.try_read">try_read</a></li><li><a href="#method.try_read_owned">try_read_owned</a></li><li><a href="#method.try_write">try_write</a></li><li><a href="#method.try_write_owned">try_write_owned</a></li><li><a href="#method.with_max_readers">with_max_readers</a></li><li><a href="#method.write">write</a></li><li><a href="#method.write_owned">write_owned</a></li></ul><h3><a href="#trait-implementations">Trait Implementations</a></h3><ul class="block"><li><a href="#impl-Debug-for-RwLock%3CT%3E">Debug</a></li><li><a href="#impl-Default-for-RwLock%3CT%3E">Default</a></li><li><a href="#impl-From%3CT%3E-for-RwLock%3CT%3E">From&lt;T&gt;</a></li><li><a href="#impl-Send-for-RwLock%3CT%3E">Send</a></li><li><a href="#impl-Sync-for-RwLock%3CT%3E">Sync</a></li></ul><h3><a href="#synthetic-implementations">Auto Trait Implementations</a></h3><ul class="block"><li><a href="#impl-RefUnwindSafe-for-RwLock%3CT%3E">!RefUnwindSafe</a></li><li><a href="#impl-Unpin-for-RwLock%3CT%3E">Unpin</a></li><li><a href="#impl-UnwindSafe-for-RwLock%3CT%3E">UnwindSafe</a></li></ul><h3><a href="#blanket-implementations">Blanket Implementations</a></h3><ul class="block"><li><a href="#impl-Any-for-RwLock%3CT%3E">Any</a></li><li><a href="#impl-Borrow%3CT%3E-for-RwLock%3CT%3E">Borrow&lt;T&gt;</a></li><li><a href="#impl-BorrowMut%3CT%3E-for-RwLock%3CT%3E">BorrowMut&lt;T&gt;</a></li><li><a href="#impl-From%3C!%3E-for-RwLock%3CT%3E">From&lt;!&gt;</a></li><li><a href="#impl-From%3CT%3E-for-RwLock%3CT%3E-1">From&lt;T&gt;</a></li><li><a href="#impl-Into%3CU%3E-for-RwLock%3CT%3E">Into&lt;U&gt;</a></li><li><a href="#impl-TryFrom%3CU%3E-for-RwLock%3CT%3E">TryFrom&lt;U&gt;</a></li><li><a href="#impl-TryInto%3CU%3E-for-RwLock%3CT%3E">TryInto&lt;U&gt;</a></li></ul></section><h2><a href="index.html">In tokio::sync</a></h2></div></nav><main><div class="width-limiter"><nav class="sub"><form class="search-form"><div class="search-container"><span></span><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><div id="help-button" title="help" tabindex="-1"><a href="../../help.html">?</a></div><div id="settings-menu" tabindex="-1"><a href="../../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../../wheel.svg"></a></div></div></form></nav><section id="main-content" class="content"><div class="main-heading"><h1 class="fqn">Struct <a href="../index.html">tokio</a>::<wbr><a href="index.html">sync</a>::<wbr><a class="struct" href="#">RwLock</a><button id="copy-path" onclick="copy_path(this)" title="Copy item path to clipboard"><img src="../../clipboard.svg" width="19" height="18" alt="Copy item path"></button></h1><span class="out-of-band"><a class="srclink" href="../../src/tokio/sync/rwlock.rs.html#88-100">source</a> · <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">&#x2212;</span>]</a></span></div><div class="item-decl"><pre class="rust struct"><code>pub struct RwLock&lt;T:&nbsp;?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>&gt; { /* private fields */ }</code></pre></div><details class="rustdoc-toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>An asynchronous reader-writer lock.</p>
<p>This type of lock allows a number of readers or at most one writer at any
point in time. The write portion of this lock typically allows modification
of the underlying data (exclusive access) and the read portion of this lock
typically allows for read-only access (shared access).</p>
<p>In comparison, a <a href="struct.Mutex.html"><code>Mutex</code></a> does not distinguish between readers or writers
that acquire the lock, therefore causing any tasks waiting for the lock to
become available to yield. An <code>RwLock</code> will allow any number of readers to
acquire the lock as long as a writer is not holding the lock.</p>
<p>The priority policy of Tokio’s read-write lock is <em>fair</em> (or
<a href="https://en.wikipedia.org/wiki/Readers%E2%80%93writer_lock#Priority_policies"><em>write-preferring</em></a>), in order to ensure that readers cannot starve
writers. Fairness is ensured using a first-in, first-out queue for the tasks
awaiting the lock; if a task that wishes to acquire the write lock is at the
head of the queue, read locks will not be given out until the write lock has
been released. This is in contrast to the Rust standard library’s
<code>std::sync::RwLock</code>, where the priority policy is dependent on the
operating system’s implementation.</p>
<p>The type parameter <code>T</code> represents the data that this lock protects. It is
required that <code>T</code> satisfies <a href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html"><code>Send</code></a> to be shared across threads. The RAII guards
returned from the locking methods implement <a href="https://doc.rust-lang.org/nightly/core/ops/deref/trait.Deref.html"><code>Deref</code></a>
(and <a href="https://doc.rust-lang.org/nightly/core/ops/deref/trait.DerefMut.html"><code>DerefMut</code></a>
for the <code>write</code> methods) to allow access to the content of the lock.</p>
<h2 id="examples"><a href="#examples">Examples</a></h2>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::sync::RwLock;
<span class="attribute">#[tokio::main]
</span><span class="kw">async fn </span>main() {
<span class="kw">let </span>lock = RwLock::new(<span class="number">5</span>);
<span class="comment">// many reader locks can be held at once
</span>{
<span class="kw">let </span>r1 = lock.read().<span class="kw">await</span>;
<span class="kw">let </span>r2 = lock.read().<span class="kw">await</span>;
<span class="macro">assert_eq!</span>(<span class="kw-2">*</span>r1, <span class="number">5</span>);
<span class="macro">assert_eq!</span>(<span class="kw-2">*</span>r2, <span class="number">5</span>);
} <span class="comment">// read locks are dropped at this point
// only one write lock may be held, however
</span>{
<span class="kw">let </span><span class="kw-2">mut </span>w = lock.write().<span class="kw">await</span>;
<span class="kw-2">*</span>w += <span class="number">1</span>;
<span class="macro">assert_eq!</span>(<span class="kw-2">*</span>w, <span class="number">6</span>);
} <span class="comment">// write lock is dropped here
</span>}</code></pre></div>
</div></details><h2 id="implementations" class="small-section-header">Implementations<a href="#implementations" class="anchor"></a></h2><div id="implementations-list"><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-RwLock%3CT%3E" class="impl has-srclink"><a class="srclink rightside" href="../../src/tokio/sync/rwlock.rs.html#193-1081">source</a><a href="#impl-RwLock%3CT%3E" class="anchor"></a><h3 class="code-header">impl&lt;T:&nbsp;?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>&gt; <a class="struct" href="struct.RwLock.html" title="struct tokio::sync::RwLock">RwLock</a>&lt;T&gt;</h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.new" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/sync/rwlock.rs.html#204-253">source</a><h4 class="code-header">pub fn <a href="#method.new" class="fnname">new</a>(value: T) -&gt; <a class="struct" href="struct.RwLock.html" title="struct tokio::sync::RwLock">RwLock</a>&lt;T&gt;<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</span></h4></section></summary><div class="docblock"><p>Creates a new instance of an <code>RwLock&lt;T&gt;</code> which is unlocked.</p>
<h5 id="examples-1"><a href="#examples-1">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::sync::RwLock;
<span class="kw">let </span>lock = RwLock::new(<span class="number">5</span>);</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.with_max_readers" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/sync/rwlock.rs.html#270-326">source</a><h4 class="code-header">pub fn <a href="#method.with_max_readers" class="fnname">with_max_readers</a>(value: T, max_reads: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>) -&gt; <a class="struct" href="struct.RwLock.html" title="struct tokio::sync::RwLock">RwLock</a>&lt;T&gt;<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</span></h4></section></summary><div class="docblock"><p>Creates a new instance of an <code>RwLock&lt;T&gt;</code> which is unlocked
and allows a maximum of <code>max_reads</code> concurrent readers.</p>
<h5 id="examples-2"><a href="#examples-2">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::sync::RwLock;
<span class="kw">let </span>lock = RwLock::with_max_readers(<span class="number">5</span>, <span class="number">1024</span>);</code></pre></div>
<h5 id="panics"><a href="#panics">Panics</a></h5>
<p>Panics if <code>max_reads</code> is more than <code>u32::MAX &gt;&gt; 3</code>.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.read" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/sync/rwlock.rs.html#423-462">source</a><h4 class="code-header">pub async fn <a href="#method.read" class="fnname">read</a>(&amp;self) -&gt; <a class="struct" href="struct.RwLockReadGuard.html" title="struct tokio::sync::RwLockReadGuard">RwLockReadGuard</a>&lt;'_, T&gt;</h4></section></summary><div class="docblock"><p>Locks this <code>RwLock</code> with shared read access, causing the current task
to yield until the lock has been acquired.</p>
<p>The calling task will yield until there are no writers which hold the
lock. There may be other readers inside the lock when the task resumes.</p>
<p>Note that under the priority policy of <a href="struct.RwLock.html" title="RwLock"><code>RwLock</code></a>, read locks are not
granted until prior write locks, to prevent starvation. Therefore
deadlock may occur if a read lock is held by the current task, a write
lock attempt is made, and then a subsequent read lock attempt is made
by the current task.</p>
<p>Returns an RAII guard which will drop this read access of the <code>RwLock</code>
when dropped.</p>
<h5 id="cancel-safety"><a href="#cancel-safety">Cancel safety</a></h5>
<p>This method uses a queue to fairly distribute locks in the order they
were requested. Cancelling a call to <code>read</code> makes you lose your place in
the queue.</p>
<h5 id="examples-3"><a href="#examples-3">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::sync::Arc;
<span class="kw">use </span>tokio::sync::RwLock;
<span class="attribute">#[tokio::main]
</span><span class="kw">async fn </span>main() {
<span class="kw">let </span>lock = Arc::new(RwLock::new(<span class="number">1</span>));
<span class="kw">let </span>c_lock = lock.clone();
<span class="kw">let </span>n = lock.read().<span class="kw">await</span>;
<span class="macro">assert_eq!</span>(<span class="kw-2">*</span>n, <span class="number">1</span>);
tokio::spawn(<span class="kw">async move </span>{
<span class="comment">// While main has an active read lock, we acquire one too.
</span><span class="kw">let </span>r = c_lock.read().<span class="kw">await</span>;
<span class="macro">assert_eq!</span>(<span class="kw-2">*</span>r, <span class="number">1</span>);
}).<span class="kw">await</span>.expect(<span class="string">&quot;The spawned task has panicked&quot;</span>);
<span class="comment">// Drop the guard after the spawned task finishes.
</span>drop(n);
}</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.blocking_read" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/sync/rwlock.rs.html#513-515">source</a><h4 class="code-header">pub fn <a href="#method.blocking_read" class="fnname">blocking_read</a>(&amp;self) -&gt; <a class="struct" href="struct.RwLockReadGuard.html" title="struct tokio::sync::RwLockReadGuard">RwLockReadGuard</a>&lt;'_, T&gt;</h4></section></summary><div class="docblock"><p>Blockingly locks this <code>RwLock</code> with shared read access.</p>
<p>This method is intended for use cases where you
need to use this rwlock in asynchronous code as well as in synchronous code.</p>
<p>Returns an RAII guard which will drop the read access of this <code>RwLock</code> when dropped.</p>
<h5 id="panics-1"><a href="#panics-1">Panics</a></h5>
<p>This function panics if called within an asynchronous execution context.</p>
<ul>
<li>If you find yourself in an asynchronous execution context and needing
to call some (synchronous) function which performs one of these
<code>blocking_</code> operations, then consider wrapping that call inside
<a href="../runtime/struct.Handle.html#method.spawn_blocking" title="crate::runtime::Handle::spawn_blocking"><code>spawn_blocking()</code></a>
(or [<code>block_in_place()</code>][crate::task::block_in_place]).</li>
</ul>
<h5 id="examples-4"><a href="#examples-4">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::sync::Arc;
<span class="kw">use </span>tokio::sync::RwLock;
<span class="attribute">#[tokio::main]
</span><span class="kw">async fn </span>main() {
<span class="kw">let </span>rwlock = Arc::new(RwLock::new(<span class="number">1</span>));
<span class="kw">let </span><span class="kw-2">mut </span>write_lock = rwlock.write().<span class="kw">await</span>;
<span class="kw">let </span>blocking_task = tokio::task::spawn_blocking({
<span class="kw">let </span>rwlock = Arc::clone(<span class="kw-2">&amp;</span>rwlock);
<span class="kw">move </span>|| {
<span class="comment">// This shall block until the `write_lock` is released.
</span><span class="kw">let </span>read_lock = rwlock.blocking_read();
<span class="macro">assert_eq!</span>(<span class="kw-2">*</span>read_lock, <span class="number">0</span>);
}
});
<span class="kw-2">*</span>write_lock -= <span class="number">1</span>;
drop(write_lock); <span class="comment">// release the lock.
// Await the completion of the blocking task.
</span>blocking_task.<span class="kw">await</span>.unwrap();
<span class="comment">// Assert uncontended.
</span><span class="macro">assert!</span>(rwlock.try_write().is_ok());
}</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.read_owned" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/sync/rwlock.rs.html#568-610">source</a><h4 class="code-header">pub async fn <a href="#method.read_owned" class="fnname">read_owned</a>(self: <a class="struct" href="https://doc.rust-lang.org/nightly/alloc/sync/struct.Arc.html" title="struct alloc::sync::Arc">Arc</a>&lt;Self&gt;) -&gt; <a class="struct" href="struct.OwnedRwLockReadGuard.html" title="struct tokio::sync::OwnedRwLockReadGuard">OwnedRwLockReadGuard</a>&lt;T&gt;</h4></section></summary><div class="docblock"><p>Locks this <code>RwLock</code> with shared read access, causing the current task
to yield until the lock has been acquired.</p>
<p>The calling task will yield until there are no writers which hold the
lock. There may be other readers inside the lock when the task resumes.</p>
<p>This method is identical to <a href="struct.RwLock.html#method.read" title="RwLock::read"><code>RwLock::read</code></a>, except that the returned
guard references the <code>RwLock</code> with an <a href="https://doc.rust-lang.org/nightly/alloc/sync/struct.Arc.html" title="Arc"><code>Arc</code></a> rather than by borrowing
it. Therefore, the <code>RwLock</code> must be wrapped in an <code>Arc</code> to call this
method, and the guard will live for the <code>'static</code> lifetime, as it keeps
the <code>RwLock</code> alive by holding an <code>Arc</code>.</p>
<p>Note that under the priority policy of <a href="struct.RwLock.html" title="RwLock"><code>RwLock</code></a>, read locks are not
granted until prior write locks, to prevent starvation. Therefore
deadlock may occur if a read lock is held by the current task, a write
lock attempt is made, and then a subsequent read lock attempt is made
by the current task.</p>
<p>Returns an RAII guard which will drop this read access of the <code>RwLock</code>
when dropped.</p>
<h5 id="cancel-safety-1"><a href="#cancel-safety-1">Cancel safety</a></h5>
<p>This method uses a queue to fairly distribute locks in the order they
were requested. Cancelling a call to <code>read_owned</code> makes you lose your
place in the queue.</p>
<h5 id="examples-5"><a href="#examples-5">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::sync::Arc;
<span class="kw">use </span>tokio::sync::RwLock;
<span class="attribute">#[tokio::main]
</span><span class="kw">async fn </span>main() {
<span class="kw">let </span>lock = Arc::new(RwLock::new(<span class="number">1</span>));
<span class="kw">let </span>c_lock = lock.clone();
<span class="kw">let </span>n = lock.read_owned().<span class="kw">await</span>;
<span class="macro">assert_eq!</span>(<span class="kw-2">*</span>n, <span class="number">1</span>);
tokio::spawn(<span class="kw">async move </span>{
<span class="comment">// While main has an active read lock, we acquire one too.
</span><span class="kw">let </span>r = c_lock.read_owned().<span class="kw">await</span>;
<span class="macro">assert_eq!</span>(<span class="kw-2">*</span>r, <span class="number">1</span>);
}).<span class="kw">await</span>.expect(<span class="string">&quot;The spawned task has panicked&quot;</span>);
<span class="comment">// Drop the guard after the spawned task finishes.
</span>drop(n);
}</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.try_read" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/sync/rwlock.rs.html#644-669">source</a><h4 class="code-header">pub fn <a href="#method.try_read" class="fnname">try_read</a>(&amp;self) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="struct" href="struct.RwLockReadGuard.html" title="struct tokio::sync::RwLockReadGuard">RwLockReadGuard</a>&lt;'_, T&gt;, <a class="struct" href="struct.TryLockError.html" title="struct tokio::sync::TryLockError">TryLockError</a>&gt;</h4></section></summary><div class="docblock"><p>Attempts to acquire this <code>RwLock</code> with shared read access.</p>
<p>If the access couldn’t be acquired immediately, returns <a href="struct.TryLockError.html"><code>TryLockError</code></a>.
Otherwise, an RAII guard is returned which will release read access
when dropped.</p>
<h5 id="examples-6"><a href="#examples-6">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::sync::Arc;
<span class="kw">use </span>tokio::sync::RwLock;
<span class="attribute">#[tokio::main]
</span><span class="kw">async fn </span>main() {
<span class="kw">let </span>lock = Arc::new(RwLock::new(<span class="number">1</span>));
<span class="kw">let </span>c_lock = lock.clone();
<span class="kw">let </span>v = lock.try_read().unwrap();
<span class="macro">assert_eq!</span>(<span class="kw-2">*</span>v, <span class="number">1</span>);
tokio::spawn(<span class="kw">async move </span>{
<span class="comment">// While main has an active read lock, we acquire one too.
</span><span class="kw">let </span>n = c_lock.read().<span class="kw">await</span>;
<span class="macro">assert_eq!</span>(<span class="kw-2">*</span>n, <span class="number">1</span>);
}).<span class="kw">await</span>.expect(<span class="string">&quot;The spawned task has panicked&quot;</span>);
<span class="comment">// Drop the guard when spawned task finishes.
</span>drop(v);
}</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.try_read_owned" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/sync/rwlock.rs.html#709-734">source</a><h4 class="code-header">pub fn <a href="#method.try_read_owned" class="fnname">try_read_owned</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;self: <a class="struct" href="https://doc.rust-lang.org/nightly/alloc/sync/struct.Arc.html" title="struct alloc::sync::Arc">Arc</a>&lt;Self&gt;<br>) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="struct" href="struct.OwnedRwLockReadGuard.html" title="struct tokio::sync::OwnedRwLockReadGuard">OwnedRwLockReadGuard</a>&lt;T&gt;, <a class="struct" href="struct.TryLockError.html" title="struct tokio::sync::TryLockError">TryLockError</a>&gt;</h4></section></summary><div class="docblock"><p>Attempts to acquire this <code>RwLock</code> with shared read access.</p>
<p>If the access couldn’t be acquired immediately, returns <a href="struct.TryLockError.html"><code>TryLockError</code></a>.
Otherwise, an RAII guard is returned which will release read access
when dropped.</p>
<p>This method is identical to <a href="struct.RwLock.html#method.try_read" title="RwLock::try_read"><code>RwLock::try_read</code></a>, except that the
returned guard references the <code>RwLock</code> with an <a href="https://doc.rust-lang.org/nightly/alloc/sync/struct.Arc.html" title="Arc"><code>Arc</code></a> rather than by
borrowing it. Therefore, the <code>RwLock</code> must be wrapped in an <code>Arc</code> to
call this method, and the guard will live for the <code>'static</code> lifetime,
as it keeps the <code>RwLock</code> alive by holding an <code>Arc</code>.</p>
<h5 id="examples-7"><a href="#examples-7">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::sync::Arc;
<span class="kw">use </span>tokio::sync::RwLock;
<span class="attribute">#[tokio::main]
</span><span class="kw">async fn </span>main() {
<span class="kw">let </span>lock = Arc::new(RwLock::new(<span class="number">1</span>));
<span class="kw">let </span>c_lock = lock.clone();
<span class="kw">let </span>v = lock.try_read_owned().unwrap();
<span class="macro">assert_eq!</span>(<span class="kw-2">*</span>v, <span class="number">1</span>);
tokio::spawn(<span class="kw">async move </span>{
<span class="comment">// While main has an active read lock, we acquire one too.
</span><span class="kw">let </span>n = c_lock.read_owned().<span class="kw">await</span>;
<span class="macro">assert_eq!</span>(<span class="kw-2">*</span>n, <span class="number">1</span>);
}).<span class="kw">await</span>.expect(<span class="string">&quot;The spawned task has panicked&quot;</span>);
<span class="comment">// Drop the guard when spawned task finishes.
</span>drop(v);
}</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.write" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/sync/rwlock.rs.html#764-804">source</a><h4 class="code-header">pub async fn <a href="#method.write" class="fnname">write</a>(&amp;self) -&gt; <a class="struct" href="struct.RwLockWriteGuard.html" title="struct tokio::sync::RwLockWriteGuard">RwLockWriteGuard</a>&lt;'_, T&gt;</h4></section></summary><div class="docblock"><p>Locks this <code>RwLock</code> with exclusive write access, causing the current
task to yield until the lock has been acquired.</p>
<p>The calling task will yield while other writers or readers currently
have access to the lock.</p>
<p>Returns an RAII guard which will drop the write access of this <code>RwLock</code>
when dropped.</p>
<h5 id="cancel-safety-2"><a href="#cancel-safety-2">Cancel safety</a></h5>
<p>This method uses a queue to fairly distribute locks in the order they
were requested. Cancelling a call to <code>write</code> makes you lose your place
in the queue.</p>
<h5 id="examples-8"><a href="#examples-8">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::sync::RwLock;
<span class="attribute">#[tokio::main]
</span><span class="kw">async fn </span>main() {
<span class="kw">let </span>lock = RwLock::new(<span class="number">1</span>);
<span class="kw">let </span><span class="kw-2">mut </span>n = lock.write().<span class="kw">await</span>;
<span class="kw-2">*</span>n = <span class="number">2</span>;
}</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.blocking_write" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/sync/rwlock.rs.html#857-859">source</a><h4 class="code-header">pub fn <a href="#method.blocking_write" class="fnname">blocking_write</a>(&amp;self) -&gt; <a class="struct" href="struct.RwLockWriteGuard.html" title="struct tokio::sync::RwLockWriteGuard">RwLockWriteGuard</a>&lt;'_, T&gt;</h4></section></summary><div class="docblock"><p>Blockingly locks this <code>RwLock</code> with exclusive write access.</p>
<p>This method is intended for use cases where you
need to use this rwlock in asynchronous code as well as in synchronous code.</p>
<p>Returns an RAII guard which will drop the write access of this <code>RwLock</code> when dropped.</p>
<h5 id="panics-2"><a href="#panics-2">Panics</a></h5>
<p>This function panics if called within an asynchronous execution context.</p>
<ul>
<li>If you find yourself in an asynchronous execution context and needing
to call some (synchronous) function which performs one of these
<code>blocking_</code> operations, then consider wrapping that call inside
<a href="../runtime/struct.Handle.html#method.spawn_blocking" title="crate::runtime::Handle::spawn_blocking"><code>spawn_blocking()</code></a>
(or [<code>block_in_place()</code>][crate::task::block_in_place]).</li>
</ul>
<h5 id="examples-9"><a href="#examples-9">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::sync::Arc;
<span class="kw">use </span>tokio::{sync::RwLock};
<span class="attribute">#[tokio::main]
</span><span class="kw">async fn </span>main() {
<span class="kw">let </span>rwlock = Arc::new(RwLock::new(<span class="number">1</span>));
<span class="kw">let </span>read_lock = rwlock.read().<span class="kw">await</span>;
<span class="kw">let </span>blocking_task = tokio::task::spawn_blocking({
<span class="kw">let </span>rwlock = Arc::clone(<span class="kw-2">&amp;</span>rwlock);
<span class="kw">move </span>|| {
<span class="comment">// This shall block until the `read_lock` is released.
</span><span class="kw">let </span><span class="kw-2">mut </span>write_lock = rwlock.blocking_write();
<span class="kw-2">*</span>write_lock = <span class="number">2</span>;
}
});
<span class="macro">assert_eq!</span>(<span class="kw-2">*</span>read_lock, <span class="number">1</span>);
<span class="comment">// Release the last outstanding read lock.
</span>drop(read_lock);
<span class="comment">// Await the completion of the blocking task.
</span>blocking_task.<span class="kw">await</span>.unwrap();
<span class="comment">// Assert uncontended.
</span><span class="kw">let </span>read_lock = rwlock.try_read().unwrap();
<span class="macro">assert_eq!</span>(<span class="kw-2">*</span>read_lock, <span class="number">2</span>);
}</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.write_owned" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/sync/rwlock.rs.html#896-939">source</a><h4 class="code-header">pub async fn <a href="#method.write_owned" class="fnname">write_owned</a>(self: <a class="struct" href="https://doc.rust-lang.org/nightly/alloc/sync/struct.Arc.html" title="struct alloc::sync::Arc">Arc</a>&lt;Self&gt;) -&gt; <a class="struct" href="struct.OwnedRwLockWriteGuard.html" title="struct tokio::sync::OwnedRwLockWriteGuard">OwnedRwLockWriteGuard</a>&lt;T&gt;</h4></section></summary><div class="docblock"><p>Locks this <code>RwLock</code> with exclusive write access, causing the current
task to yield until the lock has been acquired.</p>
<p>The calling task will yield while other writers or readers currently
have access to the lock.</p>
<p>This method is identical to <a href="struct.RwLock.html#method.write" title="RwLock::write"><code>RwLock::write</code></a>, except that the returned
guard references the <code>RwLock</code> with an <a href="https://doc.rust-lang.org/nightly/alloc/sync/struct.Arc.html" title="Arc"><code>Arc</code></a> rather than by borrowing
it. Therefore, the <code>RwLock</code> must be wrapped in an <code>Arc</code> to call this
method, and the guard will live for the <code>'static</code> lifetime, as it keeps
the <code>RwLock</code> alive by holding an <code>Arc</code>.</p>
<p>Returns an RAII guard which will drop the write access of this <code>RwLock</code>
when dropped.</p>
<h5 id="cancel-safety-3"><a href="#cancel-safety-3">Cancel safety</a></h5>
<p>This method uses a queue to fairly distribute locks in the order they
were requested. Cancelling a call to <code>write_owned</code> makes you lose your
place in the queue.</p>
<h5 id="examples-10"><a href="#examples-10">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::sync::Arc;
<span class="kw">use </span>tokio::sync::RwLock;
<span class="attribute">#[tokio::main]
</span><span class="kw">async fn </span>main() {
<span class="kw">let </span>lock = Arc::new(RwLock::new(<span class="number">1</span>));
<span class="kw">let </span><span class="kw-2">mut </span>n = lock.write_owned().<span class="kw">await</span>;
<span class="kw-2">*</span>n = <span class="number">2</span>;
}</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.try_write" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/sync/rwlock.rs.html#964-990">source</a><h4 class="code-header">pub fn <a href="#method.try_write" class="fnname">try_write</a>(&amp;self) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="struct" href="struct.RwLockWriteGuard.html" title="struct tokio::sync::RwLockWriteGuard">RwLockWriteGuard</a>&lt;'_, T&gt;, <a class="struct" href="struct.TryLockError.html" title="struct tokio::sync::TryLockError">TryLockError</a>&gt;</h4></section></summary><div class="docblock"><p>Attempts to acquire this <code>RwLock</code> with exclusive write access.</p>
<p>If the access couldn’t be acquired immediately, returns <a href="struct.TryLockError.html"><code>TryLockError</code></a>.
Otherwise, an RAII guard is returned which will release write access
when dropped.</p>
<h5 id="examples-11"><a href="#examples-11">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::sync::RwLock;
<span class="attribute">#[tokio::main]
</span><span class="kw">async fn </span>main() {
<span class="kw">let </span>rw = RwLock::new(<span class="number">1</span>);
<span class="kw">let </span>v = rw.read().<span class="kw">await</span>;
<span class="macro">assert_eq!</span>(<span class="kw-2">*</span>v, <span class="number">1</span>);
<span class="macro">assert!</span>(rw.try_write().is_err());
}</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.try_write_owned" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/sync/rwlock.rs.html#1022-1048">source</a><h4 class="code-header">pub fn <a href="#method.try_write_owned" class="fnname">try_write_owned</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;self: <a class="struct" href="https://doc.rust-lang.org/nightly/alloc/sync/struct.Arc.html" title="struct alloc::sync::Arc">Arc</a>&lt;Self&gt;<br>) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="struct" href="struct.OwnedRwLockWriteGuard.html" title="struct tokio::sync::OwnedRwLockWriteGuard">OwnedRwLockWriteGuard</a>&lt;T&gt;, <a class="struct" href="struct.TryLockError.html" title="struct tokio::sync::TryLockError">TryLockError</a>&gt;</h4></section></summary><div class="docblock"><p>Attempts to acquire this <code>RwLock</code> with exclusive write access.</p>
<p>If the access couldn’t be acquired immediately, returns <a href="struct.TryLockError.html"><code>TryLockError</code></a>.
Otherwise, an RAII guard is returned which will release write access
when dropped.</p>
<p>This method is identical to <a href="struct.RwLock.html#method.try_write" title="RwLock::try_write"><code>RwLock::try_write</code></a>, except that the
returned guard references the <code>RwLock</code> with an <a href="https://doc.rust-lang.org/nightly/alloc/sync/struct.Arc.html" title="Arc"><code>Arc</code></a> rather than by
borrowing it. Therefore, the <code>RwLock</code> must be wrapped in an <code>Arc</code> to
call this method, and the guard will live for the <code>'static</code> lifetime,
as it keeps the <code>RwLock</code> alive by holding an <code>Arc</code>.</p>
<h5 id="examples-12"><a href="#examples-12">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::sync::Arc;
<span class="kw">use </span>tokio::sync::RwLock;
<span class="attribute">#[tokio::main]
</span><span class="kw">async fn </span>main() {
<span class="kw">let </span>rw = Arc::new(RwLock::new(<span class="number">1</span>));
<span class="kw">let </span>v = Arc::clone(<span class="kw-2">&amp;</span>rw).read_owned().<span class="kw">await</span>;
<span class="macro">assert_eq!</span>(<span class="kw-2">*</span>v, <span class="number">1</span>);
<span class="macro">assert!</span>(rw.try_write_owned().is_err());
}</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.get_mut" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/sync/rwlock.rs.html#1067-1072">source</a><h4 class="code-header">pub fn <a href="#method.get_mut" class="fnname">get_mut</a>(&amp;mut self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;mut </a>T</h4></section></summary><div class="docblock"><p>Returns a mutable reference to the underlying data.</p>
<p>Since this call borrows the <code>RwLock</code> mutably, no actual locking needs to
take place – the mutable borrow statically guarantees no locks exist.</p>
<h5 id="examples-13"><a href="#examples-13">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::sync::RwLock;
<span class="kw">fn </span>main() {
<span class="kw">let </span><span class="kw-2">mut </span>lock = RwLock::new(<span class="number">1</span>);
<span class="kw">let </span>n = lock.get_mut();
<span class="kw-2">*</span>n = <span class="number">2</span>;
}</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.into_inner" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/sync/rwlock.rs.html#1075-1080">source</a><h4 class="code-header">pub fn <a href="#method.into_inner" class="fnname">into_inner</a>(self) -&gt; T<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</span></h4></section></summary><div class="docblock"><p>Consumes the lock, returning the underlying data.</p>
</div></details></div></details></div><h2 id="trait-implementations" class="small-section-header">Trait Implementations<a href="#trait-implementations" class="anchor"></a></h2><div id="trait-implementations-list"><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-Debug-for-RwLock%3CT%3E" class="impl has-srclink"><a class="srclink rightside" href="../../src/tokio/sync/rwlock.rs.html#1098-1110">source</a><a href="#impl-Debug-for-RwLock%3CT%3E" class="anchor"></a><h3 class="code-header">impl&lt;T:&nbsp;?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html" title="trait core::fmt::Debug">Debug</a> for <a class="struct" href="struct.RwLock.html" title="struct tokio::sync::RwLock">RwLock</a>&lt;T&gt;<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html" title="trait core::fmt::Debug">Debug</a>,</span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.fmt" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/tokio/sync/rwlock.rs.html#1102-1109">source</a><a href="#method.fmt" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html#tymethod.fmt" class="fnname">fmt</a>(&amp;self, f: &amp;mut <a class="struct" href="https://doc.rust-lang.org/nightly/core/fmt/struct.Formatter.html" title="struct core::fmt::Formatter">Formatter</a>&lt;'_&gt;) -&gt; <a class="type" href="https://doc.rust-lang.org/nightly/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/nightly/core/fmt/trait.Debug.html#tymethod.fmt">Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-Default-for-RwLock%3CT%3E" class="impl has-srclink"><a class="srclink rightside" href="../../src/tokio/sync/rwlock.rs.html#1089-1096">source</a><a href="#impl-Default-for-RwLock%3CT%3E" class="anchor"></a><h3 class="code-header">impl&lt;T:&nbsp;?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/default/trait.Default.html" title="trait core::default::Default">Default</a> for <a class="struct" href="struct.RwLock.html" title="struct tokio::sync::RwLock">RwLock</a>&lt;T&gt;<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/default/trait.Default.html" title="trait core::default::Default">Default</a>,</span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.default" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/tokio/sync/rwlock.rs.html#1093-1095">source</a><a href="#method.default" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/nightly/core/default/trait.Default.html#tymethod.default" class="fnname">default</a>() -&gt; Self</h4></section></summary><div class='docblock'>Returns the “default value” for a type. <a href="https://doc.rust-lang.org/nightly/core/default/trait.Default.html#tymethod.default">Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-From%3CT%3E-for-RwLock%3CT%3E" class="impl has-srclink"><a class="srclink rightside" href="../../src/tokio/sync/rwlock.rs.html#1083-1087">source</a><a href="#impl-From%3CT%3E-for-RwLock%3CT%3E" class="anchor"></a><h3 class="code-header">impl&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.From.html" title="trait core::convert::From">From</a>&lt;T&gt; for <a class="struct" href="struct.RwLock.html" title="struct tokio::sync::RwLock">RwLock</a>&lt;T&gt;</h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.from" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/tokio/sync/rwlock.rs.html#1084-1086">source</a><a href="#method.from" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/nightly/core/convert/trait.From.html#tymethod.from" class="fnname">from</a>(s: T) -&gt; Self</h4></section></summary><div class='docblock'>Converts to this type from the input type.</div></details></div></details><section id="impl-Send-for-RwLock%3CT%3E" class="impl has-srclink"><a class="srclink rightside" href="../../src/tokio/sync/rwlock.rs.html#149">source</a><a href="#impl-Send-for-RwLock%3CT%3E" class="anchor"></a><h3 class="code-header">impl&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> for <a class="struct" href="struct.RwLock.html" title="struct tokio::sync::RwLock">RwLock</a>&lt;T&gt;<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>,</span></h3></section><section id="impl-Sync-for-RwLock%3CT%3E" class="impl has-srclink"><a class="srclink rightside" href="../../src/tokio/sync/rwlock.rs.html#150">source</a><a href="#impl-Sync-for-RwLock%3CT%3E" class="anchor"></a><h3 class="code-header">impl&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> for <a class="struct" href="struct.RwLock.html" title="struct tokio::sync::RwLock">RwLock</a>&lt;T&gt;<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a>,</span></h3></section></div><h2 id="synthetic-implementations" class="small-section-header">Auto Trait Implementations<a href="#synthetic-implementations" class="anchor"></a></h2><div id="synthetic-implementations-list"><section id="impl-RefUnwindSafe-for-RwLock%3CT%3E" class="impl has-srclink"><a href="#impl-RefUnwindSafe-for-RwLock%3CT%3E" class="anchor"></a><h3 class="code-header">impl&lt;T&gt; !<a class="trait" href="https://doc.rust-lang.org/nightly/core/panic/unwind_safe/trait.RefUnwindSafe.html" title="trait core::panic::unwind_safe::RefUnwindSafe">RefUnwindSafe</a> for <a class="struct" href="struct.RwLock.html" title="struct tokio::sync::RwLock">RwLock</a>&lt;T&gt;</h3></section><section id="impl-Unpin-for-RwLock%3CT%3E" class="impl has-srclink"><a href="#impl-Unpin-for-RwLock%3CT%3E" class="anchor"></a><h3 class="code-header">impl&lt;T:&nbsp;?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a> for <a class="struct" href="struct.RwLock.html" title="struct tokio::sync::RwLock">RwLock</a>&lt;T&gt;<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>,</span></h3></section><section id="impl-UnwindSafe-for-RwLock%3CT%3E" class="impl has-srclink"><a href="#impl-UnwindSafe-for-RwLock%3CT%3E" class="anchor"></a><h3 class="code-header">impl&lt;T:&nbsp;?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/panic/unwind_safe/trait.UnwindSafe.html" title="trait core::panic::unwind_safe::UnwindSafe">UnwindSafe</a> for <a class="struct" href="struct.RwLock.html" title="struct tokio::sync::RwLock">RwLock</a>&lt;T&gt;<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/panic/unwind_safe/trait.UnwindSafe.html" title="trait core::panic::unwind_safe::UnwindSafe">UnwindSafe</a>,</span></h3></section></div><h2 id="blanket-implementations" class="small-section-header">Blanket Implementations<a href="#blanket-implementations" class="anchor"></a></h2><div id="blanket-implementations-list"><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-Any-for-RwLock%3CT%3E" class="impl has-srclink"><a class="srclink rightside" href="https://doc.rust-lang.org/nightly/src/core/any.rs.html#200">source</a><a href="#impl-Any-for-RwLock%3CT%3E" class="anchor"></a><h3 class="code-header">impl&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/any/trait.Any.html" title="trait core::any::Any">Any</a> for T<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: 'static + ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.type_id" class="method trait-impl has-srclink"><a class="srclink rightside" href="https://doc.rust-lang.org/nightly/src/core/any.rs.html#201">source</a><a href="#method.type_id" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/nightly/core/any/trait.Any.html#tymethod.type_id" class="fnname">type_id</a>(&amp;self) -&gt; <a class="struct" href="https://doc.rust-lang.org/nightly/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/nightly/core/any/trait.Any.html#tymethod.type_id">Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-Borrow%3CT%3E-for-RwLock%3CT%3E" class="impl has-srclink"><a class="srclink rightside" href="https://doc.rust-lang.org/nightly/src/core/borrow.rs.html#211">source</a><a href="#impl-Borrow%3CT%3E-for-RwLock%3CT%3E" class="anchor"></a><h3 class="code-header">impl&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/borrow/trait.Borrow.html" title="trait core::borrow::Borrow">Borrow</a>&lt;T&gt; for T<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.borrow" class="method trait-impl has-srclink"><span class="rightside"><span class="since" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/91522" title="Tracking issue for const_borrow">unstable</a></span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/borrow.rs.html#213">source</a></span><a href="#method.borrow" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/nightly/core/borrow/trait.Borrow.html#tymethod.borrow" class="fnname">borrow</a>(&amp;self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;</a>T</h4></section></summary><div class='docblock'>Immutably borrows from an owned value. <a href="https://doc.rust-lang.org/nightly/core/borrow/trait.Borrow.html#tymethod.borrow">Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-BorrowMut%3CT%3E-for-RwLock%3CT%3E" class="impl has-srclink"><a class="srclink rightside" href="https://doc.rust-lang.org/nightly/src/core/borrow.rs.html#220">source</a><a href="#impl-BorrowMut%3CT%3E-for-RwLock%3CT%3E" class="anchor"></a><h3 class="code-header">impl&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/borrow/trait.BorrowMut.html" title="trait core::borrow::BorrowMut">BorrowMut</a>&lt;T&gt; for T<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.borrow_mut" class="method trait-impl has-srclink"><span class="rightside"><span class="since" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/91522" title="Tracking issue for const_borrow">unstable</a></span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/borrow.rs.html#221">source</a></span><a href="#method.borrow_mut" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/nightly/core/borrow/trait.BorrowMut.html#tymethod.borrow_mut" class="fnname">borrow_mut</a>(&amp;mut self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;mut </a>T</h4></section></summary><div class='docblock'>Mutably borrows from an owned value. <a href="https://doc.rust-lang.org/nightly/core/borrow/trait.BorrowMut.html#tymethod.borrow_mut">Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-From%3C!%3E-for-RwLock%3CT%3E" class="impl has-srclink"><a class="srclink rightside" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#751">source</a><a href="#impl-From%3C!%3E-for-RwLock%3CT%3E" class="anchor"></a><h3 class="code-header">impl&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.From.html" title="trait core::convert::From">From</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.never.html">!</a>&gt; for T</h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.from-1" class="method trait-impl has-srclink"><span class="rightside"><span class="since" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/88674" title="Tracking issue for const_convert">unstable</a></span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#752">source</a></span><a href="#method.from-1" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/nightly/core/convert/trait.From.html#tymethod.from" class="fnname">from</a>(t: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.never.html">!</a>) -&gt; T</h4></section></summary><div class='docblock'>Converts to this type from the input type.</div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-From%3CT%3E-for-RwLock%3CT%3E-1" class="impl has-srclink"><a class="srclink rightside" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#733">source</a><a href="#impl-From%3CT%3E-for-RwLock%3CT%3E-1" class="anchor"></a><h3 class="code-header">impl&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.From.html" title="trait core::convert::From">From</a>&lt;T&gt; for T</h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.from-2" class="method trait-impl has-srclink"><span class="rightside"><span class="since" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/88674" title="Tracking issue for const_convert">unstable</a></span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#736">source</a></span><a href="#method.from-2" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/nightly/core/convert/trait.From.html#tymethod.from" class="fnname">from</a>(t: T) -&gt; T</h4></section></summary><div class="docblock"><p>Returns the argument unchanged.</p>
</div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-Into%3CU%3E-for-RwLock%3CT%3E" class="impl has-srclink"><a class="srclink rightside" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#717">source</a><a href="#impl-Into%3CU%3E-for-RwLock%3CT%3E" class="anchor"></a><h3 class="code-header">impl&lt;T, U&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a>&lt;U&gt; for T<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;U: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.From.html" title="trait core::convert::From">From</a>&lt;T&gt;,</span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.into" class="method trait-impl has-srclink"><span class="rightside"><span class="since" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/88674" title="Tracking issue for const_convert">unstable</a></span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#725">source</a></span><a href="#method.into" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/nightly/core/convert/trait.Into.html#tymethod.into" class="fnname">into</a>(self) -&gt; 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/nightly/core/convert/trait.From.html" title="From">From</a>&lt;T&gt; for U</code> chooses to do.</p>
</div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-TryFrom%3CU%3E-for-RwLock%3CT%3E" class="impl has-srclink"><a class="srclink rightside" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#775">source</a><a href="#impl-TryFrom%3CU%3E-for-RwLock%3CT%3E" class="anchor"></a><h3 class="code-header">impl&lt;T, U&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a>&lt;U&gt; for T<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;U: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a>&lt;T&gt;,</span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle" open><summary><section id="associatedtype.Error-1" class="associatedtype trait-impl has-srclink"><a href="#associatedtype.Error-1" class="anchor"></a><h4 class="code-header">type <a href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html#associatedtype.Error" class="associatedtype">Error</a> = <a class="enum" href="https://doc.rust-lang.org/nightly/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="rustdoc-toggle method-toggle" open><summary><section id="method.try_from" class="method trait-impl has-srclink"><span class="rightside"><span class="since" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/88674" title="Tracking issue for const_convert">unstable</a></span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#781">source</a></span><a href="#method.try_from" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html#tymethod.try_from" class="fnname">try_from</a>(value: U) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;T, &lt;T as <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a>&lt;U&gt;&gt;::<a class="associatedtype" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html#associatedtype.Error" title="type core::convert::TryFrom::Error">Error</a>&gt;</h4></section></summary><div class='docblock'>Performs the conversion.</div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-TryInto%3CU%3E-for-RwLock%3CT%3E" class="impl has-srclink"><a class="srclink rightside" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#760">source</a><a href="#impl-TryInto%3CU%3E-for-RwLock%3CT%3E" class="anchor"></a><h3 class="code-header">impl&lt;T, U&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryInto.html" title="trait core::convert::TryInto">TryInto</a>&lt;U&gt; for T<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;U: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a>&lt;T&gt;,</span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle" open><summary><section id="associatedtype.Error" class="associatedtype trait-impl has-srclink"><a href="#associatedtype.Error" class="anchor"></a><h4 class="code-header">type <a href="https://doc.rust-lang.org/nightly/core/convert/trait.TryInto.html#associatedtype.Error" class="associatedtype">Error</a> = &lt;U as <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a>&lt;T&gt;&gt;::<a class="associatedtype" href="https://doc.rust-lang.org/nightly/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="rustdoc-toggle method-toggle" open><summary><section id="method.try_into" class="method trait-impl has-srclink"><span class="rightside"><span class="since" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/88674" title="Tracking issue for const_convert">unstable</a></span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#766">source</a></span><a href="#method.try_into" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/nightly/core/convert/trait.TryInto.html#tymethod.try_into" class="fnname">try_into</a>(self) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;U, &lt;U as <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a>&lt;T&gt;&gt;::<a class="associatedtype" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html#associatedtype.Error" title="type core::convert::TryFrom::Error">Error</a>&gt;</h4></section></summary><div class='docblock'>Performs the conversion.</div></details></div></details></div></section></div></main><div id="rustdoc-vars" data-root-path="../../" data-current-crate="tokio" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.66.0-nightly (5c8bff74b 2022-10-21)" ></div></body></html>