-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto-generated documentation 6ab6e1b
- Loading branch information
0 parents
commit 4be14cb
Showing
14,460 changed files
with
589,601 additions
and
0 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
There are no files selected for viewing
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<!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="Abstracting over accessing parts of stored value."><title>arc_swap::access - Rust</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/SourceSerif4-Regular-46f98efaafac5295.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/FiraSans-Regular-018c141bf0843ffd.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/FiraSans-Medium-8f9a781e4970d388.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/SourceSerif4-Bold-a2c9cd1067f8b328.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2"><link rel="stylesheet" href="../../static.files/normalize-76eba96aa4d2e634.css"><link rel="stylesheet" href="../../static.files/rustdoc-cb6f1f67f1bcd037.css" id="mainThemeStyle"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="arc_swap" data-themes="" data-resource-suffix="" data-rustdoc-version="1.73.0-nightly (e4c144684 2023-08-04)" data-channel="nightly" data-search-js="search-6dfdfced5eff6596.js" data-settings-js="settings-de11bff964e9d4e5.js" data-settings-css="settings-8c76f75bfb6bd192.css" data-theme-light-css="light-6d2c9675f3d09c26.css" data-theme-dark-css="dark-45ceb8f2e522f4d1.css" data-theme-ayu-css="ayu-fd19013d6ce078bf.css" ><script src="../../static.files/storage-db41da1a38ea3cb8.js"></script><script defer src="../../static.files/main-0795b7d26be81095.js"></script><noscript><link rel="stylesheet" media="(prefers-color-scheme:light)" href="../../static.files/light-6d2c9675f3d09c26.css"><link rel="stylesheet" media="(prefers-color-scheme:dark)" href="../../static.files/dark-45ceb8f2e522f4d1.css"><link rel="stylesheet" href="../../static.files/noscript-cffde32267a19fd6.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-16x16-8b506e7a72182f1c.png"><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-422f7d1d52889060.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-2c020d218678b618.svg"></head><body class="rustdoc mod"><!--[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">☰</button><a class="logo-container" href="../../arc_swap/index.html"><img class="rust-logo" src="../../static.files/rust-logo-151179464ae7ed46.svg" alt="logo"></a><h2></h2></nav><nav class="sidebar"><a class="logo-container" href="../../arc_swap/index.html"><img class="rust-logo" src="../../static.files/rust-logo-151179464ae7ed46.svg" alt="logo"></a><h2 class="location"><a href="#">Module access</a></h2><div class="sidebar-elems"><section><ul class="block"><li><a href="#structs">Structs</a></li><li><a href="#traits">Traits</a></li></ul></section></div></nav><main><div class="width-limiter"><nav class="sub"><form class="search-form"><span></span><input class="search-input" name="search" aria-label="Run search in the documentation" 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="../../static.files/wheel-7b819b6101059cd0.svg"></a></div></form></nav><section id="main-content" class="content"><div class="main-heading"><h1>Module <a href="../index.html">arc_swap</a>::<wbr><a class="mod" href="#">access</a><button id="copy-path" title="Copy item path to clipboard"><img src="../../static.files/clipboard-7571035ce49a181d.svg" width="19" height="18" alt="Copy item path"></button></h1><span class="out-of-band"><a class="src" href="../../src/arc_swap/access.rs.html#1-544">source</a> · <button id="toggle-all-docs" title="collapse all docs">[<span>−</span>]</button></span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Abstracting over accessing parts of stored value.</p> | ||
<p>Sometimes, there’s a big globalish data structure (like a configuration for the whole program). | ||
Then there are parts of the program that need access to up-to-date version of their <em>part</em> of | ||
the configuration, but for reasons of code separation and reusability, it is not desirable to | ||
pass the whole configuration to each of the parts.</p> | ||
<p>This module provides means to grant the parts access to the relevant subsets of such global | ||
data structure while masking the fact it is part of the bigger whole from the component.</p> | ||
<p>Note that the <a href="../cache/index.html" title="mod arc_swap::cache"><code>cache</code></a> module has its own <a href="../cache/trait.Access.html" title="trait arc_swap::cache::Access"><code>Access</code></a> trait | ||
that serves a similar purpose, but with cached access. The signatures are different, therefore | ||
an incompatible trait.</p> | ||
<h2 id="the-general-idea"><a href="#the-general-idea">The general idea</a></h2> | ||
<p>Each part of the code accepts generic <a href="trait.Access.html" title="trait arc_swap::access::Access"><code>Access<T></code></a> for the <code>T</code> of its interest. This | ||
provides means to load current version of the structure behind the scenes and get only the | ||
relevant part, without knowing what the big structure is.</p> | ||
<p>For technical reasons, the <a href="trait.Access.html" title="trait arc_swap::access::Access"><code>Access</code></a> trait is not object safe. If type erasure is desired, it | ||
is possible use the <a href="trait.DynAccess.html" title="trait arc_swap::access::DynAccess"><code>DynAccess</code></a> instead, which is object safe, but | ||
slightly slower.</p> | ||
<p>For some cases, it is possible to use <a href="../struct.ArcSwapAny.html#method.map" title="method arc_swap::ArcSwapAny::map"><code>ArcSwapAny::map</code></a>. If that is not flexible enough, the | ||
<a href="struct.Map.html" title="struct arc_swap::access::Map"><code>Map</code></a> type can be created directly.</p> | ||
<p>Note that the <a href="trait.Access.html" title="trait arc_swap::access::Access"><code>Access</code></a> trait is also implemented for <a href="../struct.ArcSwapAny.html" title="struct arc_swap::ArcSwapAny"><code>ArcSwapAny</code></a> itself. Additionally, | ||
there’s the <a href="struct.Constant.html" title="struct arc_swap::access::Constant"><code>Constant</code></a> helper type, which is useful mostly for | ||
testing (it doesn’t allow reloading).</p> | ||
<h2 id="performance"><a href="#performance">Performance</a></h2> | ||
<p>In general, these utilities use <a href="../struct.ArcSwapAny.html#method.load" title="method arc_swap::ArcSwapAny::load"><code>ArcSwapAny::load</code></a> internally and then apply the provided | ||
transformation. This has several consequences:</p> | ||
<ul> | ||
<li>Limitations of the <a href="../struct.ArcSwapAny.html#method.load" title="method arc_swap::ArcSwapAny::load"><code>load</code></a> apply ‒ including the recommendation to not | ||
hold the returned guard object for too long, but long enough to get consistency.</li> | ||
<li>The transformation should be cheap ‒ optimally just borrowing into the structure.</li> | ||
</ul> | ||
<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>std::sync::Arc; | ||
<span class="kw">use </span>std::thread::{<span class="self">self</span>, JoinHandle}; | ||
<span class="kw">use </span>std::time::Duration; | ||
|
||
<span class="kw">use </span>arc_swap::ArcSwap; | ||
<span class="kw">use </span>arc_swap::access::{Access, Constant, Map}; | ||
|
||
<span class="kw">fn </span>work_with_usize<A: Access<usize> + Send + <span class="lifetime">'static</span>>(a: A) -> JoinHandle<()> { | ||
thread::spawn(<span class="kw">move </span>|| { | ||
<span class="kw">let </span><span class="kw-2">mut </span>value = <span class="number">0</span>; | ||
<span class="kw">while </span>value != <span class="number">42 </span>{ | ||
<span class="kw">let </span>guard = a.load(); | ||
value = <span class="kw-2">*</span>guard; | ||
<span class="macro">println!</span>(<span class="string">"{}"</span>, value); | ||
<span class="comment">// Not strictly necessary, but dropping the guard can free some resources, like | ||
// slots for tracking what values are still in use. We do it before the sleeping, | ||
// not at the end of the scope. | ||
</span>drop(guard); | ||
thread::sleep(Duration::from_millis(<span class="number">50</span>)); | ||
} | ||
}) | ||
} | ||
|
||
<span class="comment">// Passing the whole thing directly | ||
// (If we kept another Arc to it, we could change the value behind the scenes) | ||
</span>work_with_usize(Arc::new(ArcSwap::from_pointee(<span class="number">42</span>))).join().unwrap(); | ||
|
||
<span class="comment">// Passing a subset of a structure | ||
</span><span class="kw">struct </span>Cfg { | ||
value: usize, | ||
} | ||
|
||
<span class="kw">let </span>cfg = Arc::new(ArcSwap::from_pointee(Cfg { value: <span class="number">0 </span>})); | ||
<span class="kw">let </span>thread = work_with_usize(Map::new(Arc::clone(<span class="kw-2">&</span>cfg), |cfg: <span class="kw-2">&</span>Cfg| <span class="kw-2">&</span>cfg.value)); | ||
cfg.store(Arc::new(Cfg { value: <span class="number">42 </span>})); | ||
thread.join().unwrap(); | ||
|
||
<span class="comment">// Passing a constant that can't change. Useful mostly for testing purposes. | ||
</span>work_with_usize(Constant(<span class="number">42</span>)).join().unwrap();</code></pre></div> | ||
</div></details><h2 id="structs" class="small-section-header"><a href="#structs">Structs</a></h2><ul class="item-table"><li><div class="item-name"><a class="struct" href="struct.AccessConvert.html" title="struct arc_swap::access::AccessConvert">AccessConvert</a></div><div class="desc docblock-short"><a href="trait.DynAccess.html" title="trait arc_swap::access::DynAccess">DynAccess</a> to <a href="trait.Access.html" title="trait arc_swap::access::Access">Access</a> wrapper.</div></li><li><div class="item-name"><a class="struct" href="struct.Constant.html" title="struct arc_swap::access::Constant">Constant</a></div><div class="desc docblock-short">Access to an constant.</div></li><li><div class="item-name"><a class="struct" href="struct.Map.html" title="struct arc_swap::access::Map">Map</a></div><div class="desc docblock-short">An adaptor to provide access to a part of larger structure.</div></li></ul><h2 id="traits" class="small-section-header"><a href="#traits">Traits</a></h2><ul class="item-table"><li><div class="item-name"><a class="trait" href="trait.Access.html" title="trait arc_swap::access::Access">Access</a></div><div class="desc docblock-short">Abstracts over ways code can get access to a value of type <code>T</code>.</div></li><li><div class="item-name"><a class="trait" href="trait.DynAccess.html" title="trait arc_swap::access::DynAccess">DynAccess</a></div><div class="desc docblock-short">An object-safe version of the <a href="trait.Access.html" title="trait arc_swap::access::Access"><code>Access</code></a> trait.</div></li></ul></section></div></main></body></html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
window.SIDEBAR_ITEMS = {"struct":["AccessConvert","Constant","Map"],"trait":["Access","DynAccess"]}; |
Oops, something went wrong.