Files
GopherGate/target/doc/tokio/sync/struct.RwLock.html
2026-02-26 12:00:21 -05:00

367 lines
62 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!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."><title>RwLock in tokio::sync - 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="#">RwLock</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="#">RwLock</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.blocking_read" title="blocking_read">blocking_read</a></li><li><a href="#method.blocking_write" title="blocking_write">blocking_write</a></li><li><a href="#method.const_new" title="const_new">const_new</a></li><li><a href="#method.const_with_max_readers" title="const_with_max_readers">const_with_max_readers</a></li><li><a href="#method.get_mut" title="get_mut">get_mut</a></li><li><a href="#method.into_inner" title="into_inner">into_inner</a></li><li><a href="#method.new" title="new">new</a></li><li><a href="#method.read" title="read">read</a></li><li><a href="#method.read_owned" title="read_owned">read_owned</a></li><li><a href="#method.try_read" title="try_read">try_read</a></li><li><a href="#method.try_read_owned" title="try_read_owned">try_read_owned</a></li><li><a href="#method.try_write" title="try_write">try_write</a></li><li><a href="#method.try_write_owned" title="try_write_owned">try_write_owned</a></li><li><a href="#method.with_max_readers" title="with_max_readers">with_max_readers</a></li><li><a href="#method.write" title="write">write</a></li><li><a href="#method.write_owned" title="write_owned">write_owned</a></li></ul><h3><a href="#trait-implementations">Trait Implementations</a></h3><ul class="block trait-implementation"><li><a href="#impl-Debug-for-RwLock%3CT%3E" title="Debug">Debug</a></li><li><a href="#impl-Default-for-RwLock%3CT%3E" title="Default">Default</a></li><li><a href="#impl-From%3CT%3E-for-RwLock%3CT%3E" title="From&#60;T&#62;">From&#60;T&#62;</a></li><li><a href="#impl-Send-for-RwLock%3CT%3E" title="Send">Send</a></li><li><a href="#impl-Sync-for-RwLock%3CT%3E" title="Sync">Sync</a></li></ul><h3><a href="#synthetic-implementations">Auto Trait Implementations</a></h3><ul class="block synthetic-implementation"><li><a href="#impl-Freeze-for-RwLock%3CT%3E" title="!Freeze">!Freeze</a></li><li><a href="#impl-RefUnwindSafe-for-RwLock%3CT%3E" title="!RefUnwindSafe">!RefUnwindSafe</a></li><li><a href="#impl-UnwindSafe-for-RwLock%3CT%3E" title="!UnwindSafe">!UnwindSafe</a></li><li><a href="#impl-Unpin-for-RwLock%3CT%3E" title="Unpin">Unpin</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&#60;T&#62;">Borrow&#60;T&#62;</a></li><li><a href="#impl-BorrowMut%3CT%3E-for-T" title="BorrowMut&#60;T&#62;">BorrowMut&#60;T&#62;</a></li><li><a href="#impl-From%3C!%3E-for-T" title="From&#60;!&#62;">From&#60;!&#62;</a></li><li><a href="#impl-From%3CT%3E-for-T" title="From&#60;T&#62;">From&#60;T&#62;</a></li><li><a href="#impl-Into%3CU%3E-for-T" title="Into&#60;U&#62;">Into&#60;U&#62;</a></li><li><a href="#impl-TryFrom%3CU%3E-for-T" title="TryFrom&#60;U&#62;">TryFrom&#60;U&#62;</a></li><li><a href="#impl-TryInto%3CU%3E-for-T" title="TryInto&#60;U&#62;">TryInto&#60;U&#62;</a></li></ul></section><div id="rustdoc-modnav"><h2><a href="index.html">In tokio::<wbr>sync</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">sync</a></div><h1>Struct <span class="struct">RwLock</span>&nbsp;<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/sync/rwlock.rs.html#88-100">Source</a> </span></div><pre class="rust item-decl"><code>pub struct RwLock&lt;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>&gt; { <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>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" title="struct tokio::sync::Mutex"><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 Tokios 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 librarys
<code>std::sync::RwLock</code>, where the priority policy is dependent on the
operating systems 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/1.93.1/core/marker/trait.Send.html" title="trait core::marker::Send"><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/1.93.1/core/ops/deref/trait.Deref.html" title="trait core::ops::deref::Deref"><code>Deref</code></a>
(and <a href="https://doc.rust-lang.org/1.93.1/core/ops/deref/trait.DerefMut.html" title="trait core::ops::deref::DerefMut"><code>DerefMut</code></a>
for the <code>write</code> methods) to allow access to the content of the lock.</p>
<h2 id="examples"><a class="doc-anchor" href="#examples">§</a>Examples</h2>
<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>);
<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="section-header">Implementations<a href="#implementations" class="anchor">§</a></h2><div id="implementations-list"><details class="toggle implementors-toggle" open><summary><section id="impl-RwLock%3CT%3E" class="impl"><a class="src rightside" href="../../src/tokio/sync/rwlock.rs.html#193-1092">Source</a><a href="#impl-RwLock%3CT%3E" class="anchor">§</a><h3 class="code-header">impl&lt;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>&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="toggle method-toggle" open><summary><section id="method.new" class="method"><a class="src rightside" href="../../src/tokio/sync/rwlock.rs.html#204-254">Source</a><h4 class="code-header">pub fn <a href="#method.new" class="fn">new</a>(value: T) -&gt; <a class="struct" href="struct.RwLock.html" title="struct tokio::sync::RwLock">RwLock</a>&lt;T&gt;<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></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 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::sync::RwLock;
<span class="kw">let </span>lock = RwLock::new(<span class="number">5</span>);</code></pre></div></div></details><details class="toggle method-toggle" open><summary><section id="method.with_max_readers" class="method"><a class="src rightside" href="../../src/tokio/sync/rwlock.rs.html#271-327">Source</a><h4 class="code-header">pub fn <a href="#method.with_max_readers" class="fn">with_max_readers</a>(value: T, max_reads: <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.u32.html">u32</a>) -&gt; <a class="struct" href="struct.RwLock.html" title="struct tokio::sync::RwLock">RwLock</a>&lt;T&gt;<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></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 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::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 class="doc-anchor" href="#panics">§</a>Panics</h5>
<p>Panics if <code>max_reads</code> is more than <code>u32::MAX &gt;&gt; 3</code>.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="method.const_new" class="method"><a class="src rightside" href="../../src/tokio/sync/rwlock.rs.html#347-358">Source</a><h4 class="code-header">pub const fn <a href="#method.const_new" class="fn">const_new</a>(value: T) -&gt; <a class="struct" href="struct.RwLock.html" title="struct tokio::sync::RwLock">RwLock</a>&lt;T&gt;<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></h4></section></summary><div class="docblock"><p>Creates a new instance of an <code>RwLock&lt;T&gt;</code> which is unlocked.</p>
<p>When using the <code>tracing</code> <a href="../index.html#unstable-features" title="mod tokio">unstable feature</a>, a <code>RwLock</code> created with
<code>const_new</code> will not be instrumented. As such, it will not be visible
in <a href="https://github.com/tokio-rs/console"><code>tokio-console</code></a>. Instead, <a href="struct.RwLock.html#method.new" title="associated function tokio::sync::RwLock::new"><code>RwLock::new</code></a> should be used to create
an instrumented object if that is needed.</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::sync::RwLock;
<span class="kw">static </span>LOCK: RwLock&lt;i32&gt; = RwLock::const_new(<span class="number">5</span>);</code></pre></div></div></details><details class="toggle method-toggle" open><summary><section id="method.const_with_max_readers" class="method"><a class="src rightside" href="../../src/tokio/sync/rwlock.rs.html#371-384">Source</a><h4 class="code-header">pub const fn <a href="#method.const_with_max_readers" class="fn">const_with_max_readers</a>(value: T, max_reads: <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.u32.html">u32</a>) -&gt; <a class="struct" href="struct.RwLock.html" title="struct tokio::sync::RwLock">RwLock</a>&lt;T&gt;<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></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-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::sync::RwLock;
<span class="kw">static </span>LOCK: RwLock&lt;i32&gt; = RwLock::const_with_max_readers(<span class="number">5</span>, <span class="number">1024</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/sync/rwlock.rs.html#431-470">Source</a><h4 class="code-header">pub async fn <a href="#method.read" class="fn">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="struct tokio::sync::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 class="doc-anchor" href="#cancel-safety">§</a>Cancel safety</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-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>std::sync::Arc;
<span class="kw">use </span>tokio::sync::RwLock;
<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">"The spawned task has panicked"</span>);
<span class="comment">// Drop the guard after the spawned task finishes.
</span>drop(n);</code></pre></div></div></details><details class="toggle method-toggle" open><summary><section id="method.blocking_read" class="method"><a class="src rightside" href="../../src/tokio/sync/rwlock.rs.html#524-526">Source</a><h4 class="code-header">pub fn <a href="#method.blocking_read" class="fn">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 class="doc-anchor" href="#panics-1">§</a>Panics</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="method tokio::runtime::Handle::spawn_blocking"><code>spawn_blocking()</code></a>
(or <a href="../task/fn.block_in_place.html" title="fn tokio::task::block_in_place"><code>block_in_place()</code></a>).</li>
</ul>
<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>std::sync::Arc;
<span class="kw">use </span>tokio::sync::RwLock;
<span class="attr">#[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="toggle method-toggle" open><summary><section id="method.read_owned" class="method"><a class="src rightside" href="../../src/tokio/sync/rwlock.rs.html#579-621">Source</a><h4 class="code-header">pub async fn <a href="#method.read_owned" class="fn">read_owned</a>(self: <a class="struct" href="https://doc.rust-lang.org/1.93.1/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="method tokio::sync::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/1.93.1/alloc/sync/struct.Arc.html" title="struct alloc::sync::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="struct tokio::sync::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 class="doc-anchor" href="#cancel-safety-1">§</a>Cancel safety</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-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>std::sync::Arc;
<span class="kw">use </span>tokio::sync::RwLock;
<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">"The spawned task has panicked"</span>);
<span class="comment">// Drop the guard after the spawned task finishes.
</span>drop(n);
}</code></pre></div></div></details><details class="toggle method-toggle" open><summary><section id="method.try_read" class="method"><a class="src rightside" href="../../src/tokio/sync/rwlock.rs.html#655-680">Source</a><h4 class="code-header">pub fn <a href="#method.try_read" class="fn">try_read</a>(&amp;self) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.93.1/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 couldnt be acquired immediately, returns <a href="struct.TryLockError.html" title="struct tokio::sync::TryLockError"><code>TryLockError</code></a>.
Otherwise, an RAII guard is returned which will release read access
when dropped.</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>std::sync::Arc;
<span class="kw">use </span>tokio::sync::RwLock;
<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">"The spawned task has panicked"</span>);
<span class="comment">// Drop the guard when spawned task finishes.
</span>drop(v);</code></pre></div></div></details><details class="toggle method-toggle" open><summary><section id="method.try_read_owned" class="method"><a class="src rightside" href="../../src/tokio/sync/rwlock.rs.html#720-745">Source</a><h4 class="code-header">pub fn <a href="#method.try_read_owned" class="fn">try_read_owned</a>(
self: <a class="struct" href="https://doc.rust-lang.org/1.93.1/alloc/sync/struct.Arc.html" title="struct alloc::sync::Arc">Arc</a>&lt;Self&gt;,
) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.93.1/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 couldnt be acquired immediately, returns <a href="struct.TryLockError.html" title="struct tokio::sync::TryLockError"><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="method tokio::sync::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/1.93.1/alloc/sync/struct.Arc.html" title="struct alloc::sync::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-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>std::sync::Arc;
<span class="kw">use </span>tokio::sync::RwLock;
<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">"The spawned task has panicked"</span>);
<span class="comment">// Drop the guard when spawned task finishes.
</span>drop(v);</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/sync/rwlock.rs.html#775-815">Source</a><h4 class="code-header">pub async fn <a href="#method.write" class="fn">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 class="doc-anchor" href="#cancel-safety-2">§</a>Cancel safety</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-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::sync::RwLock;
<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="toggle method-toggle" open><summary><section id="method.blocking_write" class="method"><a class="src rightside" href="../../src/tokio/sync/rwlock.rs.html#871-873">Source</a><h4 class="code-header">pub fn <a href="#method.blocking_write" class="fn">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 class="doc-anchor" href="#panics-2">§</a>Panics</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="method tokio::runtime::Handle::spawn_blocking"><code>spawn_blocking()</code></a>
(or <a href="../task/fn.block_in_place.html" title="fn tokio::task::block_in_place"><code>block_in_place()</code></a>).</li>
</ul>
<h5 id="examples-11"><a class="doc-anchor" href="#examples-11">§</a>Examples</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="attr">#[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="toggle method-toggle" open><summary><section id="method.write_owned" class="method"><a class="src rightside" href="../../src/tokio/sync/rwlock.rs.html#910-953">Source</a><h4 class="code-header">pub async fn <a href="#method.write_owned" class="fn">write_owned</a>(self: <a class="struct" href="https://doc.rust-lang.org/1.93.1/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="method tokio::sync::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/1.93.1/alloc/sync/struct.Arc.html" title="struct alloc::sync::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 class="doc-anchor" href="#cancel-safety-3">§</a>Cancel safety</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-12"><a class="doc-anchor" href="#examples-12">§</a>Examples</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="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="toggle method-toggle" open><summary><section id="method.try_write" class="method"><a class="src rightside" href="../../src/tokio/sync/rwlock.rs.html#978-1004">Source</a><h4 class="code-header">pub fn <a href="#method.try_write" class="fn">try_write</a>(&amp;self) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.93.1/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 couldnt be acquired immediately, returns <a href="struct.TryLockError.html" title="struct tokio::sync::TryLockError"><code>TryLockError</code></a>.
Otherwise, an RAII guard is returned which will release write access
when dropped.</p>
<h5 id="examples-13"><a class="doc-anchor" href="#examples-13">§</a>Examples</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>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="toggle method-toggle" open><summary><section id="method.try_write_owned" class="method"><a class="src rightside" href="../../src/tokio/sync/rwlock.rs.html#1036-1062">Source</a><h4 class="code-header">pub fn <a href="#method.try_write_owned" class="fn">try_write_owned</a>(
self: <a class="struct" href="https://doc.rust-lang.org/1.93.1/alloc/sync/struct.Arc.html" title="struct alloc::sync::Arc">Arc</a>&lt;Self&gt;,
) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.93.1/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 couldnt be acquired immediately, returns <a href="struct.TryLockError.html" title="struct tokio::sync::TryLockError"><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="method tokio::sync::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/1.93.1/alloc/sync/struct.Arc.html" title="struct alloc::sync::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-14"><a class="doc-anchor" href="#examples-14">§</a>Examples</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="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="toggle method-toggle" open><summary><section id="method.get_mut" class="method"><a class="src rightside" href="../../src/tokio/sync/rwlock.rs.html#1081-1083">Source</a><h4 class="code-header">pub fn <a href="#method.get_mut" class="fn">get_mut</a>(&amp;mut self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.reference.html">&amp;mut T</a></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-15"><a class="doc-anchor" href="#examples-15">§</a>Examples</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="toggle method-toggle" open><summary><section id="method.into_inner" class="method"><a class="src rightside" href="../../src/tokio/sync/rwlock.rs.html#1086-1091">Source</a><h4 class="code-header">pub fn <a href="#method.into_inner" class="fn">into_inner</a>(self) -&gt; 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></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="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-Debug-for-RwLock%3CT%3E" class="impl"><a class="src rightside" href="../../src/tokio/sync/rwlock.rs.html#1109-1121">Source</a><a href="#impl-Debug-for-RwLock%3CT%3E" class="anchor">§</a><h3 class="code-header">impl&lt;T&gt; <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.RwLock.html" title="struct tokio::sync::RwLock">RwLock</a>&lt;T&gt;<div class="where">where
T: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/fmt/trait.Debug.html" title="trait core::fmt::Debug">Debug</a> + ?<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.fmt" class="method trait-impl"><a class="src rightside" href="../../src/tokio/sync/rwlock.rs.html#1113-1120">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>(&amp;self, f: &amp;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>&lt;'_&gt;) -&gt; <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-RwLock%3CT%3E" class="impl"><a class="src rightside" href="../../src/tokio/sync/rwlock.rs.html#1100-1107">Source</a><a href="#impl-Default-for-RwLock%3CT%3E" class="anchor">§</a><h3 class="code-header">impl&lt;T&gt; <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.RwLock.html" title="struct tokio::sync::RwLock">RwLock</a>&lt;T&gt;<div class="where">where
T: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/default/trait.Default.html" title="trait core::default::Default">Default</a>,</div></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/sync/rwlock.rs.html#1104-1106">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>() -&gt; 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%3CT%3E-for-RwLock%3CT%3E" class="impl"><a class="src rightside" href="../../src/tokio/sync/rwlock.rs.html#1094-1098">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/1.93.1/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="toggle method-toggle" open><summary><section id="method.from" class="method trait-impl"><a class="src rightside" href="../../src/tokio/sync/rwlock.rs.html#1095-1097">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>(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"><a class="src 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/1.93.1/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;<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> + <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>,</div></h3></section><section id="impl-Sync-for-RwLock%3CT%3E" class="impl"><a class="src 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/1.93.1/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;<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> + <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> + <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a>,</div></h3></section></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-RwLock%3CT%3E" class="impl"><a href="#impl-Freeze-for-RwLock%3CT%3E" class="anchor">§</a><h3 class="code-header">impl&lt;T&gt; !<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.RwLock.html" title="struct tokio::sync::RwLock">RwLock</a>&lt;T&gt;</h3></section><section id="impl-RefUnwindSafe-for-RwLock%3CT%3E" class="impl"><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/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.RwLock.html" title="struct tokio::sync::RwLock">RwLock</a>&lt;T&gt;</h3></section><section id="impl-Unpin-for-RwLock%3CT%3E" class="impl"><a href="#impl-Unpin-for-RwLock%3CT%3E" class="anchor">§</a><h3 class="code-header">impl&lt;T&gt; <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.RwLock.html" title="struct tokio::sync::RwLock">RwLock</a>&lt;T&gt;<div class="where">where
T: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a> + ?<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><section id="impl-UnwindSafe-for-RwLock%3CT%3E" class="impl"><a href="#impl-UnwindSafe-for-RwLock%3CT%3E" class="anchor">§</a><h3 class="code-header">impl&lt;T&gt; !<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.RwLock.html" title="struct tokio::sync::RwLock">RwLock</a>&lt;T&gt;</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&lt;T&gt; <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>(&amp;self) -&gt; <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&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/borrow/trait.Borrow.html" title="trait core::borrow::Borrow">Borrow</a>&lt;T&gt; 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>(&amp;self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.reference.html">&amp;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&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/borrow/trait.BorrowMut.html" title="trait core::borrow::BorrowMut">BorrowMut</a>&lt;T&gt; 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>(&amp;mut self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.reference.html">&amp;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-From%3C!%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.93.1/src/core/convert/mod.rs.html#802">Source</a><a href="#impl-From%3C!%3E-for-T" class="anchor">§</a><h3 class="code-header">impl&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/convert/trait.From.html" title="trait core::convert::From">From</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.never.html">!</a>&gt; for T</h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.from-2" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.93.1/src/core/convert/mod.rs.html#803">Source</a><a href="#method.from-2" 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: <a class="primitive" href="https://doc.rust-lang.org/1.93.1/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="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&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/1.93.1/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="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) -&gt; 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&lt;T, U&gt; <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a>&lt;U&gt; 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>&lt;T&gt;,</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) -&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/1.93.1/core/convert/trait.From.html" title="trait core::convert::From">From</a>&lt;T&gt; for U</code> chooses to do.</p>
</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&lt;T, U&gt; <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a>&lt;U&gt; 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>&lt;T&gt;,</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) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.93.1/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/1.93.1/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/1.93.1/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="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&lt;T, U&gt; <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/convert/trait.TryInto.html" title="trait core::convert::TryInto">TryInto</a>&lt;U&gt; 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>&lt;T&gt;,</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> = &lt;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>&lt;T&gt;&gt;::<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) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.93.1/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/1.93.1/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/1.93.1/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></body></html>