Files
phy/atomic_float/struct.AtomicF32.html
Orion Kindel 0ce894e6b0 doc
2025-03-18 10:30:23 -05:00

361 lines
71 KiB
HTML
Raw Permalink 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="A floating point type which can be safely shared between threads."><title>AtomicF32 in atomic_float - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.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" crossorigin href="../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="atomic_float" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.0 (9fc6b4312 2025-01-07)" data-channel="1.84.0" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../static.files/storage-59e33391.js"></script><script defer src="sidebar-items.js"></script><script defer src="../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../static.files/favicon-32x32-6580c154.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]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../atomic_float/index.html">atomic_<wbr>float</a><span class="version">1.1.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Atomic<wbr>F32</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#example" title="Example">Example</a></li><li><a href="#implementation" title="Implementation">Implementation</a></li></ul><h3><a href="#implementations">Methods</a></h3><ul class="block method"><li><a href="#method.as_atomic_bits" title="as_atomic_bits">as_atomic_bits</a></li><li><a href="#method.compare_and_swap" title="compare_and_swap">compare_and_swap</a></li><li><a href="#method.compare_exchange" title="compare_exchange">compare_exchange</a></li><li><a href="#method.compare_exchange_weak" title="compare_exchange_weak">compare_exchange_weak</a></li><li><a href="#method.fetch_abs" title="fetch_abs">fetch_abs</a></li><li><a href="#method.fetch_add" title="fetch_add">fetch_add</a></li><li><a href="#method.fetch_max" title="fetch_max">fetch_max</a></li><li><a href="#method.fetch_min" title="fetch_min">fetch_min</a></li><li><a href="#method.fetch_neg" title="fetch_neg">fetch_neg</a></li><li><a href="#method.fetch_sub" title="fetch_sub">fetch_sub</a></li><li><a href="#method.fetch_update" title="fetch_update">fetch_update</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.load" title="load">load</a></li><li><a href="#method.new" title="new">new</a></li><li><a href="#method.store" title="store">store</a></li><li><a href="#method.swap" title="swap">swap</a></li></ul><h3><a href="#trait-implementations">Trait Implementations</a></h3><ul class="block trait-implementation"><li><a href="#impl-Debug-for-AtomicF32" title="Debug">Debug</a></li><li><a href="#impl-Default-for-AtomicF32" title="Default">Default</a></li><li><a href="#impl-From%3Cf32%3E-for-AtomicF32" title="From&#60;f32&#62;">From&#60;f32&#62;</a></li><li><a href="#impl-PartialEq-for-AtomicF32" title="PartialEq">PartialEq</a></li><li><a href="#impl-Send-for-AtomicF32" title="Send">Send</a></li><li><a href="#impl-Sync-for-AtomicF32" 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-AtomicF32" title="!Freeze">!Freeze</a></li><li><a href="#impl-RefUnwindSafe-for-AtomicF32" title="!RefUnwindSafe">!RefUnwindSafe</a></li><li><a href="#impl-Unpin-for-AtomicF32" title="Unpin">Unpin</a></li><li><a href="#impl-UnwindSafe-for-AtomicF32" title="UnwindSafe">UnwindSafe</a></li></ul><h3><a href="#blanket-implementations">Blanket Implementations</a></h3><ul class="block blanket-implementation"><li><a href="#impl-Any-for-T" title="Any">Any</a></li><li><a href="#impl-Borrow%3CT%3E-for-T" title="Borrow&#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%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 class="in-crate"><a href="index.html">In crate atomic_<wbr>float</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="index.html">atomic_float</a></span><h1>Struct <span class="struct">AtomicF32</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../src/atomic_float/atomic_f32.rs.html#63-67">Source</a> </span></div><pre class="rust item-decl"><code>pub struct AtomicF32(<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>A floating point type which can be safely shared between threads.</p>
<p>This type has the same in-memory representation as the underlying floating
point type, <a href="https://doc.rust-lang.org/1.84.0/core/primitive.f32.html" title="primitive f32"><code>f32</code></a>.</p>
<p>See the module documentation for <a href="https://doc.rust-lang.org/1.84.0/core/sync/atomic/index.html" title="mod core::sync::atomic">core::sync::atomic</a> for information about
the portability of various atomics (this one is mostly as portable as
<a href="https://doc.rust-lang.org/1.84.0/core/sync/atomic/struct.AtomicU32.html" title="struct core::sync::atomic::AtomicU32"><code>AtomicU32</code></a>, with the caveat that we
additionally that the platform support 32-bit floats).</p>
<h2 id="example"><a class="doc-anchor" href="#example">§</a>Example</h2>
<p>The intended use case is situations like this:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">static </span>DELTA_TIME: AtomicF32 = AtomicF32::new(<span class="number">1.0</span>);
<span class="comment">// In some main simulation loop:
</span>DELTA_TIME.store(compute_delta_time(), Ordering::Release);
<span class="comment">// elsewhere, perhaps on other threads:
</span><span class="kw">let </span>dt = DELTA_TIME.load(Ordering::Acquire);
<span class="comment">// Use `dt` to compute simulation...</span></code></pre></div>
<p>As well as any other cases where use of locking would be too substantial of
overhead.</p>
<p>Note that when used like this (with Acquire and Release orderings), on
x86_64 this compiles to the same code as you would get from a C++ global,
(or a Rust <code>static mut</code>), while offering full synchronization.</p>
<p>(While caveats exist, the cases where youd need the total order guaranteed
by <a href="https://doc.rust-lang.org/1.84.0/core/sync/atomic/enum.Ordering.html#variant.SeqCst" title="variant core::sync::atomic::Ordering::SeqCst">SeqCst</a> for something like
<a href="struct.AtomicF32.html" title="struct atomic_float::AtomicF32"><code>AtomicF32</code></a> seem very rare).</p>
<h2 id="implementation"><a class="doc-anchor" href="#implementation">§</a>Implementation</h2>
<p>Note: These details are not part of the stability guarantee of this crate,
and are subject to change without a semver-breaking change.</p>
<p>Under the hood we use a transparent <code>UnsafeCell&lt;f32&gt;</code>, and cast the
<code>&amp;UnsafeCell&lt;f32&gt;</code> to an <a href="https://doc.rust-lang.org/1.84.0/core/sync/atomic/struct.AtomicU32.html" title="struct core::sync::atomic::AtomicU32"><code>&amp;AtomicU32</code></a> in
order to perform atomic operations.</p>
<p>This means that we have the same ABI and layout as f32, and that some
operations have a minimal cost (for example: on x86 all operations of
equivalent or weaker ordering than <code>Release</code> stores/<code>Acquire</code> loads are
essentially equivalent to non-atomic f32).</p>
<p>However, operations like <a href="struct.AtomicF32.html#method.fetch_add" title="method atomic_float::AtomicF32::fetch_add"><code>fetch_add</code></a> are
considerably slower than would be the case for integer atomics.</p>
</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-AtomicF32" class="impl"><a class="src rightside" href="../src/atomic_float/atomic_f32.rs.html#81-705">Source</a><a href="#impl-AtomicF32" class="anchor">§</a><h3 class="code-header">impl <a class="struct" href="struct.AtomicF32.html" title="struct atomic_float::AtomicF32">AtomicF32</a></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.new" class="method"><a class="src rightside" href="../src/atomic_float/atomic_f32.rs.html#104-106">Source</a><h4 class="code-header">pub const fn <a href="#method.new" class="fn">new</a>(float: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/core/primitive.f32.html">f32</a>) -&gt; Self</h4></section></summary><div class="docblock"><p>Initialize a <code>AtomicF32</code> from an <code>f32</code>.</p>
<h5 id="example-1"><a class="doc-anchor" href="#example-1">§</a>Example</h5>
<p>Use as a variable</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>x = AtomicF32::new(<span class="number">3.0f32</span>);
<span class="macro">assert_eq!</span>(x.load(Relaxed), <span class="number">3.0f32</span>);</code></pre></div>
<p>Use as a static:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">static </span>A_STATIC: AtomicF32 = AtomicF32::new(<span class="number">800.0</span>);
<span class="macro">assert_eq!</span>(A_STATIC.load(Relaxed), <span class="number">800.0</span>);</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/atomic_float/atomic_f32.rs.html#124-127">Source</a><h4 class="code-header">pub fn <a href="#method.get_mut" class="fn">get_mut</a>(&amp;mut self) -&gt; &amp;mut <a class="primitive" href="https://doc.rust-lang.org/1.84.0/core/primitive.f32.html">f32</a></h4></section></summary><div class="docblock"><p>Returns a mutable reference to the underlying float.</p>
<p>This is safe because the mutable reference guarantees that no other
threads are concurrently accessing the atomic data.</p>
<h5 id="example-2"><a class="doc-anchor" href="#example-2">§</a>Example</h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span><span class="kw-2">mut </span>some_float = AtomicF32::new(<span class="number">1.0</span>);
<span class="macro">assert_eq!</span>(<span class="kw-2">*</span>some_float.get_mut(), <span class="number">1.0</span>);
<span class="kw-2">*</span>some_float.get_mut() += <span class="number">1.0</span>;
<span class="macro">assert_eq!</span>(some_float.load(Ordering::SeqCst), <span class="number">2.0</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/atomic_float/atomic_f32.rs.html#142-144">Source</a><h4 class="code-header">pub fn <a href="#method.into_inner" class="fn">into_inner</a>(self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.84.0/core/primitive.f32.html">f32</a></h4></section></summary><div class="docblock"><p>Consumes the atomic and returns the contained value.</p>
<p>This is safe because passing <code>self</code> by value guarantees that no other
threads are concurrently accessing the atomic data.</p>
<h5 id="example-3"><a class="doc-anchor" href="#example-3">§</a>Example</h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>v = AtomicF32::new(<span class="number">6.0</span>);
<span class="macro">assert_eq!</span>(v.into_inner(), <span class="number">6.0f32</span>);</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.load" class="method"><a class="src rightside" href="../src/atomic_float/atomic_f32.rs.html#172-174">Source</a><h4 class="code-header">pub fn <a href="#method.load" class="fn">load</a>(&amp;self, ordering: <a class="enum" href="https://doc.rust-lang.org/1.84.0/core/sync/atomic/enum.Ordering.html" title="enum core::sync::atomic::Ordering">Ordering</a>) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.84.0/core/primitive.f32.html">f32</a></h4></section></summary><div class="docblock"><p>Loads a value from the atomic float.</p>
<p><code>load</code> takes an <a href="https://doc.rust-lang.org/1.84.0/core/sync/atomic/enum.Ordering.html" title="enum core::sync::atomic::Ordering"><code>Ordering</code></a> argument which describes the memory
ordering of this operation. Possible values are <a href="https://doc.rust-lang.org/1.84.0/core/sync/atomic/enum.Ordering.html#variant.SeqCst" title="variant core::sync::atomic::Ordering::SeqCst"><code>SeqCst</code></a>, <a href="https://doc.rust-lang.org/1.84.0/core/sync/atomic/enum.Ordering.html#variant.Acquire" title="variant core::sync::atomic::Ordering::Acquire"><code>Acquire</code></a>
and <a href="https://doc.rust-lang.org/1.84.0/core/sync/atomic/enum.Ordering.html#variant.Relaxed" title="variant core::sync::atomic::Ordering::Relaxed"><code>Relaxed</code></a>.</p>
<h5 id="panics"><a class="doc-anchor" href="#panics">§</a>Panics</h5>
<p>Panics if <code>ordering</code> is <a href="https://doc.rust-lang.org/1.84.0/core/sync/atomic/enum.Ordering.html#variant.Release" title="variant core::sync::atomic::Ordering::Release"><code>Release</code></a> or <a href="https://doc.rust-lang.org/1.84.0/core/sync/atomic/enum.Ordering.html#variant.AcqRel" title="variant core::sync::atomic::Ordering::AcqRel"><code>AcqRel</code></a>.</p>
<h5 id="example-4"><a class="doc-anchor" href="#example-4">§</a>Example</h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>atomic_float::AtomicF32;
<span class="kw">use </span>std::sync::atomic::Ordering;
<span class="kw">let </span>v = AtomicF32::new(<span class="number">22.5</span>);
<span class="macro">assert_eq!</span>(v.load(Ordering::SeqCst), <span class="number">22.5</span>);</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.store" class="method"><a class="src rightside" href="../src/atomic_float/atomic_f32.rs.html#204-206">Source</a><h4 class="code-header">pub fn <a href="#method.store" class="fn">store</a>(&amp;self, value: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/core/primitive.f32.html">f32</a>, ordering: <a class="enum" href="https://doc.rust-lang.org/1.84.0/core/sync/atomic/enum.Ordering.html" title="enum core::sync::atomic::Ordering">Ordering</a>)</h4></section></summary><div class="docblock"><p>Store a value into the atomic float.</p>
<p><code>store</code> takes an <a href="https://doc.rust-lang.org/1.84.0/core/sync/atomic/enum.Ordering.html" title="enum core::sync::atomic::Ordering"><code>Ordering</code></a> argument which describes the memory
ordering of this operation. Possible values are <a href="https://doc.rust-lang.org/1.84.0/core/sync/atomic/enum.Ordering.html#variant.SeqCst" title="variant core::sync::atomic::Ordering::SeqCst"><code>SeqCst</code></a>, <a href="https://doc.rust-lang.org/1.84.0/core/sync/atomic/enum.Ordering.html#variant.Release" title="variant core::sync::atomic::Ordering::Release"><code>Release</code></a>
and <a href="https://doc.rust-lang.org/1.84.0/core/sync/atomic/enum.Ordering.html#variant.Relaxed" title="variant core::sync::atomic::Ordering::Relaxed"><code>Relaxed</code></a>.</p>
<h5 id="panics-1"><a class="doc-anchor" href="#panics-1">§</a>Panics</h5>
<p>Panics if <code>ordering</code> is <a href="https://doc.rust-lang.org/1.84.0/core/sync/atomic/enum.Ordering.html#variant.Acquire" title="variant core::sync::atomic::Ordering::Acquire"><code>Acquire</code></a> or <a href="https://doc.rust-lang.org/1.84.0/core/sync/atomic/enum.Ordering.html#variant.AcqRel" title="variant core::sync::atomic::Ordering::AcqRel"><code>AcqRel</code></a>.</p>
<h5 id="example-5"><a class="doc-anchor" href="#example-5">§</a>Example</h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>atomic_float::AtomicF32;
<span class="kw">use </span>std::sync::atomic::Ordering;
<span class="kw">let </span>v = AtomicF32::new(<span class="number">22.5</span>);
<span class="macro">assert_eq!</span>(v.load(Ordering::SeqCst), <span class="number">22.5</span>);
v.store(<span class="number">30.0</span>, Ordering::SeqCst);
<span class="macro">assert_eq!</span>(v.load(Ordering::SeqCst), <span class="number">30.0</span>);</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.swap" class="method"><a class="src rightside" href="../src/atomic_float/atomic_f32.rs.html#231-233">Source</a><h4 class="code-header">pub fn <a href="#method.swap" class="fn">swap</a>(&amp;self, new_value: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/core/primitive.f32.html">f32</a>, ordering: <a class="enum" href="https://doc.rust-lang.org/1.84.0/core/sync/atomic/enum.Ordering.html" title="enum core::sync::atomic::Ordering">Ordering</a>) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.84.0/core/primitive.f32.html">f32</a></h4></section></summary><div class="docblock"><p>Stores a value into the atomic float, returning the previous value.</p>
<p><code>swap</code> takes an <a href="https://doc.rust-lang.org/1.84.0/core/sync/atomic/enum.Ordering.html" title="enum core::sync::atomic::Ordering"><code>Ordering</code></a> argument which describes the memory ordering
of this operation. All ordering modes are possible. Note that using
<a href="https://doc.rust-lang.org/1.84.0/core/sync/atomic/enum.Ordering.html#variant.Acquire" title="variant core::sync::atomic::Ordering::Acquire"><code>Acquire</code></a> makes the store part of this operation <a href="https://doc.rust-lang.org/1.84.0/core/sync/atomic/enum.Ordering.html#variant.Relaxed" title="variant core::sync::atomic::Ordering::Relaxed"><code>Relaxed</code></a>, and
using <a href="https://doc.rust-lang.org/1.84.0/core/sync/atomic/enum.Ordering.html#variant.Release" title="variant core::sync::atomic::Ordering::Release"><code>Release</code></a> makes the load part <a href="https://doc.rust-lang.org/1.84.0/core/sync/atomic/enum.Ordering.html#variant.Relaxed" title="variant core::sync::atomic::Ordering::Relaxed"><code>Relaxed</code></a>.</p>
<h5 id="example-6"><a class="doc-anchor" href="#example-6">§</a>Example</h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>atomic_float::AtomicF32;
<span class="kw">use </span>std::sync::atomic::Ordering;
<span class="kw">let </span>v = AtomicF32::new(<span class="number">4.5</span>);
<span class="macro">assert_eq!</span>(v.swap(<span class="number">100.0</span>, Ordering::Relaxed), <span class="number">4.5</span>);
<span class="macro">assert_eq!</span>(v.load(Ordering::Relaxed), <span class="number">100.0</span>);</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.compare_and_swap" class="method"><a class="src rightside" href="../src/atomic_float/atomic_f32.rs.html#279-285">Source</a><h4 class="code-header">pub fn <a href="#method.compare_and_swap" class="fn">compare_and_swap</a>(&amp;self, current: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/core/primitive.f32.html">f32</a>, new: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/core/primitive.f32.html">f32</a>, order: <a class="enum" href="https://doc.rust-lang.org/1.84.0/core/sync/atomic/enum.Ordering.html" title="enum core::sync::atomic::Ordering">Ordering</a>) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.84.0/core/primitive.f32.html">f32</a></h4></section></summary><div class="docblock"><p>Stores a value into the atomic float if the current value is <em>bitwise
identical</em> to the <code>current</code> value.</p>
<p>The return value is always the previous value. If it is equal to
<code>current</code>, then the value was updated.</p>
<p><code>compare_and_swap</code> also takes an <a href="https://doc.rust-lang.org/1.84.0/core/sync/atomic/enum.Ordering.html" title="enum core::sync::atomic::Ordering"><code>Ordering</code></a> argument which describes
the memory ordering of this operation. Notice that even when using
<code>AcqRel</code>, the operation might fail and hence just perform an <code>Acquire</code>
load, but not have <code>Release</code> semantics. Using <code>Acquire</code> makes the store
part of this operation <code>Relaxed</code> if it happens, and using <code>Release</code>
makes the load part <code>Relaxed</code>.</p>
<h5 id="caveats"><a class="doc-anchor" href="#caveats">§</a>Caveats</h5>
<p>As the <code>current</code> must be bitwise identical to the previous value, you
should not get the <code>current</code> value using any sort of arithmetic (both
because of rounding, and to avoid any situation where -0.0 and +0.0
would be compared). Additionally, on some platforms (WASM and ASM.js
currently) LLVM will canonicalize NaNs during loads, which can cause
unexpected behavior here — typically in the other direction (two values
being unexpectedly equal).</p>
<p>In practice, typical patterns for CaS tend to avoid these issues, but
youre encouraged to avoid relying on the behavior of cas-family APIs in
the face of rounding, signed zero, and NaNs.</p>
<h5 id="example-7"><a class="doc-anchor" href="#example-7">§</a>Example</h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>v = AtomicF32::new(<span class="number">5.0</span>);
<span class="macro">assert_eq!</span>(v.compare_and_swap(<span class="number">5.0</span>, <span class="number">10.0</span>, Ordering::Relaxed), <span class="number">5.0</span>);
<span class="macro">assert_eq!</span>(v.load(Ordering::Relaxed), <span class="number">10.0</span>);
<span class="macro">assert_eq!</span>(v.compare_and_swap(<span class="number">6.0</span>, <span class="number">12.0</span>, Ordering::Relaxed), <span class="number">10.0</span>);
<span class="macro">assert_eq!</span>(v.load(Ordering::Relaxed), <span class="number">10.0</span>);</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.compare_exchange" class="method"><a class="src rightside" href="../src/atomic_float/atomic_f32.rs.html#338-351">Source</a><h4 class="code-header">pub fn <a href="#method.compare_exchange" class="fn">compare_exchange</a>(
&amp;self,
current: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/core/primitive.f32.html">f32</a>,
new: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/core/primitive.f32.html">f32</a>,
success: <a class="enum" href="https://doc.rust-lang.org/1.84.0/core/sync/atomic/enum.Ordering.html" title="enum core::sync::atomic::Ordering">Ordering</a>,
failure: <a class="enum" href="https://doc.rust-lang.org/1.84.0/core/sync/atomic/enum.Ordering.html" title="enum core::sync::atomic::Ordering">Ordering</a>,
) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.84.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.84.0/core/primitive.f32.html">f32</a>, <a class="primitive" href="https://doc.rust-lang.org/1.84.0/core/primitive.f32.html">f32</a>&gt;</h4></section></summary><div class="docblock"><p>Stores a value into the atomic float if the current value is the bitwise
identical as the <code>current</code> value.</p>
<p>The return value is a result indicating whether the new value was
written and containing the previous value. On success this value is
guaranteed to be bitwise identical to <code>current</code>.</p>
<p><code>compare_exchange</code> takes two <a href="https://doc.rust-lang.org/1.84.0/core/sync/atomic/enum.Ordering.html" title="enum core::sync::atomic::Ordering"><code>Ordering</code></a> arguments to describe the
memory ordering of this operation. The first describes the required
ordering if the operation succeeds while the second describes the
required ordering when the operation fails. Using <code>Acquire</code> as success
ordering makes the store part of this operation <code>Relaxed</code>, and using
<code>Release</code> makes the successful load <code>Relaxed</code>. The failure ordering can
only be <code>SeqCst</code>, <code>Acquire</code> or <code>Relaxed</code> and must be equivalent to or
weaker than the success ordering.</p>
<h5 id="notes"><a class="doc-anchor" href="#notes">§</a>Notes</h5>
<p>Note that in many cases, when <code>while</code> loops where the condition contains
a <code>compare_exchange</code> operation are better written to use a
<a href="struct.AtomicF32.html#method.compare_exchange_weak" title="method atomic_float::AtomicF32::compare_exchange_weak"><code>compare_exchange_weak</code></a> in the
condition instead (as on weakly ordered platforms like ARM, the
<code>compare_exchange</code> operation itself can require a loop to perform).</p>
<h6 id="caveats-1"><a class="doc-anchor" href="#caveats-1">§</a>Caveats</h6>
<p>As the <code>current</code> parameter must be bitwise identical to the previous
value, you should not get the <code>current</code> value using any sort of
arithmetic (both because of rounding, and to avoid any situation where
-0.0 and +0.0 would be compared). Additionally, on Wasm, in some cases
<code>NaN</code> values have been known to cause problems for non-typical usage of
this API. See <a href="struct.AtomicF32.html#method.as_atomic_bits" title="method atomic_float::AtomicF32::as_atomic_bits"><code>AtomicF32::as_atomic_bits</code></a> if performing the
<code>compare_exchange</code> on the raw bits of this atomic float would solve an
issue for you.</p>
<h5 id="example-8"><a class="doc-anchor" href="#example-8">§</a>Example</h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>v = AtomicF32::new(<span class="number">5.0</span>);
<span class="macro">assert_eq!</span>(v.compare_exchange(<span class="number">5.0</span>, <span class="number">10.0</span>, Acquire, Relaxed), <span class="prelude-val">Ok</span>(<span class="number">5.0</span>));
<span class="macro">assert_eq!</span>(v.load(Relaxed), <span class="number">10.0</span>);
<span class="macro">assert_eq!</span>(v.compare_exchange(<span class="number">6.0</span>, <span class="number">12.0</span>, SeqCst, Relaxed), <span class="prelude-val">Err</span>(<span class="number">10.0</span>));
<span class="macro">assert_eq!</span>(v.load(Relaxed), <span class="number">10.0</span>);</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.compare_exchange_weak" class="method"><a class="src rightside" href="../src/atomic_float/atomic_f32.rs.html#406-419">Source</a><h4 class="code-header">pub fn <a href="#method.compare_exchange_weak" class="fn">compare_exchange_weak</a>(
&amp;self,
current: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/core/primitive.f32.html">f32</a>,
new: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/core/primitive.f32.html">f32</a>,
success: <a class="enum" href="https://doc.rust-lang.org/1.84.0/core/sync/atomic/enum.Ordering.html" title="enum core::sync::atomic::Ordering">Ordering</a>,
failure: <a class="enum" href="https://doc.rust-lang.org/1.84.0/core/sync/atomic/enum.Ordering.html" title="enum core::sync::atomic::Ordering">Ordering</a>,
) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.84.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.84.0/core/primitive.f32.html">f32</a>, <a class="primitive" href="https://doc.rust-lang.org/1.84.0/core/primitive.f32.html">f32</a>&gt;</h4></section></summary><div class="docblock"><p>Stores a value into the atomic integer if the current value is the same
as the <code>current</code> value.</p>
<p>Unlike <a href="struct.AtomicF32.html#method.compare_exchange" title="method atomic_float::AtomicF32::compare_exchange"><code>compare_exchange</code></a>, this function is
allowed to spuriously fail even when the comparison succeeds, which can
result in more efficient code on some platforms. The return value is a
result indicating whether the new value was written and containing the
previous value.</p>
<p><code>compare_exchange_weak</code> takes two <a href="https://doc.rust-lang.org/1.84.0/core/sync/atomic/enum.Ordering.html" title="enum core::sync::atomic::Ordering"><code>Ordering</code></a> arguments to describe the
memory ordering of this operation. The first describes the required
ordering if the operation succeeds while the second describes the
required ordering when the operation fails. Using <code>Acquire</code> as success
ordering makes the store part of this operation <code>Relaxed</code>, and using
<code>Release</code> makes the successful load <code>Relaxed</code>. The failure ordering can
only be <code>SeqCst</code>, <code>Acquire</code> or <code>Relaxed</code> and must be equivalent to or
weaker than the success ordering.</p>
<h6 id="caveats-2"><a class="doc-anchor" href="#caveats-2">§</a>Caveats</h6>
<p>As the <code>current</code> parameter must be bitwise identical to the previous
value, you should not get the <code>current</code> value using any sort of
arithmetic (both because of rounding, and to avoid any situation where
-0.0 and +0.0 would be compared). Additionally, on Wasm, in some cases
<code>NaN</code> values have been known to cause problems for non-typical usage of
this API. See <a href="struct.AtomicF32.html#method.as_atomic_bits" title="method atomic_float::AtomicF32::as_atomic_bits"><code>AtomicF32::as_atomic_bits</code></a> if performing the
<code>compare_exchange</code> on the raw bits of this atomic float would solve an
issue for you.</p>
<h5 id="example-9"><a class="doc-anchor" href="#example-9">§</a>Example</h5>
<p>Note that this sort of CaS loop should generally use <a href="struct.AtomicF32.html#method.fetch_update" title="method atomic_float::AtomicF32::fetch_update"><code>fetch_update</code></a>
instead.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>v = AtomicF32::new(<span class="number">5.0</span>);
<span class="kw">let </span><span class="kw-2">mut </span>old = v.load(Relaxed);
<span class="kw">loop </span>{
<span class="kw">let </span>new = old * <span class="number">2.0</span>;
<span class="kw">match </span>v.compare_exchange_weak(old, new, SeqCst, Relaxed) {
<span class="prelude-val">Ok</span>(<span class="kw">_</span>) =&gt; <span class="kw">break</span>,
<span class="prelude-val">Err</span>(x) =&gt; old = x,
}
}</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.fetch_update" class="method"><a class="src rightside" href="../src/atomic_float/atomic_f32.rs.html#458-473">Source</a><h4 class="code-header">pub fn <a href="#method.fetch_update" class="fn">fetch_update</a>&lt;F&gt;(
&amp;self,
set_order: <a class="enum" href="https://doc.rust-lang.org/1.84.0/core/sync/atomic/enum.Ordering.html" title="enum core::sync::atomic::Ordering">Ordering</a>,
fetch_order: <a class="enum" href="https://doc.rust-lang.org/1.84.0/core/sync/atomic/enum.Ordering.html" title="enum core::sync::atomic::Ordering">Ordering</a>,
update: F,
) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.84.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.84.0/core/primitive.f32.html">f32</a>, <a class="primitive" href="https://doc.rust-lang.org/1.84.0/core/primitive.f32.html">f32</a>&gt;<div class="where">where
F: <a class="trait" href="https://doc.rust-lang.org/1.84.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/1.84.0/core/primitive.f32.html">f32</a>) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.84.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.84.0/core/primitive.f32.html">f32</a>&gt;,</div></h4></section></summary><div class="docblock"><p>Fetches the value, and applies a function to it that returns an optional
new value. Returns a <code>Result</code> of <code>Ok(previous_value)</code> if the function
returned <code>Some(_)</code>, else <code>Err(previous_value)</code>.</p>
<p>Note: This may call the function multiple times if the value has been
changed from other threads in the meantime, as long as the function
returns <code>Some(_)</code>, but the function will have been applied only once to
the stored value.</p>
<p><code>fetch_update</code> takes two <a href="https://doc.rust-lang.org/1.84.0/core/sync/atomic/enum.Ordering.html" title="enum core::sync::atomic::Ordering"><code>Ordering</code></a> arguments to describe the memory
ordering of this operation. The first describes the required ordering
for when the operation finally succeeds while the second describes the
required ordering for loads. These correspond to the success and failure
orderings of <a href="struct.AtomicF32.html#method.compare_exchange" title="method atomic_float::AtomicF32::compare_exchange"><code>compare_exchange</code></a>
respectively.</p>
<p>Using <code>Acquire</code> as success ordering makes the store part of this
operation <code>Relaxed</code>, and using <code>Release</code> makes the final successful load
<code>Relaxed</code>. The (failed) load ordering can only be <code>SeqCst</code>, <code>Acquire</code> or
<code>Relaxed</code> and must be equivalent to or weaker than the success ordering.</p>
<h5 id="example-10"><a class="doc-anchor" href="#example-10">§</a>Example</h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>x = AtomicF32::new(<span class="number">7.0</span>);
<span class="macro">assert_eq!</span>(x.fetch_update(SeqCst, SeqCst, |<span class="kw">_</span>| <span class="prelude-val">None</span>), <span class="prelude-val">Err</span>(<span class="number">7.0</span>));
<span class="macro">assert_eq!</span>(x.fetch_update(SeqCst, SeqCst, |x| <span class="prelude-val">Some</span>(x + <span class="number">1.0</span>)), <span class="prelude-val">Ok</span>(<span class="number">7.0</span>));
<span class="macro">assert_eq!</span>(x.fetch_update(SeqCst, SeqCst, |x| <span class="prelude-val">Some</span>(x + <span class="number">1.0</span>)), <span class="prelude-val">Ok</span>(<span class="number">8.0</span>));
<span class="macro">assert_eq!</span>(x.load(SeqCst), <span class="number">9.0</span>);</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.fetch_add" class="method"><a class="src rightside" href="../src/atomic_float/atomic_f32.rs.html#536-538">Source</a><h4 class="code-header">pub fn <a href="#method.fetch_add" class="fn">fetch_add</a>(&amp;self, val: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/core/primitive.f32.html">f32</a>, order: <a class="enum" href="https://doc.rust-lang.org/1.84.0/core/sync/atomic/enum.Ordering.html" title="enum core::sync::atomic::Ordering">Ordering</a>) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.84.0/core/primitive.f32.html">f32</a></h4></section></summary><div class="docblock"><p>Adds to the current value, returning the previous value.</p>
<p>Because this returns the previous value, you may want to call it like:
<code>atom.fetch_add(x, order) + x</code></p>
<h5 id="examples"><a class="doc-anchor" href="#examples">§</a>Examples</h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>x = AtomicF32::new(<span class="number">7.0</span>);
<span class="macro">assert_eq!</span>(x.fetch_add(<span class="number">2.0</span>, Relaxed), <span class="number">7.0</span>);
<span class="macro">assert_eq!</span>(x.fetch_add(<span class="number">1.0</span>, SeqCst), <span class="number">9.0</span>);
<span class="macro">assert_eq!</span>(x.fetch_add(-<span class="number">100.0</span>, AcqRel), <span class="number">10.0</span>);</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.fetch_sub" class="method"><a class="src rightside" href="../src/atomic_float/atomic_f32.rs.html#559-561">Source</a><h4 class="code-header">pub fn <a href="#method.fetch_sub" class="fn">fetch_sub</a>(&amp;self, val: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/core/primitive.f32.html">f32</a>, order: <a class="enum" href="https://doc.rust-lang.org/1.84.0/core/sync/atomic/enum.Ordering.html" title="enum core::sync::atomic::Ordering">Ordering</a>) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.84.0/core/primitive.f32.html">f32</a></h4></section></summary><div class="docblock"><p>Subtract from the current value, returning the previous value.</p>
<p>Because this returns the previous value, you may want to call it like:
<code>atom.fetch_sub(x, order) - x</code></p>
<p>Note: This operation uses <a href="struct.AtomicF32.html#method.fetch_update" title="method atomic_float::AtomicF32::fetch_update"><code>fetch_update</code></a> under the hood, and is likely
to be slower than the equivalent operation for atomic integers.</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">let </span>x = AtomicF32::new(<span class="number">7.0</span>);
<span class="macro">assert_eq!</span>(x.fetch_sub(<span class="number">2.0</span>, Relaxed), <span class="number">7.0</span>);
<span class="macro">assert_eq!</span>(x.fetch_sub(-<span class="number">1.0</span>, SeqCst), <span class="number">5.0</span>);
<span class="macro">assert_eq!</span>(x.fetch_sub(<span class="number">0.5</span>, AcqRel), <span class="number">6.0</span>);</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.fetch_abs" class="method"><a class="src rightside" href="../src/atomic_float/atomic_f32.rs.html#576-578">Source</a><h4 class="code-header">pub fn <a href="#method.fetch_abs" class="fn">fetch_abs</a>(&amp;self, order: <a class="enum" href="https://doc.rust-lang.org/1.84.0/core/sync/atomic/enum.Ordering.html" title="enum core::sync::atomic::Ordering">Ordering</a>) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.84.0/core/primitive.f32.html">f32</a></h4></section></summary><div class="docblock"><p>Produce the absolute value of the current value, returning the previous
value.</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">let </span>x = AtomicF32::new(-<span class="number">7.0</span>);
<span class="macro">assert_eq!</span>(x.fetch_abs(Relaxed), -<span class="number">7.0</span>);
<span class="macro">assert_eq!</span>(x.fetch_abs(SeqCst), <span class="number">7.0</span>);</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.fetch_neg" class="method"><a class="src rightside" href="../src/atomic_float/atomic_f32.rs.html#597-599">Source</a><h4 class="code-header">pub fn <a href="#method.fetch_neg" class="fn">fetch_neg</a>(&amp;self, order: <a class="enum" href="https://doc.rust-lang.org/1.84.0/core/sync/atomic/enum.Ordering.html" title="enum core::sync::atomic::Ordering">Ordering</a>) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.84.0/core/primitive.f32.html">f32</a></h4></section></summary><div class="docblock"><p>Negates the current value, returning the previous value.</p>
<p>As a result of returning the previous value, you may want to invoke it like:
<code>-atom.fetch_neg(Relaxed)</code>.</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">let </span>x = AtomicF32::new(-<span class="number">7.0</span>);
<span class="macro">assert_eq!</span>(x.fetch_neg(Relaxed), -<span class="number">7.0</span>);
<span class="macro">assert_eq!</span>(x.fetch_neg(SeqCst), <span class="number">7.0</span>);
<span class="macro">assert_eq!</span>(x.fetch_neg(AcqRel), -<span class="number">7.0</span>);</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.fetch_min" class="method"><a class="src rightside" href="../src/atomic_float/atomic_f32.rs.html#627-629">Source</a><h4 class="code-header">pub fn <a href="#method.fetch_min" class="fn">fetch_min</a>(&amp;self, value: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/core/primitive.f32.html">f32</a>, order: <a class="enum" href="https://doc.rust-lang.org/1.84.0/core/sync/atomic/enum.Ordering.html" title="enum core::sync::atomic::Ordering">Ordering</a>) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.84.0/core/primitive.f32.html">f32</a></h4></section></summary><div class="docblock"><p>Minimum with the current value.</p>
<p>Finds the minimum of the current value and the argument <code>val</code>, and sets
the new value to the result.</p>
<p>Returns the previous value. Because of this, you may want to call it
like: <code>atom.fetch_min(x, order).min(x)</code></p>
<p>Note: This operation uses <a href="struct.AtomicF32.html#method.fetch_update" title="method atomic_float::AtomicF32::fetch_update"><code>fetch_update</code></a> under the
hood, and is likely to be slower than the equivalent operation for
atomic integers.</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">let </span>foo = AtomicF32::new(<span class="number">23.0</span>);
<span class="macro">assert_eq!</span>(foo.fetch_min(<span class="number">42.0</span>, Ordering::Relaxed), <span class="number">23.0</span>);
<span class="macro">assert_eq!</span>(foo.load(Ordering::Relaxed), <span class="number">23.0</span>);
<span class="macro">assert_eq!</span>(foo.fetch_min(<span class="number">22.0</span>, Ordering::Relaxed), <span class="number">23.0</span>);
<span class="macro">assert_eq!</span>(foo.load(Ordering::Relaxed), <span class="number">22.0</span>);</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.fetch_max" class="method"><a class="src rightside" href="../src/atomic_float/atomic_f32.rs.html#657-659">Source</a><h4 class="code-header">pub fn <a href="#method.fetch_max" class="fn">fetch_max</a>(&amp;self, value: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/core/primitive.f32.html">f32</a>, order: <a class="enum" href="https://doc.rust-lang.org/1.84.0/core/sync/atomic/enum.Ordering.html" title="enum core::sync::atomic::Ordering">Ordering</a>) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.84.0/core/primitive.f32.html">f32</a></h4></section></summary><div class="docblock"><p>Maximum with the current value.</p>
<p>Finds the maximum of the current value and the argument <code>val</code>, and sets
the new value to the result.</p>
<p>Returns the previous value. Because of this, you may want to call it
like: <code>atom.fetch_max(x, order).max(x)</code></p>
<p>Note: This operation uses <a href="struct.AtomicF32.html#method.fetch_update" title="method atomic_float::AtomicF32::fetch_update"><code>fetch_update</code></a> under the
hood, and is likely to be slower than the equivalent operation for
atomic integers.</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">let </span>foo = AtomicF32::new(<span class="number">23.0</span>);
<span class="macro">assert_eq!</span>(foo.fetch_max(<span class="number">22.0</span>, Ordering::Relaxed), <span class="number">23.0</span>);
<span class="macro">assert_eq!</span>(foo.load(Ordering::Relaxed), <span class="number">23.0</span>);
<span class="macro">assert_eq!</span>(foo.fetch_max(<span class="number">42.0</span>, Ordering::Relaxed), <span class="number">23.0</span>);
<span class="macro">assert_eq!</span>(foo.load(Ordering::Relaxed), <span class="number">42.0</span>);</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.as_atomic_bits" class="method"><a class="src rightside" href="../src/atomic_float/atomic_f32.rs.html#699-704">Source</a><h4 class="code-header">pub fn <a href="#method.as_atomic_bits" class="fn">as_atomic_bits</a>(&amp;self) -&gt; &amp;<a class="struct" href="https://doc.rust-lang.org/1.84.0/core/sync/atomic/struct.AtomicU32.html" title="struct core::sync::atomic::AtomicU32">AtomicU32</a></h4></section></summary><div class="docblock"><p>Returns a reference to an atomic integer which can be used to access the
atomic floats underlying bits in a thread safe manner.</p>
<p>This is essentially a <code>transmute::&lt;&amp;Self, &amp;AtomicU32&gt;(self)</code>, and is
zero cost.</p>
<h5 id="motivation"><a class="doc-anchor" href="#motivation">§</a>Motivation</h5>
<p>This is exposed as an escape hatch because of the caveats around the
<code>AtomicF32</code> CaS-family APIs (<a href="https://doc.rust-lang.org/1.84.0/core/sync/atomic/struct.AtomicU32.html#method.compare_and_swap" title="method core::sync::atomic::AtomicU32::compare_and_swap"><code>compare_and_swap</code></a>, <a href="https://doc.rust-lang.org/1.84.0/core/sync/atomic/struct.AtomicU32.html#method.compare_exchange" title="method core::sync::atomic::AtomicU32::compare_exchange"><code>compare_exchange</code></a>,
<a href="https://doc.rust-lang.org/1.84.0/core/sync/atomic/struct.AtomicU32.html#method.compare_exchange_weak" title="method core::sync::atomic::AtomicU32::compare_exchange_weak"><code>compare_exchange_weak</code></a>, …) and the notion of bitwise identicality
which they require being somewhat problematic for NaNs, especially on
targets like Wasm (see <a href="https://github.com/rust-lang/rust/issues/73328">rust-lang/rust#73328</a>).</p>
<p>In general despite how bad this might sound, in practice were fairly
safe: LLVM almost never optimizes through atomic operations, this
library is written to try to avoid potential issues from most naive
usage, and Im optimistic the situation will clean itself up in the
short-to-medium-term future.</p>
<p>However, if you need peace of mind, or find yourself in a case where you
suspect youre hitting this issue, you can access the underlying atomic
value using this function.</p>
<h5 id="examples-6"><a class="doc-anchor" href="#examples-6">§</a>Examples</h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>v = AtomicF32::new(<span class="number">22.5</span>);
<span class="macro">assert_eq!</span>(v.as_atomic_bits().load(Ordering::Relaxed), <span class="number">22.5f32</span>.to_bits());</code></pre></div>
</div></details></div></details></div><h2 id="trait-implementations" class="section-header">Trait Implementations<a href="#trait-implementations" class="anchor">§</a></h2><div id="trait-implementations-list"><details class="toggle implementors-toggle" open><summary><section id="impl-Debug-for-AtomicF32" class="impl"><a class="src rightside" href="../src/atomic_float/atomic_f32.rs.html#734-738">Source</a><a href="#impl-Debug-for-AtomicF32" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.84.0/core/fmt/trait.Debug.html" title="trait core::fmt::Debug">Debug</a> for <a class="struct" href="struct.AtomicF32.html" title="struct atomic_float::AtomicF32">AtomicF32</a></h3></section></summary><div class="docblock"><p>Equivalent to <code>&lt;f32 as core::fmt::Debug&gt;::fmt</code>.</p>
<h4 id="example-12"><a class="doc-anchor" href="#example-12">§</a>Example</h4>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>v = AtomicF32::new(<span class="number">40.0</span>);
<span class="macro">assert_eq!</span>(<span class="macro">format!</span>(<span class="string">"{:?}"</span>, v), <span class="macro">format!</span>(<span class="string">"{:?}"</span>, <span class="number">40.0f32</span>));</code></pre></div>
</div><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/atomic_float/atomic_f32.rs.html#735-737">Source</a><a href="#method.fmt" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.84.0/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.84.0/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.84.0/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.84.0/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-AtomicF32" class="impl"><a class="src rightside" href="../src/atomic_float/atomic_f32.rs.html#717-722">Source</a><a href="#impl-Default-for-AtomicF32" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.84.0/core/default/trait.Default.html" title="trait core::default::Default">Default</a> for <a class="struct" href="struct.AtomicF32.html" title="struct atomic_float::AtomicF32">AtomicF32</a></h3></section></summary><div class="docblock"><p>Return a zero-initialized atomic.</p>
<h4 id="example-11"><a class="doc-anchor" href="#example-11">§</a>Example</h4>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>x = AtomicF32::default();
<span class="macro">assert_eq!</span>(x.load(Ordering::SeqCst), <span class="number">0.0</span>);</code></pre></div>
</div><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/atomic_float/atomic_f32.rs.html#719-721">Source</a><a href="#method.default" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.84.0/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.84.0/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%3Cf32%3E-for-AtomicF32" class="impl"><a class="src rightside" href="../src/atomic_float/atomic_f32.rs.html#750-755">Source</a><a href="#impl-From%3Cf32%3E-for-AtomicF32" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.84.0/core/convert/trait.From.html" title="trait core::convert::From">From</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.84.0/core/primitive.f32.html">f32</a>&gt; for <a class="struct" href="struct.AtomicF32.html" title="struct atomic_float::AtomicF32">AtomicF32</a></h3></section></summary><div class="docblock"><p>Equivalent to <code>AtomicF32::new</code>.</p>
<h4 id="example-13"><a class="doc-anchor" href="#example-13">§</a>Example</h4>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>v = AtomicF32::from(<span class="number">10.0</span>);
<span class="macro">assert_eq!</span>(v.load(Ordering::SeqCst), <span class="number">10.0</span>);</code></pre></div>
</div><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/atomic_float/atomic_f32.rs.html#752-754">Source</a><a href="#method.from" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.84.0/core/convert/trait.From.html#tymethod.from" class="fn">from</a>(f: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/core/primitive.f32.html">f32</a>) -&gt; Self</h4></section></summary><div class='docblock'>Converts to this type from the input type.</div></details></div></details><details class="toggle implementors-toggle" open><summary><section id="impl-PartialEq-for-AtomicF32" class="impl"><a class="src rightside" href="../src/atomic_float/atomic_f32.rs.html#814-819">Source</a><a href="#impl-PartialEq-for-AtomicF32" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.84.0/core/cmp/trait.PartialEq.html" title="trait core::cmp::PartialEq">PartialEq</a> for <a class="struct" href="struct.AtomicF32.html" title="struct atomic_float::AtomicF32">AtomicF32</a></h3></section></summary><div class="docblock"><p>Compare two <a href="struct.AtomicF32.html" title="struct atomic_float::AtomicF32"><code>AtomicF32</code></a>s.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>a = AtomicF32::new(<span class="number">1.0</span>);
a.fetch_add(<span class="number">1.0</span>, Ordering::Relaxed);
<span class="macro">assert_ne!</span>(a, AtomicF32::new(<span class="number">1.0</span>));
<span class="macro">assert_eq!</span>(a, AtomicF32::new(<span class="number">2.0</span>));</code></pre></div>
<h4 id="caveats-3"><a class="doc-anchor" href="#caveats-3">§</a>Caveats</h4>
<p>Relaxed ordering is used for each load, so additional fencing (or avoiding
the use of this <code>PartialEq</code> implementation) may be desirable.</p>
<p>Additionally, this is implemented in terms of <code>f32</code>s <code>PartialEq</code>, so NaNs
will compare as inequal. For example:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>a = AtomicF32::new(f32::NAN);
<span class="macro">assert_ne!</span>(a, a);</code></pre></div>
</div><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.eq" class="method trait-impl"><a class="src rightside" href="../src/atomic_float/atomic_f32.rs.html#816-818">Source</a><a href="#method.eq" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.84.0/core/cmp/trait.PartialEq.html#tymethod.eq" class="fn">eq</a>(&amp;self, o: &amp;<a class="struct" href="struct.AtomicF32.html" title="struct atomic_float::AtomicF32">AtomicF32</a>) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.84.0/core/primitive.bool.html">bool</a></h4></section></summary><div class='docblock'>Tests for <code>self</code> and <code>other</code> values to be equal, and is used by <code>==</code>.</div></details><details class="toggle method-toggle" open><summary><section id="method.ne" class="method trait-impl"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="src" href="https://doc.rust-lang.org/1.84.0/src/core/cmp.rs.html#261">Source</a></span><a href="#method.ne" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.84.0/core/cmp/trait.PartialEq.html#method.ne" class="fn">ne</a>(&amp;self, other: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/core/primitive.reference.html">&amp;Rhs</a>) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.84.0/core/primitive.bool.html">bool</a></h4></section></summary><div class='docblock'>Tests for <code>!=</code>. The default implementation is almost always sufficient,
and should not be overridden without very good reason.</div></details></div></details><section id="impl-Send-for-AtomicF32" class="impl"><a class="src rightside" href="../src/atomic_float/atomic_f32.rs.html#71">Source</a><a href="#impl-Send-for-AtomicF32" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.84.0/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> for <a class="struct" href="struct.AtomicF32.html" title="struct atomic_float::AtomicF32">AtomicF32</a></h3></section><section id="impl-Sync-for-AtomicF32" class="impl"><a class="src rightside" href="../src/atomic_float/atomic_f32.rs.html#72">Source</a><a href="#impl-Sync-for-AtomicF32" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.84.0/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> for <a class="struct" href="struct.AtomicF32.html" title="struct atomic_float::AtomicF32">AtomicF32</a></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-AtomicF32" class="impl"><a href="#impl-Freeze-for-AtomicF32" class="anchor">§</a><h3 class="code-header">impl !<a class="trait" href="https://doc.rust-lang.org/1.84.0/core/marker/trait.Freeze.html" title="trait core::marker::Freeze">Freeze</a> for <a class="struct" href="struct.AtomicF32.html" title="struct atomic_float::AtomicF32">AtomicF32</a></h3></section><section id="impl-RefUnwindSafe-for-AtomicF32" class="impl"><a href="#impl-RefUnwindSafe-for-AtomicF32" class="anchor">§</a><h3 class="code-header">impl !<a class="trait" href="https://doc.rust-lang.org/1.84.0/core/panic/unwind_safe/trait.RefUnwindSafe.html" title="trait core::panic::unwind_safe::RefUnwindSafe">RefUnwindSafe</a> for <a class="struct" href="struct.AtomicF32.html" title="struct atomic_float::AtomicF32">AtomicF32</a></h3></section><section id="impl-Unpin-for-AtomicF32" class="impl"><a href="#impl-Unpin-for-AtomicF32" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.84.0/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a> for <a class="struct" href="struct.AtomicF32.html" title="struct atomic_float::AtomicF32">AtomicF32</a></h3></section><section id="impl-UnwindSafe-for-AtomicF32" class="impl"><a href="#impl-UnwindSafe-for-AtomicF32" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.84.0/core/panic/unwind_safe/trait.UnwindSafe.html" title="trait core::panic::unwind_safe::UnwindSafe">UnwindSafe</a> for <a class="struct" href="struct.AtomicF32.html" title="struct atomic_float::AtomicF32">AtomicF32</a></h3></section></div><h2 id="blanket-implementations" class="section-header">Blanket Implementations<a href="#blanket-implementations" class="anchor">§</a></h2><div id="blanket-implementations-list"><details class="toggle implementors-toggle"><summary><section id="impl-Any-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.0/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.84.0/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.84.0/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.84.0/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.84.0/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.84.0/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.84.0/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.84.0/src/core/borrow.rs.html#209">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.84.0/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.84.0/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.84.0/src/core/borrow.rs.html#211">Source</a><a href="#method.borrow" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.84.0/core/borrow/trait.Borrow.html#tymethod.borrow" class="fn">borrow</a>(&amp;self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.84.0/core/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.84.0/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.84.0/src/core/borrow.rs.html#217">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.84.0/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.84.0/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.84.0/src/core/borrow.rs.html#218">Source</a><a href="#method.borrow_mut" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.84.0/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.84.0/core/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.84.0/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%3CT%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.0/src/core/convert/mod.rs.html#765">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.84.0/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.84.0/src/core/convert/mod.rs.html#768">Source</a><a href="#method.from-1" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.84.0/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.84.0/src/core/convert/mod.rs.html#748-750">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.84.0/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.84.0/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.84.0/src/core/convert/mod.rs.html#758">Source</a><a href="#method.into" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.84.0/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.84.0/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.84.0/src/core/convert/mod.rs.html#805-807">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.84.0/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.84.0/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.84.0/src/core/convert/mod.rs.html#809">Source</a><a href="#associatedtype.Error-1" class="anchor">§</a><h4 class="code-header">type <a href="https://doc.rust-lang.org/1.84.0/core/convert/trait.TryFrom.html#associatedtype.Error" class="associatedtype">Error</a> = <a class="enum" href="https://doc.rust-lang.org/1.84.0/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.84.0/src/core/convert/mod.rs.html#812">Source</a><a href="#method.try_from" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.84.0/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.84.0/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.84.0/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.84.0/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.84.0/src/core/convert/mod.rs.html#790-792">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.84.0/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.84.0/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.84.0/src/core/convert/mod.rs.html#794">Source</a><a href="#associatedtype.Error" class="anchor">§</a><h4 class="code-header">type <a href="https://doc.rust-lang.org/1.84.0/core/convert/trait.TryInto.html#associatedtype.Error" class="associatedtype">Error</a> = &lt;U as <a class="trait" href="https://doc.rust-lang.org/1.84.0/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.84.0/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.84.0/src/core/convert/mod.rs.html#797">Source</a><a href="#method.try_into" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.84.0/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.84.0/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.84.0/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.84.0/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>