178 lines
No EOL
9.9 KiB
HTML
178 lines
No EOL
9.9 KiB
HTML
<!DOCTYPE html>
|
||
<html lang="en">
|
||
<head>
|
||
<meta charset="utf-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
<meta name="generator" content="rustdoc">
|
||
<meta name="description" content="API documentation for the Rust `ScopedKey` struct in crate `bitflags`.">
|
||
<meta name="keywords" content="rust, rustlang, rust-lang, ScopedKey">
|
||
|
||
<title>bitflags::__core::thread::ScopedKey - Rust</title>
|
||
|
||
<link rel="stylesheet" type="text/css" href="../../../rustdoc.css">
|
||
<link rel="stylesheet" type="text/css" href="../../../main.css">
|
||
|
||
|
||
|
||
|
||
</head>
|
||
<body class="rustdoc">
|
||
<!--[if lte IE 8]>
|
||
<div class="warning">
|
||
This old browser is unsupported and will most likely display funky
|
||
things.
|
||
</div>
|
||
<![endif]-->
|
||
|
||
|
||
|
||
<nav class="sidebar">
|
||
|
||
<p class='location'><a href='../../index.html'>bitflags</a>::<wbr><a href='../index.html'>__core</a>::<wbr><a href='index.html'>thread</a></p><script>window.sidebarCurrent = {name: 'ScopedKey', ty: 'struct', relpath: ''};</script><script defer src="sidebar-items.js"></script>
|
||
</nav>
|
||
|
||
<nav class="sub">
|
||
<form class="search-form js-only">
|
||
<div class="search-container">
|
||
<input class="search-input" name="search"
|
||
autocomplete="off"
|
||
placeholder="Click or press ‘S’ to search, ‘?’ for more options…"
|
||
type="search">
|
||
</div>
|
||
</form>
|
||
</nav>
|
||
|
||
<section id='main' class="content struct">
|
||
<h1 class='fqn'><span class='in-band'>Struct <a href='../../index.html'>bitflags</a>::<wbr><a href='../index.html'>__core</a>::<wbr><a href='index.html'>thread</a>::<wbr><a class='struct' href=''>ScopedKey</a></span><span class='out-of-band'><span id='render-detail'>
|
||
<a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">
|
||
[<span class='inner'>−</span>]
|
||
</a>
|
||
</span><a id='src-898' class='srclink' href='https://doc.rust-lang.org/nightly/std/thread/scoped_tls/struct.ScopedKey.html?gotosrc=898' title='goto source code'>[src]</a></span></h1>
|
||
<pre class='rust struct'>pub struct ScopedKey<T> <span class='where'>where T: 'static</span> {
|
||
// some fields omitted
|
||
}</pre><div class='stability'><em class='stab deprecated'>Deprecated since 1.8.0<p>: hasn't proven itself over LocalKey</p>
|
||
</em></div><div class='stability'><em class='stab unstable'>Unstable (<code>scoped_tls</code>)<p>: hasn't proven itself over LocalKey</p>
|
||
</em></div><div class='docblock'><p>Type representing a thread local storage key corresponding to a reference
|
||
to the type parameter <code>T</code>.</p>
|
||
|
||
<p>Keys are statically allocated and can contain a reference to an instance of
|
||
type <code>T</code> scoped to a particular lifetime. Keys provides two methods, <code>set</code>
|
||
and <code>with</code>, both of which currently use closures to control the scope of
|
||
their contents.</p>
|
||
</div><h2 id='methods'>Methods</h2><h3 class='impl'><code>impl<T> <a class='struct' href='../../../bitflags/__core/thread/struct.ScopedKey.html' title='bitflags::__core::thread::ScopedKey'>ScopedKey</a><T></code></h3><div class='impl-items'><h4 id='method.set' class='method'><code>fn <a href='#method.set' class='fnname'>set</a><R, F>(&'static self, t: &T, cb: F) -> R <span class='where'>where F: <a class='trait' href='../../../bitflags/__core/ops/trait.FnOnce.html' title='bitflags::__core::ops::FnOnce'>FnOnce</a>() -> R</span></code></h4>
|
||
<div class='stability'><em class='stab deprecated'>Deprecated since 1.8.0<p>: hasn't proven itself over LocalKey</p>
|
||
</em></div><div class='stability'><em class='stab unstable'>Unstable (<code>scoped_tls</code>)<p>: hasn't proven itself over LocalKey</p>
|
||
</em></div><div class='docblock'><p>Inserts a value into this scoped thread local storage slot for a
|
||
duration of a closure.</p>
|
||
|
||
<p>While <code>cb</code> is running, the value <code>t</code> will be returned by <code>get</code> unless
|
||
this function is called recursively inside of <code>cb</code>.</p>
|
||
|
||
<p>Upon return, this function will restore the previous value, if any
|
||
was available.</p>
|
||
|
||
<h1 id='examples' class='section-header'><a href='#examples'>Examples</a></h1>
|
||
<pre class='rust rust-example-rendered'>
|
||
<span class='attribute'>#<span class='op'>!</span>[<span class='ident'>feature</span>(<span class='ident'>scoped_tls</span>)]</span>
|
||
|
||
<span class='macro'>scoped_thread_local</span><span class='macro'>!</span>(<span class='kw'>static</span> <span class='ident'>FOO</span>: <span class='ident'>u32</span>);
|
||
|
||
<span class='ident'>FOO</span>.<span class='ident'>set</span>(<span class='kw-2'>&</span><span class='number'>100</span>, <span class='op'>||</span> {
|
||
<span class='kw'>let</span> <span class='ident'>val</span> <span class='op'>=</span> <span class='ident'>FOO</span>.<span class='ident'>with</span>(<span class='op'>|</span><span class='ident'>v</span><span class='op'>|</span> <span class='op'>*</span><span class='ident'>v</span>);
|
||
<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>val</span>, <span class='number'>100</span>);
|
||
|
||
<span class='comment'>// set can be called recursively</span>
|
||
<span class='ident'>FOO</span>.<span class='ident'>set</span>(<span class='kw-2'>&</span><span class='number'>101</span>, <span class='op'>||</span> {
|
||
<span class='comment'>// ...</span>
|
||
});
|
||
|
||
<span class='comment'>// Recursive calls restore the previous value.</span>
|
||
<span class='kw'>let</span> <span class='ident'>val</span> <span class='op'>=</span> <span class='ident'>FOO</span>.<span class='ident'>with</span>(<span class='op'>|</span><span class='ident'>v</span><span class='op'>|</span> <span class='op'>*</span><span class='ident'>v</span>);
|
||
<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>val</span>, <span class='number'>100</span>);
|
||
});</pre>
|
||
</div><h4 id='method.with' class='method'><code>fn <a href='#method.with' class='fnname'>with</a><R, F>(&'static self, cb: F) -> R <span class='where'>where F: <a class='trait' href='../../../bitflags/__core/ops/trait.FnOnce.html' title='bitflags::__core::ops::FnOnce'>FnOnce</a>(&T) -> R</span></code></h4>
|
||
<div class='stability'><em class='stab deprecated'>Deprecated since 1.8.0<p>: hasn't proven itself over LocalKey</p>
|
||
</em></div><div class='stability'><em class='stab unstable'>Unstable (<code>scoped_tls</code>)<p>: hasn't proven itself over LocalKey</p>
|
||
</em></div><div class='docblock'><p>Gets a value out of this scoped variable.</p>
|
||
|
||
<p>This function takes a closure which receives the value of this
|
||
variable.</p>
|
||
|
||
<h1 id='panics' class='section-header'><a href='#panics'>Panics</a></h1>
|
||
<p>This function will panic if <code>set</code> has not previously been called.</p>
|
||
|
||
<h1 id='examples-1' class='section-header'><a href='#examples-1'>Examples</a></h1>
|
||
<pre class='rust rust-example-rendered'>
|
||
<span class='attribute'>#<span class='op'>!</span>[<span class='ident'>feature</span>(<span class='ident'>scoped_tls</span>)]</span>
|
||
|
||
<span class='macro'>scoped_thread_local</span><span class='macro'>!</span>(<span class='kw'>static</span> <span class='ident'>FOO</span>: <span class='ident'>u32</span>);
|
||
|
||
<span class='ident'>FOO</span>.<span class='ident'>with</span>(<span class='op'>|</span><span class='ident'>slot</span><span class='op'>|</span> {
|
||
<span class='comment'>// work with `slot`</span>
|
||
});</pre>
|
||
</div><h4 id='method.is_set' class='method'><code>fn <a href='#method.is_set' class='fnname'>is_set</a>(&'static self) -> <a class='primitive' href='https://doc.rust-lang.org/nightly/bitflags/primitive.bool.html'>bool</a></code></h4>
|
||
<div class='stability'><em class='stab deprecated'>Deprecated since 1.8.0<p>: hasn't proven itself over LocalKey</p>
|
||
</em></div><div class='stability'><em class='stab unstable'>Unstable (<code>scoped_tls</code>)<p>: hasn't proven itself over LocalKey</p>
|
||
</em></div><div class='docblock'><p>Test whether this TLS key has been <code>set</code> for the current thread.</p>
|
||
</div></div></section>
|
||
<section id='search' class="content hidden"></section>
|
||
|
||
<section class="footer"></section>
|
||
|
||
<aside id="help" class="hidden">
|
||
<div>
|
||
<h1 class="hidden">Help</h1>
|
||
|
||
<div class="shortcuts">
|
||
<h2>Keyboard Shortcuts</h2>
|
||
|
||
<dl>
|
||
<dt>?</dt>
|
||
<dd>Show this help dialog</dd>
|
||
<dt>S</dt>
|
||
<dd>Focus the search field</dd>
|
||
<dt>⇤</dt>
|
||
<dd>Move up in search results</dd>
|
||
<dt>⇥</dt>
|
||
<dd>Move down in search results</dd>
|
||
<dt>⏎</dt>
|
||
<dd>Go to active search result</dd>
|
||
</dl>
|
||
</div>
|
||
|
||
<div class="infos">
|
||
<h2>Search Tricks</h2>
|
||
|
||
<p>
|
||
Prefix searches with a type followed by a colon (e.g.
|
||
<code>fn:</code>) to restrict the search to a given type.
|
||
</p>
|
||
|
||
<p>
|
||
Accepted types are: <code>fn</code>, <code>mod</code>,
|
||
<code>struct</code>, <code>enum</code>,
|
||
<code>trait</code>, <code>type</code>, <code>macro</code>,
|
||
and <code>const</code>.
|
||
</p>
|
||
|
||
<p>
|
||
Search functions by type signature (e.g.
|
||
<code>vec -> usize</code> or <code>* -> vec</code>)
|
||
</p>
|
||
</div>
|
||
</div>
|
||
</aside>
|
||
|
||
|
||
|
||
<script>
|
||
window.rootPath = "../../../";
|
||
window.currentCrate = "bitflags";
|
||
window.playgroundUrl = "";
|
||
</script>
|
||
<script src="../../../jquery.js"></script>
|
||
<script src="../../../main.js"></script>
|
||
|
||
<script defer src="../../../search-index.js"></script>
|
||
</body>
|
||
</html> |