all FX functions are now safe wrapped and I added the crate to the docs also it is added to the prelude

This commit is contained in:
ZennDev1337 2023-10-04 14:47:38 +02:00
parent 3f847e86a6
commit 522844499e
1272 changed files with 1371 additions and 61826 deletions

View file

@ -1,139 +0,0 @@
<!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="Source of the Rust file `arduboy-rust/src/hardware/buttons.rs`."><title>buttons.rs - source</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-47e7ab555ef2818a.css"><meta name="rustdoc-vars" data-root-path="../../../" data-static-root-path="../../../static.files/" data-current-crate="arduboy_rust" data-themes="" data-resource-suffix="" data-rustdoc-version="1.74.0-nightly (d9c8274fb 2023-09-12)" data-channel="nightly" data-search-js="search-5d3eaacf19ebf04f.js" data-settings-js="settings-74424d7eec62a23e.js" data-settings-css="settings-8c76f75bfb6bd192.css" data-theme-light-css="light-f194925aa375ae96.css" data-theme-dark-css="dark-1dd4d1ce031e15de.css" data-theme-ayu-css="ayu-49e58d069f567085.css" ><script src="../../../static.files/storage-db41da1a38ea3cb8.js"></script><script defer src="../../../static.files/src-script-3280b574d94e47b4.js"></script><script defer src="../../../src-files.js"></script><script defer src="../../../static.files/main-8d035c8cea6edbc4.js"></script><noscript><link rel="stylesheet" media="(prefers-color-scheme:light)" href="../../../static.files/light-f194925aa375ae96.css"><link rel="stylesheet" media="(prefers-color-scheme:dark)" href="../../../static.files/dark-1dd4d1ce031e15de.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 src"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"></nav><main><nav class="sub"><a class="sub-logo-container" href="../../../arduboy_rust/index.html"><img class="rust-logo" src="../../../static.files/rust-logo-151179464ae7ed46.svg" alt="logo"></a><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="example-wrap"><div data-nosnippet><pre class="src-line-numbers"><a href="#1" id="1">1</a>
<a href="#2" id="2">2</a>
<a href="#3" id="3">3</a>
<a href="#4" id="4">4</a>
<a href="#5" id="5">5</a>
<a href="#6" id="6">6</a>
<a href="#7" id="7">7</a>
<a href="#8" id="8">8</a>
<a href="#9" id="9">9</a>
<a href="#10" id="10">10</a>
<a href="#11" id="11">11</a>
<a href="#12" id="12">12</a>
<a href="#13" id="13">13</a>
<a href="#14" id="14">14</a>
<a href="#15" id="15">15</a>
<a href="#16" id="16">16</a>
<a href="#17" id="17">17</a>
<a href="#18" id="18">18</a>
<a href="#19" id="19">19</a>
<a href="#20" id="20">20</a>
<a href="#21" id="21">21</a>
<a href="#22" id="22">22</a>
<a href="#23" id="23">23</a>
<a href="#24" id="24">24</a>
<a href="#25" id="25">25</a>
<a href="#26" id="26">26</a>
<a href="#27" id="27">27</a>
<a href="#28" id="28">28</a>
<a href="#29" id="29">29</a>
<a href="#30" id="30">30</a>
<a href="#31" id="31">31</a>
<a href="#32" id="32">32</a>
<a href="#33" id="33">33</a>
<a href="#34" id="34">34</a>
<a href="#35" id="35">35</a>
<a href="#36" id="36">36</a>
<a href="#37" id="37">37</a>
<a href="#38" id="38">38</a>
<a href="#39" id="39">39</a>
<a href="#40" id="40">40</a>
<a href="#41" id="41">41</a>
<a href="#42" id="42">42</a>
<a href="#43" id="43">43</a>
<a href="#44" id="44">44</a>
<a href="#45" id="45">45</a>
<a href="#46" id="46">46</a>
<a href="#47" id="47">47</a>
<a href="#48" id="48">48</a>
<a href="#49" id="49">49</a>
<a href="#50" id="50">50</a>
<a href="#51" id="51">51</a>
<a href="#52" id="52">52</a>
<a href="#53" id="53">53</a>
<a href="#54" id="54">54</a>
<a href="#55" id="55">55</a>
<a href="#56" id="56">56</a>
<a href="#57" id="57">57</a>
<a href="#58" id="58">58</a>
<a href="#59" id="59">59</a>
<a href="#60" id="60">60</a>
<a href="#61" id="61">61</a>
<a href="#62" id="62">62</a>
<a href="#63" id="63">63</a>
<a href="#64" id="64">64</a>
<a href="#65" id="65">65</a>
<a href="#66" id="66">66</a>
<a href="#67" id="67">67</a>
<a href="#68" id="68">68</a>
<a href="#69" id="69">69</a>
</pre></div><pre class="rust"><code><span class="doccomment">//! A list of all six buttons available on the Arduboy
/// Just a `const` for the UP button
</span><span class="kw">pub const </span>UP: ButtonSet = ButtonSet {
flag_set: <span class="number">0b10000000</span>,
};
<span class="doccomment">/// Just a `const` for the RIGHT button
</span><span class="kw">pub const </span>RIGHT: ButtonSet = ButtonSet {
flag_set: <span class="number">0b01000000</span>,
};
<span class="doccomment">/// Just a `const` for the LEFT button
</span><span class="kw">pub const </span>LEFT: ButtonSet = ButtonSet {
flag_set: <span class="number">0b00100000</span>,
};
<span class="doccomment">/// Just a `const` for the DOWN button
</span><span class="kw">pub const </span>DOWN: ButtonSet = ButtonSet {
flag_set: <span class="number">0b00010000</span>,
};
<span class="doccomment">/// Just a `const` for the A button
</span><span class="kw">pub const </span>A: ButtonSet = ButtonSet {
flag_set: <span class="number">0b00001000</span>,
};
<span class="doccomment">/// Just a `const` for the B button
</span><span class="kw">pub const </span>B: ButtonSet = ButtonSet {
flag_set: <span class="number">0b00000100</span>,
};
<span class="doccomment">/// Just a `const` for the UP button
</span><span class="kw">pub const </span>UP_BUTTON: ButtonSet = UP;
<span class="doccomment">/// Just a `const` for the RIGHT button
</span><span class="kw">pub const </span>RIGHT_BUTTON: ButtonSet = RIGHT;
<span class="doccomment">/// Just a `const` for the DOWN button
</span><span class="kw">pub const </span>DOWN_BUTTON: ButtonSet = DOWN;
<span class="doccomment">/// Just a `const` for the LEFT button
</span><span class="kw">pub const </span>LEFT_BUTTON: ButtonSet = LEFT;
<span class="doccomment">/// Just a `const` for the A button
</span><span class="kw">pub const </span>A_BUTTON: ButtonSet = A;
<span class="doccomment">/// Just a `const` for the B button
</span><span class="kw">pub const </span>B_BUTTON: ButtonSet = B;
<span class="doccomment">///This struct gives the library a understanding what Buttons on the Arduboy are.
</span><span class="attr">#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
</span><span class="kw">pub struct </span>ButtonSet {
<span class="kw">pub </span>flag_set: u8,
}
<span class="kw">impl </span>ButtonSet {
<span class="kw">pub unsafe fn </span>pressed(<span class="kw-2">&amp;</span><span class="self">self</span>) -&gt; bool {
<span class="kw">crate</span>::library::arduboy2::pressed(<span class="self">self</span>.flag_set)
}
<span class="kw">pub unsafe fn </span>just_pressed(<span class="kw-2">&amp;</span><span class="self">self</span>) -&gt; bool {
<span class="kw">crate</span>::library::arduboy2::just_pressed(<span class="self">self</span>.flag_set)
}
<span class="kw">pub unsafe fn </span>just_released(<span class="kw-2">&amp;</span><span class="self">self</span>) -&gt; bool {
<span class="kw">crate</span>::library::arduboy2::just_released(<span class="self">self</span>.flag_set)
}
<span class="kw">pub unsafe fn </span>not_pressed(<span class="kw-2">&amp;</span><span class="self">self</span>) -&gt; bool {
<span class="kw">crate</span>::library::arduboy2::not_pressed(<span class="self">self</span>.flag_set)
}
}
<span class="kw">impl </span>core::ops::BitOr <span class="kw">for </span>ButtonSet {
<span class="kw">type </span>Output = <span class="self">Self</span>;
<span class="kw">fn </span>bitor(<span class="self">self</span>, other: <span class="self">Self</span>) -&gt; <span class="self">Self </span>{
<span class="self">Self </span>{
flag_set: <span class="self">self</span>.flag_set | other.flag_set,
}
}
}
</code></pre></div></section></main></body></html>

View file

@ -1,23 +0,0 @@
<!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="Source of the Rust file `arduboy-rust/src/hardware/led.rs`."><title>led.rs - source</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-47e7ab555ef2818a.css"><meta name="rustdoc-vars" data-root-path="../../../" data-static-root-path="../../../static.files/" data-current-crate="arduboy_rust" data-themes="" data-resource-suffix="" data-rustdoc-version="1.74.0-nightly (d9c8274fb 2023-09-12)" data-channel="nightly" data-search-js="search-5d3eaacf19ebf04f.js" data-settings-js="settings-74424d7eec62a23e.js" data-settings-css="settings-8c76f75bfb6bd192.css" data-theme-light-css="light-f194925aa375ae96.css" data-theme-dark-css="dark-1dd4d1ce031e15de.css" data-theme-ayu-css="ayu-49e58d069f567085.css" ><script src="../../../static.files/storage-db41da1a38ea3cb8.js"></script><script defer src="../../../static.files/src-script-3280b574d94e47b4.js"></script><script defer src="../../../src-files.js"></script><script defer src="../../../static.files/main-8d035c8cea6edbc4.js"></script><noscript><link rel="stylesheet" media="(prefers-color-scheme:light)" href="../../../static.files/light-f194925aa375ae96.css"><link rel="stylesheet" media="(prefers-color-scheme:dark)" href="../../../static.files/dark-1dd4d1ce031e15de.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 src"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"></nav><main><nav class="sub"><a class="sub-logo-container" href="../../../arduboy_rust/index.html"><img class="rust-logo" src="../../../static.files/rust-logo-151179464ae7ed46.svg" alt="logo"></a><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="example-wrap"><div data-nosnippet><pre class="src-line-numbers"><a href="#1" id="1">1</a>
<a href="#2" id="2">2</a>
<a href="#3" id="3">3</a>
<a href="#4" id="4">4</a>
<a href="#5" id="5">5</a>
<a href="#6" id="6">6</a>
<a href="#7" id="7">7</a>
<a href="#8" id="8">8</a>
<a href="#9" id="9">9</a>
<a href="#10" id="10">10</a>
<a href="#11" id="11">11</a>
</pre></div><pre class="rust"><code><span class="doccomment">//! A list of all LED variables available
///Just a `const` for the red led
</span><span class="kw">pub const </span>RED_LED: u8 = <span class="number">10</span>;
<span class="doccomment">///Just a `const` for the green led
</span><span class="kw">pub const </span>GREEN_LED: u8 = <span class="number">11</span>;
<span class="doccomment">///Just a `const` for the blue led
</span><span class="kw">pub const </span>BLUE_LED: u8 = <span class="number">9</span>;
<span class="doccomment">///Just a `const` for led on
</span><span class="kw">pub const </span>RGB_ON: u8 = <span class="number">1</span>;
<span class="doccomment">///Just a `const` for led off
</span><span class="kw">pub const </span>RGB_OFF: u8 = <span class="number">0</span>;
</code></pre></div></section></main></body></html>

View file

@ -1,7 +0,0 @@
<!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="Source of the Rust file `arduboy-rust/src/hardware/mod.rs`."><title>mod.rs - source</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-47e7ab555ef2818a.css"><meta name="rustdoc-vars" data-root-path="../../../" data-static-root-path="../../../static.files/" data-current-crate="arduboy_rust" data-themes="" data-resource-suffix="" data-rustdoc-version="1.74.0-nightly (d9c8274fb 2023-09-12)" data-channel="nightly" data-search-js="search-5d3eaacf19ebf04f.js" data-settings-js="settings-74424d7eec62a23e.js" data-settings-css="settings-8c76f75bfb6bd192.css" data-theme-light-css="light-f194925aa375ae96.css" data-theme-dark-css="dark-1dd4d1ce031e15de.css" data-theme-ayu-css="ayu-49e58d069f567085.css" ><script src="../../../static.files/storage-db41da1a38ea3cb8.js"></script><script defer src="../../../static.files/src-script-3280b574d94e47b4.js"></script><script defer src="../../../src-files.js"></script><script defer src="../../../static.files/main-8d035c8cea6edbc4.js"></script><noscript><link rel="stylesheet" media="(prefers-color-scheme:light)" href="../../../static.files/light-f194925aa375ae96.css"><link rel="stylesheet" media="(prefers-color-scheme:dark)" href="../../../static.files/dark-1dd4d1ce031e15de.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 src"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"></nav><main><nav class="sub"><a class="sub-logo-container" href="../../../arduboy_rust/index.html"><img class="rust-logo" src="../../../static.files/rust-logo-151179464ae7ed46.svg" alt="logo"></a><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="example-wrap"><div data-nosnippet><pre class="src-line-numbers"><a href="#1" id="1">1</a>
<a href="#2" id="2">2</a>
<a href="#3" id="3">3</a>
</pre></div><pre class="rust"><code><span class="doccomment">//! This is the Module to interact in a save way with the Arduboy hardware.
</span><span class="kw">pub mod </span>buttons;
<span class="kw">pub mod </span>led;
</code></pre></div></section></main></body></html>

View file

@ -1,81 +0,0 @@
<!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="Source of the Rust file `arduboy-rust/src/lib.rs`."><title>lib.rs - source</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-47e7ab555ef2818a.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="arduboy_rust" data-themes="" data-resource-suffix="" data-rustdoc-version="1.74.0-nightly (d9c8274fb 2023-09-12)" data-channel="nightly" data-search-js="search-5d3eaacf19ebf04f.js" data-settings-js="settings-74424d7eec62a23e.js" data-settings-css="settings-8c76f75bfb6bd192.css" data-theme-light-css="light-f194925aa375ae96.css" data-theme-dark-css="dark-1dd4d1ce031e15de.css" data-theme-ayu-css="ayu-49e58d069f567085.css" ><script src="../../static.files/storage-db41da1a38ea3cb8.js"></script><script defer src="../../static.files/src-script-3280b574d94e47b4.js"></script><script defer src="../../src-files.js"></script><script defer src="../../static.files/main-8d035c8cea6edbc4.js"></script><noscript><link rel="stylesheet" media="(prefers-color-scheme:light)" href="../../static.files/light-f194925aa375ae96.css"><link rel="stylesheet" media="(prefers-color-scheme:dark)" href="../../static.files/dark-1dd4d1ce031e15de.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 src"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"></nav><main><nav class="sub"><a class="sub-logo-container" href="../../arduboy_rust/index.html"><img class="rust-logo" src="../../static.files/rust-logo-151179464ae7ed46.svg" alt="logo"></a><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="example-wrap"><div data-nosnippet><pre class="src-line-numbers"><a href="#1" id="1">1</a>
<a href="#2" id="2">2</a>
<a href="#3" id="3">3</a>
<a href="#4" id="4">4</a>
<a href="#5" id="5">5</a>
<a href="#6" id="6">6</a>
<a href="#7" id="7">7</a>
<a href="#8" id="8">8</a>
<a href="#9" id="9">9</a>
<a href="#10" id="10">10</a>
<a href="#11" id="11">11</a>
<a href="#12" id="12">12</a>
<a href="#13" id="13">13</a>
<a href="#14" id="14">14</a>
<a href="#15" id="15">15</a>
<a href="#16" id="16">16</a>
<a href="#17" id="17">17</a>
<a href="#18" id="18">18</a>
<a href="#19" id="19">19</a>
<a href="#20" id="20">20</a>
<a href="#21" id="21">21</a>
<a href="#22" id="22">22</a>
<a href="#23" id="23">23</a>
<a href="#24" id="24">24</a>
<a href="#25" id="25">25</a>
<a href="#26" id="26">26</a>
<a href="#27" id="27">27</a>
<a href="#28" id="28">28</a>
<a href="#29" id="29">29</a>
<a href="#30" id="30">30</a>
<a href="#31" id="31">31</a>
<a href="#32" id="32">32</a>
<a href="#33" id="33">33</a>
<a href="#34" id="34">34</a>
<a href="#35" id="35">35</a>
<a href="#36" id="36">36</a>
<a href="#37" id="37">37</a>
<a href="#38" id="38">38</a>
<a href="#39" id="39">39</a>
<a href="#40" id="40">40</a>
</pre></div><pre class="rust"><code><span class="attr">#![cfg(target_arch = <span class="string">&quot;avr&quot;</span>)]
#![no_std]
#![feature(c_size_t)]
</span><span class="doccomment">//! This is the arduboy_rust crate
//! To get started import the [prelude] to your project.
//!
//! Import the module:
//! ```
//! use arduboy_rust::prelude::*;
//! ```
//! ### Disable C++ libraries
//! Inside the root directory is a file named `import_config.h`
//!
//! You can disable C++ libraries in the `import_config.h` file.
//! Just comment the unused library definition out.
//!
//! Be careful with disabling libraries because:
//! - The only error you get is something like this if you try to use a function that relies on the library you disabled.
//! ```text
//! game.90c69b91e57f285-cgu.0:(.text.loop+0x290): undefined reference to `sound_tone&#39;
//! ```
//! - the benefit of disabling will be important in the feature when I add support for the ArduboyG library etc.
//!
//! To get an idea, the ArduboyTones Library needs additional 2-3% of the flash memory.
//!
//! &lt;a href=&quot;https://github.com/zenndev1337/rust-for-arduboy&quot; target=&quot;_blank&quot;&gt;Here is the link to the GitHub Repo&lt;/a&gt;
</span><span class="kw">extern crate </span>panic_halt;
<span class="kw">pub mod </span>hardware;
<span class="kw">mod </span>library;
<span class="kw">pub mod </span>prelude;
<span class="kw">mod </span>print;
<span class="attr">#[doc(inline)]
</span><span class="kw">pub extern crate </span>heapless;
<span class="kw">pub use </span><span class="kw">crate</span>::library::arduboy2::{<span class="self">self</span>, Arduboy2, Color, FONT_SIZE, HEIGHT, WIDTH};
<span class="kw">pub use </span><span class="kw">crate</span>::library::arduboy_tone::{<span class="self">self</span>, ArduboyTones};
<span class="kw">pub use </span><span class="kw">crate</span>::library::ardvoice::{<span class="self">self</span>, ArdVoice};
<span class="kw">pub use </span><span class="kw">crate</span>::library::eeprom::{EEPROM, EEPROMBYTE};
<span class="kw">pub use </span><span class="kw">crate</span>::library::{arduino, c, sprites};
<span class="kw">pub mod </span>serial_print;
</code></pre></div></section></main></body></html>

File diff suppressed because it is too large Load diff

View file

@ -1,305 +0,0 @@
<!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="Source of the Rust file `arduboy-rust/src/library/arduboy_tone.rs`."><title>arduboy_tone.rs - source</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-47e7ab555ef2818a.css"><meta name="rustdoc-vars" data-root-path="../../../" data-static-root-path="../../../static.files/" data-current-crate="arduboy_rust" data-themes="" data-resource-suffix="" data-rustdoc-version="1.74.0-nightly (d9c8274fb 2023-09-12)" data-channel="nightly" data-search-js="search-5d3eaacf19ebf04f.js" data-settings-js="settings-74424d7eec62a23e.js" data-settings-css="settings-8c76f75bfb6bd192.css" data-theme-light-css="light-f194925aa375ae96.css" data-theme-dark-css="dark-1dd4d1ce031e15de.css" data-theme-ayu-css="ayu-49e58d069f567085.css" ><script src="../../../static.files/storage-db41da1a38ea3cb8.js"></script><script defer src="../../../static.files/src-script-3280b574d94e47b4.js"></script><script defer src="../../../src-files.js"></script><script defer src="../../../static.files/main-8d035c8cea6edbc4.js"></script><noscript><link rel="stylesheet" media="(prefers-color-scheme:light)" href="../../../static.files/light-f194925aa375ae96.css"><link rel="stylesheet" media="(prefers-color-scheme:dark)" href="../../../static.files/dark-1dd4d1ce031e15de.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 src"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"></nav><main><nav class="sub"><a class="sub-logo-container" href="../../../arduboy_rust/index.html"><img class="rust-logo" src="../../../static.files/rust-logo-151179464ae7ed46.svg" alt="logo"></a><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="example-wrap"><div data-nosnippet><pre class="src-line-numbers"><a href="#1" id="1">1</a>
<a href="#2" id="2">2</a>
<a href="#3" id="3">3</a>
<a href="#4" id="4">4</a>
<a href="#5" id="5">5</a>
<a href="#6" id="6">6</a>
<a href="#7" id="7">7</a>
<a href="#8" id="8">8</a>
<a href="#9" id="9">9</a>
<a href="#10" id="10">10</a>
<a href="#11" id="11">11</a>
<a href="#12" id="12">12</a>
<a href="#13" id="13">13</a>
<a href="#14" id="14">14</a>
<a href="#15" id="15">15</a>
<a href="#16" id="16">16</a>
<a href="#17" id="17">17</a>
<a href="#18" id="18">18</a>
<a href="#19" id="19">19</a>
<a href="#20" id="20">20</a>
<a href="#21" id="21">21</a>
<a href="#22" id="22">22</a>
<a href="#23" id="23">23</a>
<a href="#24" id="24">24</a>
<a href="#25" id="25">25</a>
<a href="#26" id="26">26</a>
<a href="#27" id="27">27</a>
<a href="#28" id="28">28</a>
<a href="#29" id="29">29</a>
<a href="#30" id="30">30</a>
<a href="#31" id="31">31</a>
<a href="#32" id="32">32</a>
<a href="#33" id="33">33</a>
<a href="#34" id="34">34</a>
<a href="#35" id="35">35</a>
<a href="#36" id="36">36</a>
<a href="#37" id="37">37</a>
<a href="#38" id="38">38</a>
<a href="#39" id="39">39</a>
<a href="#40" id="40">40</a>
<a href="#41" id="41">41</a>
<a href="#42" id="42">42</a>
<a href="#43" id="43">43</a>
<a href="#44" id="44">44</a>
<a href="#45" id="45">45</a>
<a href="#46" id="46">46</a>
<a href="#47" id="47">47</a>
<a href="#48" id="48">48</a>
<a href="#49" id="49">49</a>
<a href="#50" id="50">50</a>
<a href="#51" id="51">51</a>
<a href="#52" id="52">52</a>
<a href="#53" id="53">53</a>
<a href="#54" id="54">54</a>
<a href="#55" id="55">55</a>
<a href="#56" id="56">56</a>
<a href="#57" id="57">57</a>
<a href="#58" id="58">58</a>
<a href="#59" id="59">59</a>
<a href="#60" id="60">60</a>
<a href="#61" id="61">61</a>
<a href="#62" id="62">62</a>
<a href="#63" id="63">63</a>
<a href="#64" id="64">64</a>
<a href="#65" id="65">65</a>
<a href="#66" id="66">66</a>
<a href="#67" id="67">67</a>
<a href="#68" id="68">68</a>
<a href="#69" id="69">69</a>
<a href="#70" id="70">70</a>
<a href="#71" id="71">71</a>
<a href="#72" id="72">72</a>
<a href="#73" id="73">73</a>
<a href="#74" id="74">74</a>
<a href="#75" id="75">75</a>
<a href="#76" id="76">76</a>
<a href="#77" id="77">77</a>
<a href="#78" id="78">78</a>
<a href="#79" id="79">79</a>
<a href="#80" id="80">80</a>
<a href="#81" id="81">81</a>
<a href="#82" id="82">82</a>
<a href="#83" id="83">83</a>
<a href="#84" id="84">84</a>
<a href="#85" id="85">85</a>
<a href="#86" id="86">86</a>
<a href="#87" id="87">87</a>
<a href="#88" id="88">88</a>
<a href="#89" id="89">89</a>
<a href="#90" id="90">90</a>
<a href="#91" id="91">91</a>
<a href="#92" id="92">92</a>
<a href="#93" id="93">93</a>
<a href="#94" id="94">94</a>
<a href="#95" id="95">95</a>
<a href="#96" id="96">96</a>
<a href="#97" id="97">97</a>
<a href="#98" id="98">98</a>
<a href="#99" id="99">99</a>
<a href="#100" id="100">100</a>
<a href="#101" id="101">101</a>
<a href="#102" id="102">102</a>
<a href="#103" id="103">103</a>
<a href="#104" id="104">104</a>
<a href="#105" id="105">105</a>
<a href="#106" id="106">106</a>
<a href="#107" id="107">107</a>
<a href="#108" id="108">108</a>
<a href="#109" id="109">109</a>
<a href="#110" id="110">110</a>
<a href="#111" id="111">111</a>
<a href="#112" id="112">112</a>
<a href="#113" id="113">113</a>
<a href="#114" id="114">114</a>
<a href="#115" id="115">115</a>
<a href="#116" id="116">116</a>
<a href="#117" id="117">117</a>
<a href="#118" id="118">118</a>
<a href="#119" id="119">119</a>
<a href="#120" id="120">120</a>
<a href="#121" id="121">121</a>
<a href="#122" id="122">122</a>
<a href="#123" id="123">123</a>
<a href="#124" id="124">124</a>
<a href="#125" id="125">125</a>
<a href="#126" id="126">126</a>
<a href="#127" id="127">127</a>
<a href="#128" id="128">128</a>
<a href="#129" id="129">129</a>
<a href="#130" id="130">130</a>
<a href="#131" id="131">131</a>
<a href="#132" id="132">132</a>
<a href="#133" id="133">133</a>
<a href="#134" id="134">134</a>
<a href="#135" id="135">135</a>
<a href="#136" id="136">136</a>
<a href="#137" id="137">137</a>
<a href="#138" id="138">138</a>
<a href="#139" id="139">139</a>
<a href="#140" id="140">140</a>
<a href="#141" id="141">141</a>
<a href="#142" id="142">142</a>
<a href="#143" id="143">143</a>
<a href="#144" id="144">144</a>
<a href="#145" id="145">145</a>
<a href="#146" id="146">146</a>
<a href="#147" id="147">147</a>
<a href="#148" id="148">148</a>
<a href="#149" id="149">149</a>
<a href="#150" id="150">150</a>
<a href="#151" id="151">151</a>
<a href="#152" id="152">152</a>
</pre></div><pre class="rust"><code><span class="doccomment">//!This is the Module to interact in a save way with the ArduboyTones C++ library.
//!
//! You will need to uncomment the ArduboyTones_Library in the import_config.h file.
</span><span class="kw">pub use </span><span class="kw">crate</span>::library::arduboy_tone_pitch;
<span class="kw">use </span>core::ffi::{c_uchar, c_uint, c_ulong};
<span class="kw">extern </span><span class="string">&quot;C&quot; </span>{
<span class="attr">#[link_name = <span class="string">&quot;sound_tone&quot;</span>]
</span><span class="kw">fn </span>sound_tone(frequency: c_uint, duration: c_ulong);
<span class="attr">#[link_name = <span class="string">&quot;sound_tone2&quot;</span>]
</span><span class="kw">fn </span>sound_tone2(frequency1: c_uint, duration1: c_ulong, frequency2: c_uint, duration2: c_ulong);
<span class="attr">#[link_name = <span class="string">&quot;sound_tone3&quot;</span>]
</span><span class="kw">fn </span>sound_tone3(
frequency1: c_uint,
duration1: c_ulong,
frequency2: c_uint,
duration2: c_ulong,
frequency3: c_uint,
duration3: c_ulong,
);
<span class="attr">#[link_name = <span class="string">&quot;sound_tones&quot;</span>]
</span><span class="kw">fn </span>sound_tones(tones: <span class="kw-2">*const </span>c_uint);
<span class="attr">#[link_name = <span class="string">&quot;sound_no_tone&quot;</span>]
</span><span class="kw">fn </span>sound_no_tone();
<span class="attr">#[link_name = <span class="string">&quot;sound_playing&quot;</span>]
</span><span class="kw">fn </span>sound_playing() -&gt; bool;
<span class="attr">#[link_name = <span class="string">&quot;sound_tones_in_ram&quot;</span>]
</span><span class="kw">fn </span>sound_tones_in_ram(tones: <span class="kw-2">*mut </span>c_ulong);
<span class="attr">#[link_name = <span class="string">&quot;sound_volume_mode&quot;</span>]
</span><span class="kw">fn </span>sound_volume_mode(mode: c_uchar);
}
<span class="doccomment">///This is the struct to interact in a save way with the ArduboyTones C++ library.
///
/// You will need to uncomment the ArduboyTones_Library in the import_config.h file.
</span><span class="kw">pub struct </span>ArduboyTones {}
<span class="kw">impl </span>ArduboyTones {
<span class="doccomment">///Get a new instance of [ArduboyTones]
/// ## Example
/// ```
/// const sound: ArduboyTones = ArduboyTones::new();
/// ```
</span><span class="kw">pub const fn </span>new() -&gt; ArduboyTones {
ArduboyTones {}
}
<span class="doccomment">///Play a single tone.
///
///- freq The frequency of the tone, in hertz.
///- dur The duration to play the tone for, in 1024ths of a
///second (very close to milliseconds). A duration of 0, or if not provided,
///means play forever, or until `noTone()` is called or a new tone or
///sequence is started.
</span><span class="kw">pub fn </span>tone(<span class="kw-2">&amp;</span><span class="self">self</span>, frequency: u16, duration: u32) {
<span class="kw">unsafe </span>{ sound_tone(frequency, duration) }
}
<span class="doccomment">/// Play two tones in sequence.
///
/// - freq1,freq2 The frequency of the tone in hertz.
/// - dur1,dur2 The duration to play the tone for, in 1024ths of a
/// second (very close to milliseconds).
</span><span class="kw">pub fn </span>tone2(<span class="kw-2">&amp;</span><span class="self">self</span>, frequency1: u16, duration1: u32, frequency2: u16, duration2: u32) {
<span class="kw">unsafe </span>{ sound_tone2(frequency1, duration1, frequency2, duration2) }
}
<span class="doccomment">/// Play three tones in sequence.
///
/// - freq1,freq2,freq3 The frequency of the tone, in hertz.
/// - dur1,dur2,dur3 The duration to play the tone for, in 1024ths of a
/// second (very close to milliseconds).
</span><span class="kw">pub fn </span>tone3(
<span class="kw-2">&amp;</span><span class="self">self</span>,
frequency1: u16,
duration1: u32,
frequency2: u16,
duration2: u32,
frequency3: u16,
duration3: u32,
) {
<span class="kw">unsafe </span>{ sound_tone3(frequency1, duration1, frequency2, duration2, frequency3, duration3) }
}
<span class="doccomment">/// Play a tone sequence from frequency/duration pairs in a PROGMEM array.
///
/// - tones A pointer to an array of frequency/duration pairs.
///
/// The array must be placed in code space using `PROGMEM`.
///
/// See the `tone()` function for details on the frequency and duration values.
/// A frequency of 0 for any tone means silence (a musical rest).
///
/// The last element of the array must be `TONES_END` or `TONES_REPEAT`.
///
/// Example:
/// ```
/// progmem!(
/// static sound1:[u8;_]=[220,1000, 0,250, 440,500, 880,2000,TONES_END]
/// );
///
/// tones(get_tones_addr!(sound1));
/// ```
</span><span class="kw">pub fn </span>tones(<span class="kw-2">&amp;</span><span class="self">self</span>, tones: <span class="kw-2">*const </span>u16) {
<span class="kw">unsafe </span>{ sound_tones(tones) }
}
<span class="doccomment">/// Stop playing the tone or sequence.
///
/// If a tone or sequence is playing, it will stop. If nothing
/// is playing, this function will do nothing.
</span><span class="kw">pub fn </span>no_tone(<span class="kw-2">&amp;</span><span class="self">self</span>) {
<span class="kw">unsafe </span>{ sound_no_tone() }
}
<span class="doccomment">/// Check if a tone or tone sequence is playing.
///
/// - return boolean `true` if playing (even if sound is muted).
</span><span class="kw">pub fn </span>playing(<span class="kw-2">&amp;</span><span class="self">self</span>) -&gt; bool {
<span class="kw">unsafe </span>{ sound_playing() }
}
<span class="doccomment">/// Play a tone sequence from frequency/duration pairs in an array in RAM.
///
/// - tones A pointer to an array of frequency/duration pairs.
///
/// The array must be located in RAM.
///
/// See the `tone()` function for details on the frequency and duration values.
/// A frequency of 0 for any tone means silence (a musical rest).
///
/// The last element of the array must be `TONES_END` or `TONES_REPEAT`.
///
/// Example:
///
/// ```
/// let sound2: [u16; 9] = [220, 1000, 0, 250, 440, 500, 880, 2000, TONES_END];
/// ```
/// Using `tones()`, with the data in PROGMEM, is normally a better
/// choice. The only reason to use tonesInRAM() would be if dynamically
/// altering the contents of the array is required.
</span><span class="kw">pub fn </span>tones_in_ram(<span class="kw-2">&amp;</span><span class="self">self</span>, tones: <span class="kw-2">*mut </span>u32) {
<span class="kw">unsafe </span>{ sound_tones_in_ram(tones) }
}
<span class="doccomment">/// Set the volume to always normal, always high, or tone controlled.
///
/// One of the following values should be used:
///
/// - `VOLUME_IN_TONE` The volume of each tone will be specified in the tone
/// itself.
/// - `VOLUME_ALWAYS_NORMAL` All tones will play at the normal volume level.
/// - `VOLUME_ALWAYS_HIGH` All tones will play at the high volume level.
</span><span class="kw">pub fn </span>volume_mode(<span class="kw-2">&amp;</span><span class="self">self</span>, mode: u8) {
<span class="kw">unsafe </span>{ sound_volume_mode(mode) }
}
}
</code></pre></div></section></main></body></html>

View file

@ -1,501 +0,0 @@
<!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="Source of the Rust file `arduboy-rust/src/library/arduboy_tone_pitch.rs`."><title>arduboy_tone_pitch.rs - source</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-47e7ab555ef2818a.css"><meta name="rustdoc-vars" data-root-path="../../../" data-static-root-path="../../../static.files/" data-current-crate="arduboy_rust" data-themes="" data-resource-suffix="" data-rustdoc-version="1.74.0-nightly (d9c8274fb 2023-09-12)" data-channel="nightly" data-search-js="search-5d3eaacf19ebf04f.js" data-settings-js="settings-74424d7eec62a23e.js" data-settings-css="settings-8c76f75bfb6bd192.css" data-theme-light-css="light-f194925aa375ae96.css" data-theme-dark-css="dark-1dd4d1ce031e15de.css" data-theme-ayu-css="ayu-49e58d069f567085.css" ><script src="../../../static.files/storage-db41da1a38ea3cb8.js"></script><script defer src="../../../static.files/src-script-3280b574d94e47b4.js"></script><script defer src="../../../src-files.js"></script><script defer src="../../../static.files/main-8d035c8cea6edbc4.js"></script><noscript><link rel="stylesheet" media="(prefers-color-scheme:light)" href="../../../static.files/light-f194925aa375ae96.css"><link rel="stylesheet" media="(prefers-color-scheme:dark)" href="../../../static.files/dark-1dd4d1ce031e15de.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 src"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"></nav><main><nav class="sub"><a class="sub-logo-container" href="../../../arduboy_rust/index.html"><img class="rust-logo" src="../../../static.files/rust-logo-151179464ae7ed46.svg" alt="logo"></a><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="example-wrap"><div data-nosnippet><pre class="src-line-numbers"><a href="#1" id="1">1</a>
<a href="#2" id="2">2</a>
<a href="#3" id="3">3</a>
<a href="#4" id="4">4</a>
<a href="#5" id="5">5</a>
<a href="#6" id="6">6</a>
<a href="#7" id="7">7</a>
<a href="#8" id="8">8</a>
<a href="#9" id="9">9</a>
<a href="#10" id="10">10</a>
<a href="#11" id="11">11</a>
<a href="#12" id="12">12</a>
<a href="#13" id="13">13</a>
<a href="#14" id="14">14</a>
<a href="#15" id="15">15</a>
<a href="#16" id="16">16</a>
<a href="#17" id="17">17</a>
<a href="#18" id="18">18</a>
<a href="#19" id="19">19</a>
<a href="#20" id="20">20</a>
<a href="#21" id="21">21</a>
<a href="#22" id="22">22</a>
<a href="#23" id="23">23</a>
<a href="#24" id="24">24</a>
<a href="#25" id="25">25</a>
<a href="#26" id="26">26</a>
<a href="#27" id="27">27</a>
<a href="#28" id="28">28</a>
<a href="#29" id="29">29</a>
<a href="#30" id="30">30</a>
<a href="#31" id="31">31</a>
<a href="#32" id="32">32</a>
<a href="#33" id="33">33</a>
<a href="#34" id="34">34</a>
<a href="#35" id="35">35</a>
<a href="#36" id="36">36</a>
<a href="#37" id="37">37</a>
<a href="#38" id="38">38</a>
<a href="#39" id="39">39</a>
<a href="#40" id="40">40</a>
<a href="#41" id="41">41</a>
<a href="#42" id="42">42</a>
<a href="#43" id="43">43</a>
<a href="#44" id="44">44</a>
<a href="#45" id="45">45</a>
<a href="#46" id="46">46</a>
<a href="#47" id="47">47</a>
<a href="#48" id="48">48</a>
<a href="#49" id="49">49</a>
<a href="#50" id="50">50</a>
<a href="#51" id="51">51</a>
<a href="#52" id="52">52</a>
<a href="#53" id="53">53</a>
<a href="#54" id="54">54</a>
<a href="#55" id="55">55</a>
<a href="#56" id="56">56</a>
<a href="#57" id="57">57</a>
<a href="#58" id="58">58</a>
<a href="#59" id="59">59</a>
<a href="#60" id="60">60</a>
<a href="#61" id="61">61</a>
<a href="#62" id="62">62</a>
<a href="#63" id="63">63</a>
<a href="#64" id="64">64</a>
<a href="#65" id="65">65</a>
<a href="#66" id="66">66</a>
<a href="#67" id="67">67</a>
<a href="#68" id="68">68</a>
<a href="#69" id="69">69</a>
<a href="#70" id="70">70</a>
<a href="#71" id="71">71</a>
<a href="#72" id="72">72</a>
<a href="#73" id="73">73</a>
<a href="#74" id="74">74</a>
<a href="#75" id="75">75</a>
<a href="#76" id="76">76</a>
<a href="#77" id="77">77</a>
<a href="#78" id="78">78</a>
<a href="#79" id="79">79</a>
<a href="#80" id="80">80</a>
<a href="#81" id="81">81</a>
<a href="#82" id="82">82</a>
<a href="#83" id="83">83</a>
<a href="#84" id="84">84</a>
<a href="#85" id="85">85</a>
<a href="#86" id="86">86</a>
<a href="#87" id="87">87</a>
<a href="#88" id="88">88</a>
<a href="#89" id="89">89</a>
<a href="#90" id="90">90</a>
<a href="#91" id="91">91</a>
<a href="#92" id="92">92</a>
<a href="#93" id="93">93</a>
<a href="#94" id="94">94</a>
<a href="#95" id="95">95</a>
<a href="#96" id="96">96</a>
<a href="#97" id="97">97</a>
<a href="#98" id="98">98</a>
<a href="#99" id="99">99</a>
<a href="#100" id="100">100</a>
<a href="#101" id="101">101</a>
<a href="#102" id="102">102</a>
<a href="#103" id="103">103</a>
<a href="#104" id="104">104</a>
<a href="#105" id="105">105</a>
<a href="#106" id="106">106</a>
<a href="#107" id="107">107</a>
<a href="#108" id="108">108</a>
<a href="#109" id="109">109</a>
<a href="#110" id="110">110</a>
<a href="#111" id="111">111</a>
<a href="#112" id="112">112</a>
<a href="#113" id="113">113</a>
<a href="#114" id="114">114</a>
<a href="#115" id="115">115</a>
<a href="#116" id="116">116</a>
<a href="#117" id="117">117</a>
<a href="#118" id="118">118</a>
<a href="#119" id="119">119</a>
<a href="#120" id="120">120</a>
<a href="#121" id="121">121</a>
<a href="#122" id="122">122</a>
<a href="#123" id="123">123</a>
<a href="#124" id="124">124</a>
<a href="#125" id="125">125</a>
<a href="#126" id="126">126</a>
<a href="#127" id="127">127</a>
<a href="#128" id="128">128</a>
<a href="#129" id="129">129</a>
<a href="#130" id="130">130</a>
<a href="#131" id="131">131</a>
<a href="#132" id="132">132</a>
<a href="#133" id="133">133</a>
<a href="#134" id="134">134</a>
<a href="#135" id="135">135</a>
<a href="#136" id="136">136</a>
<a href="#137" id="137">137</a>
<a href="#138" id="138">138</a>
<a href="#139" id="139">139</a>
<a href="#140" id="140">140</a>
<a href="#141" id="141">141</a>
<a href="#142" id="142">142</a>
<a href="#143" id="143">143</a>
<a href="#144" id="144">144</a>
<a href="#145" id="145">145</a>
<a href="#146" id="146">146</a>
<a href="#147" id="147">147</a>
<a href="#148" id="148">148</a>
<a href="#149" id="149">149</a>
<a href="#150" id="150">150</a>
<a href="#151" id="151">151</a>
<a href="#152" id="152">152</a>
<a href="#153" id="153">153</a>
<a href="#154" id="154">154</a>
<a href="#155" id="155">155</a>
<a href="#156" id="156">156</a>
<a href="#157" id="157">157</a>
<a href="#158" id="158">158</a>
<a href="#159" id="159">159</a>
<a href="#160" id="160">160</a>
<a href="#161" id="161">161</a>
<a href="#162" id="162">162</a>
<a href="#163" id="163">163</a>
<a href="#164" id="164">164</a>
<a href="#165" id="165">165</a>
<a href="#166" id="166">166</a>
<a href="#167" id="167">167</a>
<a href="#168" id="168">168</a>
<a href="#169" id="169">169</a>
<a href="#170" id="170">170</a>
<a href="#171" id="171">171</a>
<a href="#172" id="172">172</a>
<a href="#173" id="173">173</a>
<a href="#174" id="174">174</a>
<a href="#175" id="175">175</a>
<a href="#176" id="176">176</a>
<a href="#177" id="177">177</a>
<a href="#178" id="178">178</a>
<a href="#179" id="179">179</a>
<a href="#180" id="180">180</a>
<a href="#181" id="181">181</a>
<a href="#182" id="182">182</a>
<a href="#183" id="183">183</a>
<a href="#184" id="184">184</a>
<a href="#185" id="185">185</a>
<a href="#186" id="186">186</a>
<a href="#187" id="187">187</a>
<a href="#188" id="188">188</a>
<a href="#189" id="189">189</a>
<a href="#190" id="190">190</a>
<a href="#191" id="191">191</a>
<a href="#192" id="192">192</a>
<a href="#193" id="193">193</a>
<a href="#194" id="194">194</a>
<a href="#195" id="195">195</a>
<a href="#196" id="196">196</a>
<a href="#197" id="197">197</a>
<a href="#198" id="198">198</a>
<a href="#199" id="199">199</a>
<a href="#200" id="200">200</a>
<a href="#201" id="201">201</a>
<a href="#202" id="202">202</a>
<a href="#203" id="203">203</a>
<a href="#204" id="204">204</a>
<a href="#205" id="205">205</a>
<a href="#206" id="206">206</a>
<a href="#207" id="207">207</a>
<a href="#208" id="208">208</a>
<a href="#209" id="209">209</a>
<a href="#210" id="210">210</a>
<a href="#211" id="211">211</a>
<a href="#212" id="212">212</a>
<a href="#213" id="213">213</a>
<a href="#214" id="214">214</a>
<a href="#215" id="215">215</a>
<a href="#216" id="216">216</a>
<a href="#217" id="217">217</a>
<a href="#218" id="218">218</a>
<a href="#219" id="219">219</a>
<a href="#220" id="220">220</a>
<a href="#221" id="221">221</a>
<a href="#222" id="222">222</a>
<a href="#223" id="223">223</a>
<a href="#224" id="224">224</a>
<a href="#225" id="225">225</a>
<a href="#226" id="226">226</a>
<a href="#227" id="227">227</a>
<a href="#228" id="228">228</a>
<a href="#229" id="229">229</a>
<a href="#230" id="230">230</a>
<a href="#231" id="231">231</a>
<a href="#232" id="232">232</a>
<a href="#233" id="233">233</a>
<a href="#234" id="234">234</a>
<a href="#235" id="235">235</a>
<a href="#236" id="236">236</a>
<a href="#237" id="237">237</a>
<a href="#238" id="238">238</a>
<a href="#239" id="239">239</a>
<a href="#240" id="240">240</a>
<a href="#241" id="241">241</a>
<a href="#242" id="242">242</a>
<a href="#243" id="243">243</a>
<a href="#244" id="244">244</a>
<a href="#245" id="245">245</a>
<a href="#246" id="246">246</a>
<a href="#247" id="247">247</a>
<a href="#248" id="248">248</a>
<a href="#249" id="249">249</a>
<a href="#250" id="250">250</a>
</pre></div><pre class="rust"><code><span class="doccomment">//! A list of all tones available and used by the Sounds library Arduboy2Tones
</span><span class="kw">pub const </span>TONES_END: u16 = <span class="number">0x8000</span>;
<span class="kw">pub const </span>TONES_REPEAT: u16 = <span class="number">0x8001</span>;
<span class="kw">pub const </span>TONE_HIGH_VOLUME: u16 = <span class="number">0x8000</span>;
<span class="kw">pub const </span>VOLUME_IN_TONE: u8 = <span class="number">0</span>;
<span class="kw">pub const </span>VOLUME_ALWAYS_NORMAL: u8 = <span class="number">1</span>;
<span class="kw">pub const </span>VOLUME_ALWAYS_HIGH: u8 = <span class="number">2</span>;
<span class="kw">pub const </span>NOTE_REST: u16 = <span class="number">0</span>;
<span class="kw">pub const </span>NOTE_C0: u16 = <span class="number">16</span>;
<span class="kw">pub const </span>NOTE_CS0: u16 = <span class="number">17</span>;
<span class="kw">pub const </span>NOTE_D0: u16 = <span class="number">18</span>;
<span class="kw">pub const </span>NOTE_DS0: u16 = <span class="number">19</span>;
<span class="kw">pub const </span>NOTE_E0: u16 = <span class="number">21</span>;
<span class="kw">pub const </span>NOTE_F0: u16 = <span class="number">22</span>;
<span class="kw">pub const </span>NOTE_FS0: u16 = <span class="number">23</span>;
<span class="kw">pub const </span>NOTE_G0: u16 = <span class="number">25</span>;
<span class="kw">pub const </span>NOTE_GS0: u16 = <span class="number">26</span>;
<span class="kw">pub const </span>NOTE_A0: u16 = <span class="number">28</span>;
<span class="kw">pub const </span>NOTE_AS0: u16 = <span class="number">29</span>;
<span class="kw">pub const </span>NOTE_B0: u16 = <span class="number">31</span>;
<span class="kw">pub const </span>NOTE_C1: u16 = <span class="number">33</span>;
<span class="kw">pub const </span>NOTE_CS1: u16 = <span class="number">35</span>;
<span class="kw">pub const </span>NOTE_D1: u16 = <span class="number">37</span>;
<span class="kw">pub const </span>NOTE_DS1: u16 = <span class="number">39</span>;
<span class="kw">pub const </span>NOTE_E1: u16 = <span class="number">41</span>;
<span class="kw">pub const </span>NOTE_F1: u16 = <span class="number">44</span>;
<span class="kw">pub const </span>NOTE_FS1: u16 = <span class="number">46</span>;
<span class="kw">pub const </span>NOTE_G1: u16 = <span class="number">49</span>;
<span class="kw">pub const </span>NOTE_GS1: u16 = <span class="number">52</span>;
<span class="kw">pub const </span>NOTE_A1: u16 = <span class="number">55</span>;
<span class="kw">pub const </span>NOTE_AS1: u16 = <span class="number">58</span>;
<span class="kw">pub const </span>NOTE_B1: u16 = <span class="number">62</span>;
<span class="kw">pub const </span>NOTE_C2: u16 = <span class="number">65</span>;
<span class="kw">pub const </span>NOTE_CS2: u16 = <span class="number">69</span>;
<span class="kw">pub const </span>NOTE_D2: u16 = <span class="number">73</span>;
<span class="kw">pub const </span>NOTE_DS2: u16 = <span class="number">78</span>;
<span class="kw">pub const </span>NOTE_E2: u16 = <span class="number">82</span>;
<span class="kw">pub const </span>NOTE_F2: u16 = <span class="number">87</span>;
<span class="kw">pub const </span>NOTE_FS2: u16 = <span class="number">93</span>;
<span class="kw">pub const </span>NOTE_G2: u16 = <span class="number">98</span>;
<span class="kw">pub const </span>NOTE_GS2: u16 = <span class="number">104</span>;
<span class="kw">pub const </span>NOTE_A2: u16 = <span class="number">110</span>;
<span class="kw">pub const </span>NOTE_AS2: u16 = <span class="number">117</span>;
<span class="kw">pub const </span>NOTE_B2: u16 = <span class="number">123</span>;
<span class="kw">pub const </span>NOTE_C3: u16 = <span class="number">131</span>;
<span class="kw">pub const </span>NOTE_CS3: u16 = <span class="number">139</span>;
<span class="kw">pub const </span>NOTE_D3: u16 = <span class="number">147</span>;
<span class="kw">pub const </span>NOTE_DS3: u16 = <span class="number">156</span>;
<span class="kw">pub const </span>NOTE_E3: u16 = <span class="number">165</span>;
<span class="kw">pub const </span>NOTE_F3: u16 = <span class="number">175</span>;
<span class="kw">pub const </span>NOTE_FS3: u16 = <span class="number">185</span>;
<span class="kw">pub const </span>NOTE_G3: u16 = <span class="number">196</span>;
<span class="kw">pub const </span>NOTE_GS3: u16 = <span class="number">208</span>;
<span class="kw">pub const </span>NOTE_A3: u16 = <span class="number">220</span>;
<span class="kw">pub const </span>NOTE_AS3: u16 = <span class="number">233</span>;
<span class="kw">pub const </span>NOTE_B3: u16 = <span class="number">247</span>;
<span class="kw">pub const </span>NOTE_C4: u16 = <span class="number">262</span>;
<span class="kw">pub const </span>NOTE_CS4: u16 = <span class="number">277</span>;
<span class="kw">pub const </span>NOTE_D4: u16 = <span class="number">294</span>;
<span class="kw">pub const </span>NOTE_DS4: u16 = <span class="number">311</span>;
<span class="kw">pub const </span>NOTE_E4: u16 = <span class="number">330</span>;
<span class="kw">pub const </span>NOTE_F4: u16 = <span class="number">349</span>;
<span class="kw">pub const </span>NOTE_FS4: u16 = <span class="number">370</span>;
<span class="kw">pub const </span>NOTE_G4: u16 = <span class="number">392</span>;
<span class="kw">pub const </span>NOTE_GS4: u16 = <span class="number">415</span>;
<span class="kw">pub const </span>NOTE_A4: u16 = <span class="number">440</span>;
<span class="kw">pub const </span>NOTE_AS4: u16 = <span class="number">466</span>;
<span class="kw">pub const </span>NOTE_B4: u16 = <span class="number">494</span>;
<span class="kw">pub const </span>NOTE_C5: u16 = <span class="number">523</span>;
<span class="kw">pub const </span>NOTE_CS5: u16 = <span class="number">554</span>;
<span class="kw">pub const </span>NOTE_D5: u16 = <span class="number">587</span>;
<span class="kw">pub const </span>NOTE_DS5: u16 = <span class="number">622</span>;
<span class="kw">pub const </span>NOTE_E5: u16 = <span class="number">659</span>;
<span class="kw">pub const </span>NOTE_F5: u16 = <span class="number">698</span>;
<span class="kw">pub const </span>NOTE_FS5: u16 = <span class="number">740</span>;
<span class="kw">pub const </span>NOTE_G5: u16 = <span class="number">784</span>;
<span class="kw">pub const </span>NOTE_GS5: u16 = <span class="number">831</span>;
<span class="kw">pub const </span>NOTE_A5: u16 = <span class="number">880</span>;
<span class="kw">pub const </span>NOTE_AS5: u16 = <span class="number">932</span>;
<span class="kw">pub const </span>NOTE_B5: u16 = <span class="number">988</span>;
<span class="kw">pub const </span>NOTE_C6: u16 = <span class="number">1047</span>;
<span class="kw">pub const </span>NOTE_CS6: u16 = <span class="number">1109</span>;
<span class="kw">pub const </span>NOTE_D6: u16 = <span class="number">1175</span>;
<span class="kw">pub const </span>NOTE_DS6: u16 = <span class="number">1245</span>;
<span class="kw">pub const </span>NOTE_E6: u16 = <span class="number">1319</span>;
<span class="kw">pub const </span>NOTE_F6: u16 = <span class="number">1397</span>;
<span class="kw">pub const </span>NOTE_FS6: u16 = <span class="number">1480</span>;
<span class="kw">pub const </span>NOTE_G6: u16 = <span class="number">1568</span>;
<span class="kw">pub const </span>NOTE_GS6: u16 = <span class="number">1661</span>;
<span class="kw">pub const </span>NOTE_A6: u16 = <span class="number">1760</span>;
<span class="kw">pub const </span>NOTE_AS6: u16 = <span class="number">1865</span>;
<span class="kw">pub const </span>NOTE_B6: u16 = <span class="number">1976</span>;
<span class="kw">pub const </span>NOTE_C7: u16 = <span class="number">2093</span>;
<span class="kw">pub const </span>NOTE_CS7: u16 = <span class="number">2218</span>;
<span class="kw">pub const </span>NOTE_D7: u16 = <span class="number">2349</span>;
<span class="kw">pub const </span>NOTE_DS7: u16 = <span class="number">2489</span>;
<span class="kw">pub const </span>NOTE_E7: u16 = <span class="number">2637</span>;
<span class="kw">pub const </span>NOTE_F7: u16 = <span class="number">2794</span>;
<span class="kw">pub const </span>NOTE_FS7: u16 = <span class="number">2960</span>;
<span class="kw">pub const </span>NOTE_G7: u16 = <span class="number">3136</span>;
<span class="kw">pub const </span>NOTE_GS7: u16 = <span class="number">3322</span>;
<span class="kw">pub const </span>NOTE_A7: u16 = <span class="number">3520</span>;
<span class="kw">pub const </span>NOTE_AS7: u16 = <span class="number">3729</span>;
<span class="kw">pub const </span>NOTE_B7: u16 = <span class="number">3951</span>;
<span class="kw">pub const </span>NOTE_C8: u16 = <span class="number">4186</span>;
<span class="kw">pub const </span>NOTE_CS8: u16 = <span class="number">4435</span>;
<span class="kw">pub const </span>NOTE_D8: u16 = <span class="number">4699</span>;
<span class="kw">pub const </span>NOTE_DS8: u16 = <span class="number">4978</span>;
<span class="kw">pub const </span>NOTE_E8: u16 = <span class="number">5274</span>;
<span class="kw">pub const </span>NOTE_F8: u16 = <span class="number">5588</span>;
<span class="kw">pub const </span>NOTE_FS8: u16 = <span class="number">5920</span>;
<span class="kw">pub const </span>NOTE_G8: u16 = <span class="number">6272</span>;
<span class="kw">pub const </span>NOTE_GS8: u16 = <span class="number">6645</span>;
<span class="kw">pub const </span>NOTE_A8: u16 = <span class="number">7040</span>;
<span class="kw">pub const </span>NOTE_AS8: u16 = <span class="number">7459</span>;
<span class="kw">pub const </span>NOTE_B8: u16 = <span class="number">7902</span>;
<span class="kw">pub const </span>NOTE_C9: u16 = <span class="number">8372</span>;
<span class="kw">pub const </span>NOTE_CS9: u16 = <span class="number">8870</span>;
<span class="kw">pub const </span>NOTE_D9: u16 = <span class="number">9397</span>;
<span class="kw">pub const </span>NOTE_DS9: u16 = <span class="number">9956</span>;
<span class="kw">pub const </span>NOTE_E9: u16 = <span class="number">10548</span>;
<span class="kw">pub const </span>NOTE_F9: u16 = <span class="number">11175</span>;
<span class="kw">pub const </span>NOTE_FS9: u16 = <span class="number">11840</span>;
<span class="kw">pub const </span>NOTE_G9: u16 = <span class="number">12544</span>;
<span class="kw">pub const </span>NOTE_GS9: u16 = <span class="number">13290</span>;
<span class="kw">pub const </span>NOTE_A9: u16 = <span class="number">14080</span>;
<span class="kw">pub const </span>NOTE_AS9: u16 = <span class="number">14917</span>;
<span class="kw">pub const </span>NOTE_B9: u16 = <span class="number">15804</span>;
<span class="kw">pub const </span>NOTE_C0H: u16 = NOTE_C0 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_CS0H: u16 = NOTE_CS0 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_D0H: u16 = NOTE_D0 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_DS0H: u16 = NOTE_DS0 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_E0H: u16 = NOTE_E0 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_F0H: u16 = NOTE_F0 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_FS0H: u16 = NOTE_FS0 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_G0H: u16 = NOTE_G0 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_GS0H: u16 = NOTE_GS0 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_A0H: u16 = NOTE_A0 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_AS0H: u16 = NOTE_AS0 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_B0H: u16 = NOTE_B0 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_C1H: u16 = NOTE_C1 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_CS1H: u16 = NOTE_CS1 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_D1H: u16 = NOTE_D1 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_DS1H: u16 = NOTE_DS1 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_E1H: u16 = NOTE_E1 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_F1H: u16 = NOTE_F1 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_FS1H: u16 = NOTE_FS1 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_G1H: u16 = NOTE_G1 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_GS1H: u16 = NOTE_GS1 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_A1H: u16 = NOTE_A1 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_AS1H: u16 = NOTE_AS1 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_B1H: u16 = NOTE_B1 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_C2H: u16 = NOTE_C2 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_CS2H: u16 = NOTE_CS2 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_D2H: u16 = NOTE_D2 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_DS2H: u16 = NOTE_DS2 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_E2H: u16 = NOTE_E2 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_F2H: u16 = NOTE_F2 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_FS2H: u16 = NOTE_FS2 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_G2H: u16 = NOTE_G2 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_GS2H: u16 = NOTE_GS2 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_A2H: u16 = NOTE_A2 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_AS2H: u16 = NOTE_AS2 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_B2H: u16 = NOTE_B2 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_C3H: u16 = NOTE_C3 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_CS3H: u16 = NOTE_CS3 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_D3H: u16 = NOTE_D3 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_DS3H: u16 = NOTE_DS3 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_E3H: u16 = NOTE_E3 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_F3H: u16 = NOTE_F3 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_FS3H: u16 = NOTE_F3 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_G3H: u16 = NOTE_G3 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_GS3H: u16 = NOTE_GS3 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_A3H: u16 = NOTE_A3 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_AS3H: u16 = NOTE_AS3 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_B3H: u16 = NOTE_B3 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_C4H: u16 = NOTE_C4 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_CS4H: u16 = NOTE_CS4 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_D4H: u16 = NOTE_D4 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_DS4H: u16 = NOTE_DS4 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_E4H: u16 = NOTE_E4 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_F4H: u16 = NOTE_F4 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_FS4H: u16 = NOTE_FS4 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_G4H: u16 = NOTE_G4 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_GS4H: u16 = NOTE_GS4 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_A4H: u16 = NOTE_A4 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_AS4H: u16 = NOTE_AS4 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_B4H: u16 = NOTE_B4 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_C5H: u16 = NOTE_C5 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_CS5H: u16 = NOTE_CS5 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_D5H: u16 = NOTE_D5 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_DS5H: u16 = NOTE_DS5 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_E5H: u16 = NOTE_E5 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_F5H: u16 = NOTE_F5 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_FS5H: u16 = NOTE_FS5 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_G5H: u16 = NOTE_G5 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_GS5H: u16 = NOTE_GS5 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_A5H: u16 = NOTE_A5 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_AS5H: u16 = NOTE_AS5 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_B5H: u16 = NOTE_B5 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_C6H: u16 = NOTE_C6 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_CS6H: u16 = NOTE_CS6 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_D6H: u16 = NOTE_D6 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_DS6H: u16 = NOTE_DS6 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_E6H: u16 = NOTE_E6 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_F6H: u16 = NOTE_F6 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_FS6H: u16 = NOTE_FS6 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_G6H: u16 = NOTE_G6 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_GS6H: u16 = NOTE_GS6 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_A6H: u16 = NOTE_A6 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_AS6H: u16 = NOTE_AS6 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_B6H: u16 = NOTE_B6 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_C7H: u16 = NOTE_C7 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_CS7H: u16 = NOTE_CS7 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_D7H: u16 = NOTE_D7 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_DS7H: u16 = NOTE_DS7 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_E7H: u16 = NOTE_E7 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_F7H: u16 = NOTE_F7 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_FS7H: u16 = NOTE_FS7 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_G7H: u16 = NOTE_G7 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_GS7H: u16 = NOTE_GS7 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_A7H: u16 = NOTE_A7 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_AS7H: u16 = NOTE_AS7 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_B7H: u16 = NOTE_B7 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_C8H: u16 = NOTE_C8 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_CS8H: u16 = NOTE_CS8 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_D8H: u16 = NOTE_D8 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_DS8H: u16 = NOTE_DS8 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_E8H: u16 = NOTE_E8 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_F8H: u16 = NOTE_F8 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_FS8H: u16 = NOTE_FS8 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_G8H: u16 = NOTE_G8 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_GS8H: u16 = NOTE_GS8 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_A8H: u16 = NOTE_A8 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_AS8H: u16 = NOTE_AS8 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_B8H: u16 = NOTE_B8 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_C9H: u16 = NOTE_C9 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_CS9H: u16 = NOTE_CS9 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_D9H: u16 = NOTE_D9 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_DS9H: u16 = NOTE_DS9 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_E9H: u16 = NOTE_E9 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_F9H: u16 = NOTE_F9 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_FS9H: u16 = NOTE_FS9 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_G9H: u16 = NOTE_G9 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_GS9H: u16 = NOTE_GS9 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_A9H: u16 = NOTE_A9 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_AS9H: u16 = NOTE_AS9 + TONE_HIGH_VOLUME;
<span class="kw">pub const </span>NOTE_B9H: u16 = NOTE_B9 + TONE_HIGH_VOLUME;
</code></pre></div></section></main></body></html>

View file

@ -1,55 +0,0 @@
<!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="Source of the Rust file `arduboy-rust/src/library/arduino.rs`."><title>arduino.rs - source</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-47e7ab555ef2818a.css"><meta name="rustdoc-vars" data-root-path="../../../" data-static-root-path="../../../static.files/" data-current-crate="arduboy_rust" data-themes="" data-resource-suffix="" data-rustdoc-version="1.74.0-nightly (d9c8274fb 2023-09-12)" data-channel="nightly" data-search-js="search-5d3eaacf19ebf04f.js" data-settings-js="settings-74424d7eec62a23e.js" data-settings-css="settings-8c76f75bfb6bd192.css" data-theme-light-css="light-f194925aa375ae96.css" data-theme-dark-css="dark-1dd4d1ce031e15de.css" data-theme-ayu-css="ayu-49e58d069f567085.css" ><script src="../../../static.files/storage-db41da1a38ea3cb8.js"></script><script defer src="../../../static.files/src-script-3280b574d94e47b4.js"></script><script defer src="../../../src-files.js"></script><script defer src="../../../static.files/main-8d035c8cea6edbc4.js"></script><noscript><link rel="stylesheet" media="(prefers-color-scheme:light)" href="../../../static.files/light-f194925aa375ae96.css"><link rel="stylesheet" media="(prefers-color-scheme:dark)" href="../../../static.files/dark-1dd4d1ce031e15de.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 src"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"></nav><main><nav class="sub"><a class="sub-logo-container" href="../../../arduboy_rust/index.html"><img class="rust-logo" src="../../../static.files/rust-logo-151179464ae7ed46.svg" alt="logo"></a><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="example-wrap"><div data-nosnippet><pre class="src-line-numbers"><a href="#1" id="1">1</a>
<a href="#2" id="2">2</a>
<a href="#3" id="3">3</a>
<a href="#4" id="4">4</a>
<a href="#5" id="5">5</a>
<a href="#6" id="6">6</a>
<a href="#7" id="7">7</a>
<a href="#8" id="8">8</a>
<a href="#9" id="9">9</a>
<a href="#10" id="10">10</a>
<a href="#11" id="11">11</a>
<a href="#12" id="12">12</a>
<a href="#13" id="13">13</a>
<a href="#14" id="14">14</a>
<a href="#15" id="15">15</a>
<a href="#16" id="16">16</a>
<a href="#17" id="17">17</a>
<a href="#18" id="18">18</a>
<a href="#19" id="19">19</a>
<a href="#20" id="20">20</a>
<a href="#21" id="21">21</a>
<a href="#22" id="22">22</a>
<a href="#23" id="23">23</a>
<a href="#24" id="24">24</a>
<a href="#25" id="25">25</a>
<a href="#26" id="26">26</a>
<a href="#27" id="27">27</a>
</pre></div><pre class="rust"><code><span class="doccomment">//! This is the Module to interact in a save way with the Arduino C++ library.
</span><span class="kw">use </span>core::ffi::{c_long, c_ulong};
<span class="kw">extern </span><span class="string">&quot;C&quot; </span>{
<span class="attr">#[link_name = <span class="string">&quot;arduino_random_between&quot;</span>]
</span><span class="kw">fn </span>arduino_random_between_raw(min: c_long, max: c_long) -&gt; c_long;
<span class="attr">#[link_name = <span class="string">&quot;arduino_random_less_than&quot;</span>]
</span><span class="kw">fn </span>arduino_random_less_than_raw(max: c_long) -&gt; c_long;
<span class="attr">#[link_name = <span class="string">&quot;arduino_delay&quot;</span>]
</span><span class="kw">fn </span>arduino_delay(ms: c_ulong);
}
<span class="doccomment">/// A Arduino function to get a random number between 2 numbers
/// seed based
</span><span class="kw">pub fn </span>random_between(min: i32, max: i32) -&gt; i32 {
<span class="kw">unsafe </span>{ arduino_random_between_raw(min, max) }
}
<span class="doccomment">/// A Arduino function to get a random number smaller than the number given
/// seed based
</span><span class="kw">pub fn </span>random_less_than(max: i32) -&gt; i32 {
<span class="kw">unsafe </span>{ arduino_random_less_than_raw(max) }
}
<span class="doccomment">/// A Arduino function to pause the cpu circles for a given amount of ms
</span><span class="kw">pub fn </span>delay(ms: u32) {
<span class="kw">unsafe </span>{ arduino_delay(ms) }
}
</code></pre></div></section></main></body></html>

View file

@ -1,85 +0,0 @@
<!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="Source of the Rust file `arduboy-rust/src/library/ardvoice.rs`."><title>ardvoice.rs - source</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-47e7ab555ef2818a.css"><meta name="rustdoc-vars" data-root-path="../../../" data-static-root-path="../../../static.files/" data-current-crate="arduboy_rust" data-themes="" data-resource-suffix="" data-rustdoc-version="1.74.0-nightly (d9c8274fb 2023-09-12)" data-channel="nightly" data-search-js="search-5d3eaacf19ebf04f.js" data-settings-js="settings-74424d7eec62a23e.js" data-settings-css="settings-8c76f75bfb6bd192.css" data-theme-light-css="light-f194925aa375ae96.css" data-theme-dark-css="dark-1dd4d1ce031e15de.css" data-theme-ayu-css="ayu-49e58d069f567085.css" ><script src="../../../static.files/storage-db41da1a38ea3cb8.js"></script><script defer src="../../../static.files/src-script-3280b574d94e47b4.js"></script><script defer src="../../../src-files.js"></script><script defer src="../../../static.files/main-8d035c8cea6edbc4.js"></script><noscript><link rel="stylesheet" media="(prefers-color-scheme:light)" href="../../../static.files/light-f194925aa375ae96.css"><link rel="stylesheet" media="(prefers-color-scheme:dark)" href="../../../static.files/dark-1dd4d1ce031e15de.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 src"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"></nav><main><nav class="sub"><a class="sub-logo-container" href="../../../arduboy_rust/index.html"><img class="rust-logo" src="../../../static.files/rust-logo-151179464ae7ed46.svg" alt="logo"></a><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="example-wrap"><div data-nosnippet><pre class="src-line-numbers"><a href="#1" id="1">1</a>
<a href="#2" id="2">2</a>
<a href="#3" id="3">3</a>
<a href="#4" id="4">4</a>
<a href="#5" id="5">5</a>
<a href="#6" id="6">6</a>
<a href="#7" id="7">7</a>
<a href="#8" id="8">8</a>
<a href="#9" id="9">9</a>
<a href="#10" id="10">10</a>
<a href="#11" id="11">11</a>
<a href="#12" id="12">12</a>
<a href="#13" id="13">13</a>
<a href="#14" id="14">14</a>
<a href="#15" id="15">15</a>
<a href="#16" id="16">16</a>
<a href="#17" id="17">17</a>
<a href="#18" id="18">18</a>
<a href="#19" id="19">19</a>
<a href="#20" id="20">20</a>
<a href="#21" id="21">21</a>
<a href="#22" id="22">22</a>
<a href="#23" id="23">23</a>
<a href="#24" id="24">24</a>
<a href="#25" id="25">25</a>
<a href="#26" id="26">26</a>
<a href="#27" id="27">27</a>
<a href="#28" id="28">28</a>
<a href="#29" id="29">29</a>
<a href="#30" id="30">30</a>
<a href="#31" id="31">31</a>
<a href="#32" id="32">32</a>
<a href="#33" id="33">33</a>
<a href="#34" id="34">34</a>
<a href="#35" id="35">35</a>
<a href="#36" id="36">36</a>
<a href="#37" id="37">37</a>
<a href="#38" id="38">38</a>
<a href="#39" id="39">39</a>
<a href="#40" id="40">40</a>
<a href="#41" id="41">41</a>
<a href="#42" id="42">42</a>
</pre></div><pre class="rust"><code><span class="doccomment">//! This is the Module to interact in a save way with the ArdVoice C++ library.
//!
//! You will need to uncomment the ArdVoice_Library in the import_config.h file.
</span><span class="kw">use </span>core::ffi::{c_float, c_uchar, c_ulong};
<span class="kw">extern </span><span class="string">&quot;C&quot; </span>{
<span class="attr">#[link_name = <span class="string">&quot;ardvoice_play_voice&quot;</span>]
</span><span class="kw">fn </span>ardvoice_play_voice_raw(audio: <span class="kw-2">*const </span>c_uchar);
<span class="attr">#[link_name = <span class="string">&quot;ardvoice_play_voice_complex&quot;</span>]
</span><span class="kw">fn </span>ardvoice_play_voice_complex_raw(
audio: <span class="kw-2">*const </span>c_uchar,
startTime: c_ulong,
endTime: c_ulong,
speed: c_float,
);
<span class="attr">#[link_name = <span class="string">&quot;ardvoice_stop_voice&quot;</span>]
</span><span class="kw">fn </span>ardvoice_stop_voice_raw();
<span class="attr">#[link_name = <span class="string">&quot;ardvoice_is_voice_playing&quot;</span>]
</span><span class="kw">fn </span>ardvoice_is_voice_playing_raw() -&gt; bool;
}
<span class="doccomment">///This is the struct to interact in a save way with the ArdVoice C++ library.
///
///You will need to uncomment the ArdVoice_Library in the import_config.h file.
</span><span class="kw">pub struct </span>ArdVoice {}
<span class="kw">impl </span>ArdVoice {
<span class="kw">pub const fn </span>new() -&gt; <span class="self">Self </span>{
ArdVoice {}
}
<span class="kw">pub fn </span>play_voice(<span class="kw-2">&amp;</span><span class="self">self</span>, audio: <span class="kw-2">*const </span>u8) {
<span class="kw">unsafe </span>{ ardvoice_play_voice_raw(audio) }
}
<span class="kw">pub fn </span>play_voice_complex(<span class="kw-2">&amp;</span><span class="self">self</span>, audio: <span class="kw-2">*const </span>u8, start_time: u32, end_time: u32, speed: f32) {
<span class="kw">unsafe </span>{ ardvoice_play_voice_complex_raw(audio, start_time, end_time, speed) }
}
<span class="kw">pub fn </span>stop_voice(<span class="kw-2">&amp;</span><span class="self">self</span>) {
<span class="kw">unsafe </span>{ ardvoice_stop_voice_raw() }
}
<span class="kw">pub fn </span>is_voice_playing(<span class="kw-2">&amp;</span><span class="self">self</span>) -&gt; bool {
<span class="kw">unsafe </span>{ ardvoice_is_voice_playing_raw() }
}
}
</code></pre></div></section></main></body></html>

View file

@ -1,23 +0,0 @@
<!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="Source of the Rust file `arduboy-rust/src/library/c.rs`."><title>c.rs - source</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-47e7ab555ef2818a.css"><meta name="rustdoc-vars" data-root-path="../../../" data-static-root-path="../../../static.files/" data-current-crate="arduboy_rust" data-themes="" data-resource-suffix="" data-rustdoc-version="1.74.0-nightly (d9c8274fb 2023-09-12)" data-channel="nightly" data-search-js="search-5d3eaacf19ebf04f.js" data-settings-js="settings-74424d7eec62a23e.js" data-settings-css="settings-8c76f75bfb6bd192.css" data-theme-light-css="light-f194925aa375ae96.css" data-theme-dark-css="dark-1dd4d1ce031e15de.css" data-theme-ayu-css="ayu-49e58d069f567085.css" ><script src="../../../static.files/storage-db41da1a38ea3cb8.js"></script><script defer src="../../../static.files/src-script-3280b574d94e47b4.js"></script><script defer src="../../../src-files.js"></script><script defer src="../../../static.files/main-8d035c8cea6edbc4.js"></script><noscript><link rel="stylesheet" media="(prefers-color-scheme:light)" href="../../../static.files/light-f194925aa375ae96.css"><link rel="stylesheet" media="(prefers-color-scheme:dark)" href="../../../static.files/dark-1dd4d1ce031e15de.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 src"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"></nav><main><nav class="sub"><a class="sub-logo-container" href="../../../arduboy_rust/index.html"><img class="rust-logo" src="../../../static.files/rust-logo-151179464ae7ed46.svg" alt="logo"></a><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="example-wrap"><div data-nosnippet><pre class="src-line-numbers"><a href="#1" id="1">1</a>
<a href="#2" id="2">2</a>
<a href="#3" id="3">3</a>
<a href="#4" id="4">4</a>
<a href="#5" id="5">5</a>
<a href="#6" id="6">6</a>
<a href="#7" id="7">7</a>
<a href="#8" id="8">8</a>
<a href="#9" id="9">9</a>
<a href="#10" id="10">10</a>
<a href="#11" id="11">11</a>
</pre></div><pre class="rust"><code><span class="doccomment">//! Clib functions you can use on the Arduboy
</span><span class="kw">use </span>core::ffi::{c_char, c_size_t};
<span class="kw">extern </span><span class="string">&quot;C&quot; </span>{
<span class="attr">#[link_name = <span class="string">&quot;strlen&quot;</span>]
</span><span class="kw">fn </span>c_strlen(cstr: <span class="kw-2">*const </span>c_char) -&gt; c_size_t;
}
<span class="doccomment">/// A C function to get the length of a string
</span><span class="kw">pub fn </span>strlen(cstr: <span class="kw-2">*const </span>i8) -&gt; usize {
<span class="kw">unsafe </span>{ c_strlen(cstr) }
}
</code></pre></div></section></main></body></html>

View file

@ -1,331 +0,0 @@
<!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="Source of the Rust file `arduboy-rust/src/library/eeprom.rs`."><title>eeprom.rs - source</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-47e7ab555ef2818a.css"><meta name="rustdoc-vars" data-root-path="../../../" data-static-root-path="../../../static.files/" data-current-crate="arduboy_rust" data-themes="" data-resource-suffix="" data-rustdoc-version="1.74.0-nightly (d9c8274fb 2023-09-12)" data-channel="nightly" data-search-js="search-5d3eaacf19ebf04f.js" data-settings-js="settings-74424d7eec62a23e.js" data-settings-css="settings-8c76f75bfb6bd192.css" data-theme-light-css="light-f194925aa375ae96.css" data-theme-dark-css="dark-1dd4d1ce031e15de.css" data-theme-ayu-css="ayu-49e58d069f567085.css" ><script src="../../../static.files/storage-db41da1a38ea3cb8.js"></script><script defer src="../../../static.files/src-script-3280b574d94e47b4.js"></script><script defer src="../../../src-files.js"></script><script defer src="../../../static.files/main-8d035c8cea6edbc4.js"></script><noscript><link rel="stylesheet" media="(prefers-color-scheme:light)" href="../../../static.files/light-f194925aa375ae96.css"><link rel="stylesheet" media="(prefers-color-scheme:dark)" href="../../../static.files/dark-1dd4d1ce031e15de.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 src"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"></nav><main><nav class="sub"><a class="sub-logo-container" href="../../../arduboy_rust/index.html"><img class="rust-logo" src="../../../static.files/rust-logo-151179464ae7ed46.svg" alt="logo"></a><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="example-wrap"><div data-nosnippet><pre class="src-line-numbers"><a href="#1" id="1">1</a>
<a href="#2" id="2">2</a>
<a href="#3" id="3">3</a>
<a href="#4" id="4">4</a>
<a href="#5" id="5">5</a>
<a href="#6" id="6">6</a>
<a href="#7" id="7">7</a>
<a href="#8" id="8">8</a>
<a href="#9" id="9">9</a>
<a href="#10" id="10">10</a>
<a href="#11" id="11">11</a>
<a href="#12" id="12">12</a>
<a href="#13" id="13">13</a>
<a href="#14" id="14">14</a>
<a href="#15" id="15">15</a>
<a href="#16" id="16">16</a>
<a href="#17" id="17">17</a>
<a href="#18" id="18">18</a>
<a href="#19" id="19">19</a>
<a href="#20" id="20">20</a>
<a href="#21" id="21">21</a>
<a href="#22" id="22">22</a>
<a href="#23" id="23">23</a>
<a href="#24" id="24">24</a>
<a href="#25" id="25">25</a>
<a href="#26" id="26">26</a>
<a href="#27" id="27">27</a>
<a href="#28" id="28">28</a>
<a href="#29" id="29">29</a>
<a href="#30" id="30">30</a>
<a href="#31" id="31">31</a>
<a href="#32" id="32">32</a>
<a href="#33" id="33">33</a>
<a href="#34" id="34">34</a>
<a href="#35" id="35">35</a>
<a href="#36" id="36">36</a>
<a href="#37" id="37">37</a>
<a href="#38" id="38">38</a>
<a href="#39" id="39">39</a>
<a href="#40" id="40">40</a>
<a href="#41" id="41">41</a>
<a href="#42" id="42">42</a>
<a href="#43" id="43">43</a>
<a href="#44" id="44">44</a>
<a href="#45" id="45">45</a>
<a href="#46" id="46">46</a>
<a href="#47" id="47">47</a>
<a href="#48" id="48">48</a>
<a href="#49" id="49">49</a>
<a href="#50" id="50">50</a>
<a href="#51" id="51">51</a>
<a href="#52" id="52">52</a>
<a href="#53" id="53">53</a>
<a href="#54" id="54">54</a>
<a href="#55" id="55">55</a>
<a href="#56" id="56">56</a>
<a href="#57" id="57">57</a>
<a href="#58" id="58">58</a>
<a href="#59" id="59">59</a>
<a href="#60" id="60">60</a>
<a href="#61" id="61">61</a>
<a href="#62" id="62">62</a>
<a href="#63" id="63">63</a>
<a href="#64" id="64">64</a>
<a href="#65" id="65">65</a>
<a href="#66" id="66">66</a>
<a href="#67" id="67">67</a>
<a href="#68" id="68">68</a>
<a href="#69" id="69">69</a>
<a href="#70" id="70">70</a>
<a href="#71" id="71">71</a>
<a href="#72" id="72">72</a>
<a href="#73" id="73">73</a>
<a href="#74" id="74">74</a>
<a href="#75" id="75">75</a>
<a href="#76" id="76">76</a>
<a href="#77" id="77">77</a>
<a href="#78" id="78">78</a>
<a href="#79" id="79">79</a>
<a href="#80" id="80">80</a>
<a href="#81" id="81">81</a>
<a href="#82" id="82">82</a>
<a href="#83" id="83">83</a>
<a href="#84" id="84">84</a>
<a href="#85" id="85">85</a>
<a href="#86" id="86">86</a>
<a href="#87" id="87">87</a>
<a href="#88" id="88">88</a>
<a href="#89" id="89">89</a>
<a href="#90" id="90">90</a>
<a href="#91" id="91">91</a>
<a href="#92" id="92">92</a>
<a href="#93" id="93">93</a>
<a href="#94" id="94">94</a>
<a href="#95" id="95">95</a>
<a href="#96" id="96">96</a>
<a href="#97" id="97">97</a>
<a href="#98" id="98">98</a>
<a href="#99" id="99">99</a>
<a href="#100" id="100">100</a>
<a href="#101" id="101">101</a>
<a href="#102" id="102">102</a>
<a href="#103" id="103">103</a>
<a href="#104" id="104">104</a>
<a href="#105" id="105">105</a>
<a href="#106" id="106">106</a>
<a href="#107" id="107">107</a>
<a href="#108" id="108">108</a>
<a href="#109" id="109">109</a>
<a href="#110" id="110">110</a>
<a href="#111" id="111">111</a>
<a href="#112" id="112">112</a>
<a href="#113" id="113">113</a>
<a href="#114" id="114">114</a>
<a href="#115" id="115">115</a>
<a href="#116" id="116">116</a>
<a href="#117" id="117">117</a>
<a href="#118" id="118">118</a>
<a href="#119" id="119">119</a>
<a href="#120" id="120">120</a>
<a href="#121" id="121">121</a>
<a href="#122" id="122">122</a>
<a href="#123" id="123">123</a>
<a href="#124" id="124">124</a>
<a href="#125" id="125">125</a>
<a href="#126" id="126">126</a>
<a href="#127" id="127">127</a>
<a href="#128" id="128">128</a>
<a href="#129" id="129">129</a>
<a href="#130" id="130">130</a>
<a href="#131" id="131">131</a>
<a href="#132" id="132">132</a>
<a href="#133" id="133">133</a>
<a href="#134" id="134">134</a>
<a href="#135" id="135">135</a>
<a href="#136" id="136">136</a>
<a href="#137" id="137">137</a>
<a href="#138" id="138">138</a>
<a href="#139" id="139">139</a>
<a href="#140" id="140">140</a>
<a href="#141" id="141">141</a>
<a href="#142" id="142">142</a>
<a href="#143" id="143">143</a>
<a href="#144" id="144">144</a>
<a href="#145" id="145">145</a>
<a href="#146" id="146">146</a>
<a href="#147" id="147">147</a>
<a href="#148" id="148">148</a>
<a href="#149" id="149">149</a>
<a href="#150" id="150">150</a>
<a href="#151" id="151">151</a>
<a href="#152" id="152">152</a>
<a href="#153" id="153">153</a>
<a href="#154" id="154">154</a>
<a href="#155" id="155">155</a>
<a href="#156" id="156">156</a>
<a href="#157" id="157">157</a>
<a href="#158" id="158">158</a>
<a href="#159" id="159">159</a>
<a href="#160" id="160">160</a>
<a href="#161" id="161">161</a>
<a href="#162" id="162">162</a>
<a href="#163" id="163">163</a>
<a href="#164" id="164">164</a>
<a href="#165" id="165">165</a>
</pre></div><pre class="rust"><code><span class="kw">use </span>core::ffi::{c_int, c_uchar};
<span class="kw">pub const </span>EEPROM_STORAGE_SPACE_START: i16 = <span class="number">16</span>;
<span class="kw">extern </span><span class="string">&quot;C&quot; </span>{
<span class="attr">#[link_name = <span class="string">&quot;arduboy_eeprom_read&quot;</span>]
</span><span class="kw">fn </span>arduboy_eeprom_read_raw(idx: c_int) -&gt; c_uchar;
<span class="attr">#[link_name = <span class="string">&quot;arduboy_eeprom_update&quot;</span>]
</span><span class="kw">fn </span>arduboy_eeprom_update_raw(idx: c_int, val: c_uchar);
<span class="attr">#[link_name = <span class="string">&quot;arduboy_eeprom_write&quot;</span>]
</span><span class="kw">fn </span>arduboy_eeprom_write_raw(idx: c_int, val: c_uchar);
<span class="attr">#[link_name = <span class="string">&quot;arduboy_eeprom_get&quot;</span>]
</span><span class="kw">fn </span>arduboy_eeprom_get_raw(idx: c_int, object: <span class="kw-2">*mut </span>u8, size: usize);
<span class="attr">#[link_name = <span class="string">&quot;arduboy_eeprom_put&quot;</span>]
</span><span class="kw">fn </span>arduboy_eeprom_put_raw(idx: c_int, object: <span class="kw-2">*const </span>u8, size: usize);
}
<span class="doccomment">///This is the struct to store and read structs objects to/from eeprom memory.
/// ## Example
/// ```
/// static e: EEPROM = EEPROM::new(10);
/// struct Scorebord {
/// player1: u16,
/// text: &amp;&#39;static str,
/// }
/// static mut s: Scorebord = Scorebord {
/// player1: 0,
/// text: &quot;lol\0&quot;,
/// };
///
/// // init inside of the setup function
/// e.init(&amp;mut s);
/// ```
</span><span class="kw">pub struct </span>EEPROM {
start_c1: i16,
start_c2: i16,
idx: i16,
}
<span class="kw">impl </span>EEPROM {
<span class="kw">pub const fn </span>new(<span class="kw-2">mut </span>idx: i16) -&gt; EEPROM {
<span class="kw">if </span>idx &gt; <span class="number">950 </span>{
idx = <span class="number">0
</span>}
EEPROM {
start_c1: EEPROM_STORAGE_SPACE_START + idx,
start_c2: EEPROM_STORAGE_SPACE_START + idx + <span class="number">1</span>,
idx: EEPROM_STORAGE_SPACE_START + idx + <span class="number">2</span>,
}
}
<span class="kw">pub fn </span>init&lt;T&gt;(<span class="kw-2">&amp;</span><span class="self">self</span>, your_struct: <span class="kw-2">&amp;mut </span>T) {
<span class="kw">let </span>c1 = <span class="self">self</span>.read(<span class="self">self</span>.start_c1);
<span class="kw">let </span>c2 = <span class="self">self</span>.read(<span class="self">self</span>.start_c2);
<span class="kw">if </span>c1 != <span class="string">b&#39;Z&#39; </span>|| c2 != <span class="string">b&#39;D&#39; </span>{
<span class="self">self</span>.update(<span class="self">self</span>.start_c1, <span class="string">b&#39;Z&#39;</span>);
<span class="self">self</span>.update(<span class="self">self</span>.start_c2, <span class="string">b&#39;D&#39;</span>);
<span class="self">self</span>.put(your_struct);
};
<span class="self">self</span>.get(your_struct)
}
<span class="kw">fn </span>read(<span class="kw-2">&amp;</span><span class="self">self</span>, idx: i16) -&gt; u8 {
<span class="kw">unsafe </span>{ arduboy_eeprom_read_raw(idx) }
}
<span class="kw">fn </span>update(<span class="kw-2">&amp;</span><span class="self">self</span>, idx: i16, val: u8) {
<span class="kw">unsafe </span>{ arduboy_eeprom_update_raw(idx, val) }
}
<span class="kw">pub fn </span>get&lt;T&gt;(<span class="kw-2">&amp;</span><span class="self">self</span>, your_struct: <span class="kw-2">&amp;mut </span>T) {
<span class="kw">let </span>pointer = your_struct <span class="kw">as </span><span class="kw-2">*mut </span>T;
<span class="kw">let </span>object_pointer = pointer <span class="kw">as </span><span class="kw-2">*mut </span>u8;
<span class="kw">let </span>object_size = core::mem::size_of::&lt;T&gt;();
<span class="kw">unsafe </span>{
arduboy_eeprom_get_raw(<span class="self">self</span>.idx, object_pointer, object_size);
};
}
<span class="kw">pub fn </span>get_direct&lt;T&gt;(<span class="kw-2">&amp;</span><span class="self">self</span>) -&gt; T {
<span class="kw">let </span><span class="kw-2">mut </span>buffer = core::mem::MaybeUninit::&lt;T&gt;::uninit();
<span class="kw">let </span>pointer = buffer.as_mut_ptr();
<span class="kw">let </span>object_pointer = pointer <span class="kw">as </span><span class="kw-2">*mut </span>u8;
<span class="kw">let </span>object_size = core::mem::size_of::&lt;T&gt;();
<span class="kw">unsafe </span>{
arduboy_eeprom_get_raw(<span class="self">self</span>.idx, object_pointer, object_size);
};
<span class="kw">return unsafe </span>{ buffer.assume_init() };
}
<span class="kw">pub fn </span>put&lt;T&gt;(<span class="kw-2">&amp;</span><span class="self">self</span>, your_struct: <span class="kw-2">&amp;</span>T) {
<span class="kw">let </span>pointer = your_struct <span class="kw">as </span><span class="kw-2">*const </span>T;
<span class="kw">let </span>object_pointer = pointer <span class="kw">as </span><span class="kw-2">*const </span>u8;
<span class="kw">let </span>object_size = core::mem::size_of::&lt;T&gt;();
<span class="kw">unsafe </span>{
arduboy_eeprom_put_raw(<span class="self">self</span>.idx, object_pointer, object_size);
};
}
}
<span class="doccomment">///Use this struct to store and read single bytes to/from eeprom memory.
</span><span class="kw">pub struct </span>EEPROMBYTE {
start_c1: i16,
start_c2: i16,
idx: i16,
}
<span class="kw">impl </span>EEPROMBYTE {
<span class="kw">pub const fn </span>new(<span class="kw-2">mut </span>idx: i16) -&gt; EEPROMBYTE {
<span class="kw">if </span>idx &gt; <span class="number">1010 </span>{
idx = <span class="number">0
</span>}
EEPROMBYTE {
start_c1: EEPROM_STORAGE_SPACE_START + idx,
start_c2: EEPROM_STORAGE_SPACE_START + idx + <span class="number">1</span>,
idx: EEPROM_STORAGE_SPACE_START + idx + <span class="number">2</span>,
}
}
<span class="kw">pub fn </span>init(<span class="kw-2">&amp;</span><span class="self">self</span>) {
<span class="kw">let </span>c1 = <span class="self">self</span>.read_intern(<span class="self">self</span>.start_c1);
<span class="kw">let </span>c2 = <span class="self">self</span>.read_intern(<span class="self">self</span>.start_c2);
<span class="kw">if </span>c1 != <span class="string">b&#39;Z&#39; </span>|| c2 != <span class="string">b&#39;D&#39; </span>{
<span class="self">self</span>.update_intern(<span class="self">self</span>.start_c1, <span class="string">b&#39;Z&#39;</span>);
<span class="self">self</span>.update_intern(<span class="self">self</span>.start_c2, <span class="string">b&#39;D&#39;</span>);
<span class="self">self</span>.update(<span class="number">0</span>);
};
}
<span class="kw">fn </span>read_intern(<span class="kw-2">&amp;</span><span class="self">self</span>, idx: i16) -&gt; u8 {
<span class="kw">unsafe </span>{ arduboy_eeprom_read_raw(idx) }
}
<span class="kw">pub fn </span>read(<span class="kw-2">&amp;</span><span class="self">self</span>) -&gt; u8 {
<span class="kw">unsafe </span>{ arduboy_eeprom_read_raw(<span class="self">self</span>.idx) }
}
<span class="kw">fn </span>update_intern(<span class="kw-2">&amp;</span><span class="self">self</span>, idx: i16, val: u8) {
<span class="kw">unsafe </span>{ arduboy_eeprom_update_raw(idx, val) }
}
<span class="kw">pub fn </span>update(<span class="kw-2">&amp;</span><span class="self">self</span>, val: u8) {
<span class="kw">unsafe </span>{ arduboy_eeprom_update_raw(<span class="self">self</span>.idx, val) }
}
<span class="kw">pub fn </span>write(<span class="kw-2">&amp;</span><span class="self">self</span>, val: u8) {
<span class="kw">unsafe </span>{ arduboy_eeprom_write_raw(<span class="self">self</span>.idx, val) }
}
}
<span class="doccomment">///Use this struct to store and read single bytes to/from eeprom memory without using a check digit.
///Unlike the other eeprom structs, this does not need to be initialised.
</span><span class="kw">pub struct </span>EEPROMBYTECHECKLESS {
idx: i16,
}
<span class="kw">impl </span>EEPROMBYTECHECKLESS {
<span class="kw">pub const fn </span>new(<span class="kw-2">mut </span>idx: i16) -&gt; EEPROMBYTECHECKLESS {
<span class="kw">if </span>idx &gt; <span class="number">1010 </span>{
idx = <span class="number">0
</span>}
EEPROMBYTECHECKLESS {
idx: EEPROM_STORAGE_SPACE_START + idx,
}
}
<span class="kw">pub fn </span>read(<span class="kw-2">&amp;</span><span class="self">self</span>) -&gt; u8 {
<span class="kw">unsafe </span>{ arduboy_eeprom_read_raw(<span class="self">self</span>.idx) }
}
<span class="kw">pub fn </span>update(<span class="kw-2">&amp;</span><span class="self">self</span>, val: u8) {
<span class="kw">unsafe </span>{ arduboy_eeprom_update_raw(<span class="self">self</span>.idx, val) }
}
<span class="kw">pub fn </span>write(<span class="kw-2">&amp;</span><span class="self">self</span>, val: u8) {
<span class="kw">unsafe </span>{ arduboy_eeprom_write_raw(<span class="self">self</span>.idx, val) }
}
}
</code></pre></div></section></main></body></html>

View file

@ -1,19 +0,0 @@
<!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="Source of the Rust file `arduboy-rust/src/library/mod.rs`."><title>mod.rs - source</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-47e7ab555ef2818a.css"><meta name="rustdoc-vars" data-root-path="../../../" data-static-root-path="../../../static.files/" data-current-crate="arduboy_rust" data-themes="" data-resource-suffix="" data-rustdoc-version="1.74.0-nightly (d9c8274fb 2023-09-12)" data-channel="nightly" data-search-js="search-5d3eaacf19ebf04f.js" data-settings-js="settings-74424d7eec62a23e.js" data-settings-css="settings-8c76f75bfb6bd192.css" data-theme-light-css="light-f194925aa375ae96.css" data-theme-dark-css="dark-1dd4d1ce031e15de.css" data-theme-ayu-css="ayu-49e58d069f567085.css" ><script src="../../../static.files/storage-db41da1a38ea3cb8.js"></script><script defer src="../../../static.files/src-script-3280b574d94e47b4.js"></script><script defer src="../../../src-files.js"></script><script defer src="../../../static.files/main-8d035c8cea6edbc4.js"></script><noscript><link rel="stylesheet" media="(prefers-color-scheme:light)" href="../../../static.files/light-f194925aa375ae96.css"><link rel="stylesheet" media="(prefers-color-scheme:dark)" href="../../../static.files/dark-1dd4d1ce031e15de.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 src"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"></nav><main><nav class="sub"><a class="sub-logo-container" href="../../../arduboy_rust/index.html"><img class="rust-logo" src="../../../static.files/rust-logo-151179464ae7ed46.svg" alt="logo"></a><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="example-wrap"><div data-nosnippet><pre class="src-line-numbers"><a href="#1" id="1">1</a>
<a href="#2" id="2">2</a>
<a href="#3" id="3">3</a>
<a href="#4" id="4">4</a>
<a href="#5" id="5">5</a>
<a href="#6" id="6">6</a>
<a href="#7" id="7">7</a>
<a href="#8" id="8">8</a>
<a href="#9" id="9">9</a>
</pre></div><pre class="rust"><code><span class="kw">pub mod </span>arduboy2;
<span class="kw">pub mod </span>arduboy_tone;
<span class="kw">pub mod </span>arduboy_tone_pitch;
<span class="kw">pub mod </span>arduino;
<span class="kw">pub mod </span>ardvoice;
<span class="kw">pub mod </span>c;
<span class="kw">pub mod </span>eeprom;
<span class="kw">pub mod </span>progmem;
<span class="kw">pub mod </span>sprites;
</code></pre></div></section></main></body></html>

View file

@ -1,285 +0,0 @@
<!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="Source of the Rust file `arduboy-rust/src/library/progmem.rs`."><title>progmem.rs - source</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-47e7ab555ef2818a.css"><meta name="rustdoc-vars" data-root-path="../../../" data-static-root-path="../../../static.files/" data-current-crate="arduboy_rust" data-themes="" data-resource-suffix="" data-rustdoc-version="1.74.0-nightly (d9c8274fb 2023-09-12)" data-channel="nightly" data-search-js="search-5d3eaacf19ebf04f.js" data-settings-js="settings-74424d7eec62a23e.js" data-settings-css="settings-8c76f75bfb6bd192.css" data-theme-light-css="light-f194925aa375ae96.css" data-theme-dark-css="dark-1dd4d1ce031e15de.css" data-theme-ayu-css="ayu-49e58d069f567085.css" ><script src="../../../static.files/storage-db41da1a38ea3cb8.js"></script><script defer src="../../../static.files/src-script-3280b574d94e47b4.js"></script><script defer src="../../../src-files.js"></script><script defer src="../../../static.files/main-8d035c8cea6edbc4.js"></script><noscript><link rel="stylesheet" media="(prefers-color-scheme:light)" href="../../../static.files/light-f194925aa375ae96.css"><link rel="stylesheet" media="(prefers-color-scheme:dark)" href="../../../static.files/dark-1dd4d1ce031e15de.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 src"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"></nav><main><nav class="sub"><a class="sub-logo-container" href="../../../arduboy_rust/index.html"><img class="rust-logo" src="../../../static.files/rust-logo-151179464ae7ed46.svg" alt="logo"></a><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="example-wrap"><div data-nosnippet><pre class="src-line-numbers"><a href="#1" id="1">1</a>
<a href="#2" id="2">2</a>
<a href="#3" id="3">3</a>
<a href="#4" id="4">4</a>
<a href="#5" id="5">5</a>
<a href="#6" id="6">6</a>
<a href="#7" id="7">7</a>
<a href="#8" id="8">8</a>
<a href="#9" id="9">9</a>
<a href="#10" id="10">10</a>
<a href="#11" id="11">11</a>
<a href="#12" id="12">12</a>
<a href="#13" id="13">13</a>
<a href="#14" id="14">14</a>
<a href="#15" id="15">15</a>
<a href="#16" id="16">16</a>
<a href="#17" id="17">17</a>
<a href="#18" id="18">18</a>
<a href="#19" id="19">19</a>
<a href="#20" id="20">20</a>
<a href="#21" id="21">21</a>
<a href="#22" id="22">22</a>
<a href="#23" id="23">23</a>
<a href="#24" id="24">24</a>
<a href="#25" id="25">25</a>
<a href="#26" id="26">26</a>
<a href="#27" id="27">27</a>
<a href="#28" id="28">28</a>
<a href="#29" id="29">29</a>
<a href="#30" id="30">30</a>
<a href="#31" id="31">31</a>
<a href="#32" id="32">32</a>
<a href="#33" id="33">33</a>
<a href="#34" id="34">34</a>
<a href="#35" id="35">35</a>
<a href="#36" id="36">36</a>
<a href="#37" id="37">37</a>
<a href="#38" id="38">38</a>
<a href="#39" id="39">39</a>
<a href="#40" id="40">40</a>
<a href="#41" id="41">41</a>
<a href="#42" id="42">42</a>
<a href="#43" id="43">43</a>
<a href="#44" id="44">44</a>
<a href="#45" id="45">45</a>
<a href="#46" id="46">46</a>
<a href="#47" id="47">47</a>
<a href="#48" id="48">48</a>
<a href="#49" id="49">49</a>
<a href="#50" id="50">50</a>
<a href="#51" id="51">51</a>
<a href="#52" id="52">52</a>
<a href="#53" id="53">53</a>
<a href="#54" id="54">54</a>
<a href="#55" id="55">55</a>
<a href="#56" id="56">56</a>
<a href="#57" id="57">57</a>
<a href="#58" id="58">58</a>
<a href="#59" id="59">59</a>
<a href="#60" id="60">60</a>
<a href="#61" id="61">61</a>
<a href="#62" id="62">62</a>
<a href="#63" id="63">63</a>
<a href="#64" id="64">64</a>
<a href="#65" id="65">65</a>
<a href="#66" id="66">66</a>
<a href="#67" id="67">67</a>
<a href="#68" id="68">68</a>
<a href="#69" id="69">69</a>
<a href="#70" id="70">70</a>
<a href="#71" id="71">71</a>
<a href="#72" id="72">72</a>
<a href="#73" id="73">73</a>
<a href="#74" id="74">74</a>
<a href="#75" id="75">75</a>
<a href="#76" id="76">76</a>
<a href="#77" id="77">77</a>
<a href="#78" id="78">78</a>
<a href="#79" id="79">79</a>
<a href="#80" id="80">80</a>
<a href="#81" id="81">81</a>
<a href="#82" id="82">82</a>
<a href="#83" id="83">83</a>
<a href="#84" id="84">84</a>
<a href="#85" id="85">85</a>
<a href="#86" id="86">86</a>
<a href="#87" id="87">87</a>
<a href="#88" id="88">88</a>
<a href="#89" id="89">89</a>
<a href="#90" id="90">90</a>
<a href="#91" id="91">91</a>
<a href="#92" id="92">92</a>
<a href="#93" id="93">93</a>
<a href="#94" id="94">94</a>
<a href="#95" id="95">95</a>
<a href="#96" id="96">96</a>
<a href="#97" id="97">97</a>
<a href="#98" id="98">98</a>
<a href="#99" id="99">99</a>
<a href="#100" id="100">100</a>
<a href="#101" id="101">101</a>
<a href="#102" id="102">102</a>
<a href="#103" id="103">103</a>
<a href="#104" id="104">104</a>
<a href="#105" id="105">105</a>
<a href="#106" id="106">106</a>
<a href="#107" id="107">107</a>
<a href="#108" id="108">108</a>
<a href="#109" id="109">109</a>
<a href="#110" id="110">110</a>
<a href="#111" id="111">111</a>
<a href="#112" id="112">112</a>
<a href="#113" id="113">113</a>
<a href="#114" id="114">114</a>
<a href="#115" id="115">115</a>
<a href="#116" id="116">116</a>
<a href="#117" id="117">117</a>
<a href="#118" id="118">118</a>
<a href="#119" id="119">119</a>
<a href="#120" id="120">120</a>
<a href="#121" id="121">121</a>
<a href="#122" id="122">122</a>
<a href="#123" id="123">123</a>
<a href="#124" id="124">124</a>
<a href="#125" id="125">125</a>
<a href="#126" id="126">126</a>
<a href="#127" id="127">127</a>
<a href="#128" id="128">128</a>
<a href="#129" id="129">129</a>
<a href="#130" id="130">130</a>
<a href="#131" id="131">131</a>
<a href="#132" id="132">132</a>
<a href="#133" id="133">133</a>
<a href="#134" id="134">134</a>
<a href="#135" id="135">135</a>
<a href="#136" id="136">136</a>
<a href="#137" id="137">137</a>
<a href="#138" id="138">138</a>
<a href="#139" id="139">139</a>
<a href="#140" id="140">140</a>
<a href="#141" id="141">141</a>
<a href="#142" id="142">142</a>
</pre></div><pre class="rust"><code><span class="attr">#![allow(unused_imports)]
</span><span class="doccomment">/// Create a space for Progmem variable
/// ## Example
/// ```
/// //for text
/// progmem!(
/// static text: [u8; _] = *b&quot;I&#39;m a PROGMEM Text\0&quot;;
/// );
/// //for tone sequence
/// progmem!(
/// static tone: [u16; _] = [
/// NOTE_E4, 400, NOTE_D4, 200, NOTE_C4, 400, NOTE_D4, 200, NOTE_C4, 300, NOTE_REST,
/// ];
/// );
/// //for for bitmap
/// progmem!(
/// static image: [u8; _] = [8, 8, 0x81, 0x00, 0x12, 0x40, 0x04, 0x11, 0x00, 0x04];
/// );
///
/// // for a Vector
/// progmem!(
/// static mut walls: Vec&lt;Player, 100&gt; = Vec::new();
/// );
/// ```
</span><span class="attr">#[macro_export]
</span><span class="macro">macro_rules! </span>progmem {
(
$( <span class="attr">#[<span class="macro-nonterminal">$attr</span>:meta] </span>)*
<span class="macro-nonterminal">$v</span>:vis <span class="macro-nonterminal">$id</span>:ident <span class="macro-nonterminal">$name</span>:ident: [<span class="macro-nonterminal">$ty</span>:ty; <span class="kw">_</span>] = <span class="macro-nonterminal">$value</span>:expr;
$(<span class="macro-nonterminal">$rest</span>:tt)*
) =&gt; {
$( <span class="attr">#[<span class="macro-nonterminal">$attr</span>] </span>)*
<span class="attr">#[link_section = <span class="string">&quot;.progmem.data&quot;</span>]
</span><span class="macro-nonterminal">$v $id $name</span>: [<span class="macro-nonterminal">$ty</span>; <span class="macro-nonterminal">$value</span>.len()] = <span class="macro-nonterminal">$value</span>;
<span class="macro-nonterminal">$</span><span class="macro">crate::progmem!</span>{
$(<span class="macro-nonterminal">$rest</span>)*
}
};
(
$( <span class="attr">#[<span class="macro-nonterminal">$attr</span>:meta] </span>)*
<span class="macro-nonterminal">$v</span>:vis <span class="macro-nonterminal">$id</span>:ident <span class="kw-2">mut </span><span class="macro-nonterminal">$name</span>:ident: [<span class="macro-nonterminal">$ty</span>:ty; <span class="kw">_</span>] = <span class="macro-nonterminal">$value</span>:expr;
$(<span class="macro-nonterminal">$rest</span>:tt)*
) =&gt; {
$( <span class="attr">#[<span class="macro-nonterminal">$attr</span>] </span>)*
<span class="attr">#[link_section = <span class="string">&quot;.progmem.data&quot;</span>]
</span><span class="macro-nonterminal">$v $id </span><span class="kw-2">mut </span><span class="macro-nonterminal">$name</span>: [<span class="macro-nonterminal">$ty</span>; <span class="macro-nonterminal">$value</span>.len()] = <span class="macro-nonterminal">$value</span>;
<span class="macro-nonterminal">$</span><span class="macro">crate::progmem!</span>{
$(<span class="macro-nonterminal">$rest</span>)*
}
};
(
$( <span class="attr">#[<span class="macro-nonterminal">$attr</span>:meta] </span>)*
<span class="macro-nonterminal">$v</span>:vis <span class="macro-nonterminal">$id</span>:ident <span class="macro-nonterminal">$name</span>:ident: <span class="macro-nonterminal">$ty</span>:ty = <span class="macro-nonterminal">$value</span>:expr;
$(<span class="macro-nonterminal">$rest</span>:tt)*
) =&gt; {
$( <span class="attr">#[<span class="macro-nonterminal">$attr</span>] </span>)*
<span class="attr">#[link_section = <span class="string">&quot;.progmem.data&quot;</span>]
</span><span class="macro-nonterminal">$v $id $name</span>: <span class="macro-nonterminal">$ty </span>= <span class="macro-nonterminal">$value</span>;
<span class="macro-nonterminal">$</span><span class="macro">crate::progmem!</span>{
$(<span class="macro-nonterminal">$rest</span>)*
}
};
(
$( <span class="attr">#[<span class="macro-nonterminal">$attr</span>:meta] </span>)*
<span class="macro-nonterminal">$v</span>:vis <span class="macro-nonterminal">$id</span>:ident <span class="kw-2">mut </span><span class="macro-nonterminal">$name</span>:ident: <span class="macro-nonterminal">$ty</span>:ty = <span class="macro-nonterminal">$value</span>:expr;
$(<span class="macro-nonterminal">$rest</span>:tt)*
) =&gt; {
$( <span class="attr">#[<span class="macro-nonterminal">$attr</span>] </span>)*
<span class="attr">#[link_section = <span class="string">&quot;.progmem.data&quot;</span>]
</span><span class="macro-nonterminal">$v $id </span><span class="kw-2">mut </span><span class="macro-nonterminal">$name</span>: <span class="macro-nonterminal">$ty </span>= <span class="macro-nonterminal">$value</span>;
<span class="macro-nonterminal">$</span><span class="macro">crate::progmem!</span>{
$(<span class="macro-nonterminal">$rest</span>)*
}
};
() =&gt; ()
}
<span class="kw">pub</span>(<span class="kw">super</span>) <span class="kw">use </span>progmem;
<span class="doccomment">///Create a `const` raw pointer to a sprite as u8, without creating an intermediate reference.
</span><span class="attr">#[macro_export]
</span><span class="macro">macro_rules! </span>get_sprite_addr {
( <span class="macro-nonterminal">$s</span>:expr ) =&gt; {
<span class="kw">unsafe </span>{ <span class="macro">addr_of!</span>(<span class="macro-nonterminal">$s</span>) <span class="kw">as </span><span class="kw-2">*const </span>u8 }
};
}
<span class="kw">pub</span>(<span class="kw">super</span>) <span class="kw">use </span>get_sprite_addr;
<span class="doccomment">///Create a `const` raw pointer to a ardvoice tone as u8, without creating an intermediate reference.
</span><span class="attr">#[macro_export]
</span><span class="macro">macro_rules! </span>get_ardvoice_tone_addr {
( <span class="macro-nonterminal">$s</span>:expr ) =&gt; {
<span class="kw">unsafe </span>{ <span class="macro">addr_of!</span>(<span class="macro-nonterminal">$s</span>) <span class="kw">as </span><span class="kw-2">*const </span>u8 }
};
}
<span class="kw">pub</span>(<span class="kw">super</span>) <span class="kw">use </span>get_ardvoice_tone_addr;
<span class="doccomment">///Create a `const` raw pointer to a tone sequenze as u16, without creating an intermediate reference.
</span><span class="attr">#[macro_export]
</span><span class="macro">macro_rules! </span>get_tones_addr {
( <span class="macro-nonterminal">$s</span>:expr ) =&gt; {
<span class="kw">unsafe </span>{ <span class="macro">addr_of!</span>(<span class="macro-nonterminal">$s</span>) <span class="kw">as </span><span class="kw-2">*const </span>u16 }
};
}
<span class="kw">pub</span>(<span class="kw">super</span>) <span class="kw">use </span>get_tones_addr;
<span class="doccomment">///Create a `const` raw pointer to a \[u8;_] that saves text, without creating an intermediate reference.
</span><span class="attr">#[macro_export]
</span><span class="macro">macro_rules! </span>get_string_addr {
( <span class="macro-nonterminal">$s</span>:expr ) =&gt; {
Pstring {
pointer: <span class="kw">unsafe </span>{ <span class="macro">addr_of!</span>(<span class="macro-nonterminal">$s</span>) <span class="kw">as </span><span class="kw-2">*const </span>i8 },
}
};
}
<span class="kw">pub</span>(<span class="kw">super</span>) <span class="kw">use </span>get_string_addr;
<span class="doccomment">///This is the way to go if you want print some random text
///
/// This doesn&#39;t waste the 2kb ram it saves to progmem (28kb)
/// This automatically saves the given text to the Progmem.
/// ## Example
/// ```
/// arduboy.print(f!(b&quot;Random text to print\0&quot;))
/// ```
</span><span class="attr">#[macro_export]
</span><span class="macro">macro_rules! </span>f {
(<span class="macro-nonterminal">$string_literal</span>:literal) =&gt; {{
<span class="macro">progmem!</span>(
<span class="kw">static </span>local: [u8; <span class="kw">_</span>] = <span class="kw-2">*</span><span class="macro-nonterminal">$string_literal</span>;
);
<span class="macro">get_string_addr!</span>(local)
}};
}
<span class="kw">pub</span>(<span class="kw">super</span>) <span class="kw">use </span>f;
<span class="doccomment">/// This struct is important for the Progmem functionality.
///
/// Typically you will never use this by your self.
/// It will be used by the get_string_addr macro in combination with a print command.
</span><span class="attr">#[derive(Copy, Clone)]
</span><span class="kw">pub struct </span>Pstring {
<span class="kw">pub </span>pointer: <span class="kw-2">*const </span>i8,
}
</code></pre></div></section></main></body></html>

View file

@ -1,359 +0,0 @@
<!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="Source of the Rust file `arduboy-rust/src/library/sprites.rs`."><title>sprites.rs - source</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-47e7ab555ef2818a.css"><meta name="rustdoc-vars" data-root-path="../../../" data-static-root-path="../../../static.files/" data-current-crate="arduboy_rust" data-themes="" data-resource-suffix="" data-rustdoc-version="1.74.0-nightly (d9c8274fb 2023-09-12)" data-channel="nightly" data-search-js="search-5d3eaacf19ebf04f.js" data-settings-js="settings-74424d7eec62a23e.js" data-settings-css="settings-8c76f75bfb6bd192.css" data-theme-light-css="light-f194925aa375ae96.css" data-theme-dark-css="dark-1dd4d1ce031e15de.css" data-theme-ayu-css="ayu-49e58d069f567085.css" ><script src="../../../static.files/storage-db41da1a38ea3cb8.js"></script><script defer src="../../../static.files/src-script-3280b574d94e47b4.js"></script><script defer src="../../../src-files.js"></script><script defer src="../../../static.files/main-8d035c8cea6edbc4.js"></script><noscript><link rel="stylesheet" media="(prefers-color-scheme:light)" href="../../../static.files/light-f194925aa375ae96.css"><link rel="stylesheet" media="(prefers-color-scheme:dark)" href="../../../static.files/dark-1dd4d1ce031e15de.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 src"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"></nav><main><nav class="sub"><a class="sub-logo-container" href="../../../arduboy_rust/index.html"><img class="rust-logo" src="../../../static.files/rust-logo-151179464ae7ed46.svg" alt="logo"></a><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="example-wrap"><div data-nosnippet><pre class="src-line-numbers"><a href="#1" id="1">1</a>
<a href="#2" id="2">2</a>
<a href="#3" id="3">3</a>
<a href="#4" id="4">4</a>
<a href="#5" id="5">5</a>
<a href="#6" id="6">6</a>
<a href="#7" id="7">7</a>
<a href="#8" id="8">8</a>
<a href="#9" id="9">9</a>
<a href="#10" id="10">10</a>
<a href="#11" id="11">11</a>
<a href="#12" id="12">12</a>
<a href="#13" id="13">13</a>
<a href="#14" id="14">14</a>
<a href="#15" id="15">15</a>
<a href="#16" id="16">16</a>
<a href="#17" id="17">17</a>
<a href="#18" id="18">18</a>
<a href="#19" id="19">19</a>
<a href="#20" id="20">20</a>
<a href="#21" id="21">21</a>
<a href="#22" id="22">22</a>
<a href="#23" id="23">23</a>
<a href="#24" id="24">24</a>
<a href="#25" id="25">25</a>
<a href="#26" id="26">26</a>
<a href="#27" id="27">27</a>
<a href="#28" id="28">28</a>
<a href="#29" id="29">29</a>
<a href="#30" id="30">30</a>
<a href="#31" id="31">31</a>
<a href="#32" id="32">32</a>
<a href="#33" id="33">33</a>
<a href="#34" id="34">34</a>
<a href="#35" id="35">35</a>
<a href="#36" id="36">36</a>
<a href="#37" id="37">37</a>
<a href="#38" id="38">38</a>
<a href="#39" id="39">39</a>
<a href="#40" id="40">40</a>
<a href="#41" id="41">41</a>
<a href="#42" id="42">42</a>
<a href="#43" id="43">43</a>
<a href="#44" id="44">44</a>
<a href="#45" id="45">45</a>
<a href="#46" id="46">46</a>
<a href="#47" id="47">47</a>
<a href="#48" id="48">48</a>
<a href="#49" id="49">49</a>
<a href="#50" id="50">50</a>
<a href="#51" id="51">51</a>
<a href="#52" id="52">52</a>
<a href="#53" id="53">53</a>
<a href="#54" id="54">54</a>
<a href="#55" id="55">55</a>
<a href="#56" id="56">56</a>
<a href="#57" id="57">57</a>
<a href="#58" id="58">58</a>
<a href="#59" id="59">59</a>
<a href="#60" id="60">60</a>
<a href="#61" id="61">61</a>
<a href="#62" id="62">62</a>
<a href="#63" id="63">63</a>
<a href="#64" id="64">64</a>
<a href="#65" id="65">65</a>
<a href="#66" id="66">66</a>
<a href="#67" id="67">67</a>
<a href="#68" id="68">68</a>
<a href="#69" id="69">69</a>
<a href="#70" id="70">70</a>
<a href="#71" id="71">71</a>
<a href="#72" id="72">72</a>
<a href="#73" id="73">73</a>
<a href="#74" id="74">74</a>
<a href="#75" id="75">75</a>
<a href="#76" id="76">76</a>
<a href="#77" id="77">77</a>
<a href="#78" id="78">78</a>
<a href="#79" id="79">79</a>
<a href="#80" id="80">80</a>
<a href="#81" id="81">81</a>
<a href="#82" id="82">82</a>
<a href="#83" id="83">83</a>
<a href="#84" id="84">84</a>
<a href="#85" id="85">85</a>
<a href="#86" id="86">86</a>
<a href="#87" id="87">87</a>
<a href="#88" id="88">88</a>
<a href="#89" id="89">89</a>
<a href="#90" id="90">90</a>
<a href="#91" id="91">91</a>
<a href="#92" id="92">92</a>
<a href="#93" id="93">93</a>
<a href="#94" id="94">94</a>
<a href="#95" id="95">95</a>
<a href="#96" id="96">96</a>
<a href="#97" id="97">97</a>
<a href="#98" id="98">98</a>
<a href="#99" id="99">99</a>
<a href="#100" id="100">100</a>
<a href="#101" id="101">101</a>
<a href="#102" id="102">102</a>
<a href="#103" id="103">103</a>
<a href="#104" id="104">104</a>
<a href="#105" id="105">105</a>
<a href="#106" id="106">106</a>
<a href="#107" id="107">107</a>
<a href="#108" id="108">108</a>
<a href="#109" id="109">109</a>
<a href="#110" id="110">110</a>
<a href="#111" id="111">111</a>
<a href="#112" id="112">112</a>
<a href="#113" id="113">113</a>
<a href="#114" id="114">114</a>
<a href="#115" id="115">115</a>
<a href="#116" id="116">116</a>
<a href="#117" id="117">117</a>
<a href="#118" id="118">118</a>
<a href="#119" id="119">119</a>
<a href="#120" id="120">120</a>
<a href="#121" id="121">121</a>
<a href="#122" id="122">122</a>
<a href="#123" id="123">123</a>
<a href="#124" id="124">124</a>
<a href="#125" id="125">125</a>
<a href="#126" id="126">126</a>
<a href="#127" id="127">127</a>
<a href="#128" id="128">128</a>
<a href="#129" id="129">129</a>
<a href="#130" id="130">130</a>
<a href="#131" id="131">131</a>
<a href="#132" id="132">132</a>
<a href="#133" id="133">133</a>
<a href="#134" id="134">134</a>
<a href="#135" id="135">135</a>
<a href="#136" id="136">136</a>
<a href="#137" id="137">137</a>
<a href="#138" id="138">138</a>
<a href="#139" id="139">139</a>
<a href="#140" id="140">140</a>
<a href="#141" id="141">141</a>
<a href="#142" id="142">142</a>
<a href="#143" id="143">143</a>
<a href="#144" id="144">144</a>
<a href="#145" id="145">145</a>
<a href="#146" id="146">146</a>
<a href="#147" id="147">147</a>
<a href="#148" id="148">148</a>
<a href="#149" id="149">149</a>
<a href="#150" id="150">150</a>
<a href="#151" id="151">151</a>
<a href="#152" id="152">152</a>
<a href="#153" id="153">153</a>
<a href="#154" id="154">154</a>
<a href="#155" id="155">155</a>
<a href="#156" id="156">156</a>
<a href="#157" id="157">157</a>
<a href="#158" id="158">158</a>
<a href="#159" id="159">159</a>
<a href="#160" id="160">160</a>
<a href="#161" id="161">161</a>
<a href="#162" id="162">162</a>
<a href="#163" id="163">163</a>
<a href="#164" id="164">164</a>
<a href="#165" id="165">165</a>
<a href="#166" id="166">166</a>
<a href="#167" id="167">167</a>
<a href="#168" id="168">168</a>
<a href="#169" id="169">169</a>
<a href="#170" id="170">170</a>
<a href="#171" id="171">171</a>
<a href="#172" id="172">172</a>
<a href="#173" id="173">173</a>
<a href="#174" id="174">174</a>
<a href="#175" id="175">175</a>
<a href="#176" id="176">176</a>
<a href="#177" id="177">177</a>
<a href="#178" id="178">178</a>
<a href="#179" id="179">179</a>
</pre></div><pre class="rust"><code><span class="doccomment">//!This is the module to interact in a save way with the Sprites C++ library.
</span><span class="kw">use </span>core::ffi::{c_int, c_uchar};
<span class="kw">extern </span><span class="string">&quot;C&quot; </span>{
<span class="attr">#[link_name = <span class="string">&quot;arduino_draw_override&quot;</span>]
</span><span class="kw">fn </span>arduino_draw_override_raw(x: c_int, y: c_int, bitmap: <span class="kw-2">*const </span>c_uchar, frame: c_uchar);
<span class="attr">#[link_name = <span class="string">&quot;arduino_draw_external_mask&quot;</span>]
</span><span class="kw">fn </span>arduino_draw_external_mask_raw(
x: c_int,
y: c_int,
bitmap: <span class="kw-2">*const </span>c_uchar,
mask: <span class="kw-2">*const </span>c_uchar,
frame: c_uchar,
mask_frame: c_uchar,
);
<span class="attr">#[link_name = <span class="string">&quot;arduino_draw_plus_mask&quot;</span>]
</span><span class="kw">fn </span>arduino_draw_plus_mask_raw(x: c_int, y: c_int, bitmap: <span class="kw-2">*const </span>c_uchar, frame: c_uchar);
<span class="attr">#[link_name = <span class="string">&quot;arduino_draw_erase&quot;</span>]
</span><span class="kw">fn </span>arduino_draw_erase_raw(x: c_int, y: c_int, bitmap: <span class="kw-2">*const </span>c_uchar, frame: c_uchar);
<span class="attr">#[link_name = <span class="string">&quot;arduino_draw_self_masked&quot;</span>]
</span><span class="kw">fn </span>arduino_draw_self_masked_raw(x: c_int, y: c_int, bitmap: <span class="kw-2">*const </span>c_uchar, frame: c_uchar);
}
<span class="doccomment">/// Draw a sprite by replacing the existing content completely.
///
/// ### Parameters
///
/// - x,y The coordinates of the top left pixel location.
/// - bitmap A pointer to the array containing the image frames.
/// - frame The frame number of the image to draw.
///
/// A sprite is drawn by overwriting the pixels in the buffer with the data from the specified frame in the array. No masking is done. A bit set to 1 in the frame will set the pixel to 1 in the buffer, and a 0 in the array will set a 0 in the buffer.
///```text
/// image before after (# = 1, - = 0)
///
/// ----- ----- -----
/// --#-- ----- --#--
/// ##-## ----- ##-##
/// --#-- ----- --#--
/// ----- ----- -----
///
/// image before after
///
/// ----- ##### -----
/// --#-- ##### --#--
/// ##-## ##### ##-##
/// --#-- ##### --#--
/// ----- ##### -----
/// ```
</span><span class="kw">pub fn </span>draw_override(x: i16, y: i16, bitmap: <span class="kw-2">*const </span>u8, frame: u8) {
<span class="kw">unsafe </span>{ arduino_draw_override_raw(x, y, bitmap, frame) }
}
<span class="doccomment">///Draw a sprite using a separate image and mask array.
///
///Parameters
///- x,y The coordinates of the top left pixel location.
///- bitmap A pointer to the array containing the image frames.
///- mask A pointer to the array containing the mask frames.
///- frame The frame number of the image to draw.
///- mask_frame The frame number for the mask to use (can be different from the image frame number).
///
///An array containing the image frames, and another array containing corresponding mask frames, are used to draw a sprite.
///
///For the mask array, the width and height are not included but must contain data of the same dimensions as the corresponding image array.
///
///Bits set to 1 in the mask indicate that the pixel will be set to the value of the corresponding image bit. Bits set to 0 in the mask will be left unchanged.
///```text
/// image mask before after (# = 1, - = 0)
///
/// ----- -###- ----- -----
/// --#-- ##### ----- --#--
/// ##-## ##-## ----- ##-##
/// --#-- ##### ----- --#--
/// ----- -###- ----- -----
///
/// image mask before after
///
/// ----- -###- ##### #---#
/// --#-- ##### ##### --#--
/// ##-## ##### ##### ##-##
/// --#-- ##### ##### --#--
/// ----- -###- ##### #---#
/// ```
</span><span class="kw">pub fn </span>draw_external_mask(
x: i16,
y: i16,
bitmap: <span class="kw-2">*const </span>u8,
mask: <span class="kw-2">*const </span>u8,
frame: u8,
mask_frame: u8,
) {
<span class="kw">unsafe </span>{ arduino_draw_external_mask_raw(x, y, bitmap, mask, frame, mask_frame) }
}
<span class="doccomment">///Draw a sprite using an array containing both image and mask values.
///
///Parameters
/// - x,y The coordinates of the top left pixel location.
/// - bitmap A pointer to the array containing the image/mask frames.
/// - frame The frame number of the image to draw.
///
///An array containing combined image and mask data is used to draw a sprite. Bytes are given in pairs with the first byte representing the image pixels and the second byte specifying the corresponding mask. The width given in the array still specifies the image width, so each row of image and mask bytes will be twice the width value.
///
///Bits set to 1 in the mask indicate that the pixel will be set to the value of the corresponding image bit. Bits set to 0 in the mask will be left unchanged.
///
///image mask before after (# = 1, - = 0)
///```text
/// ----- -###- ----- -----
/// --#-- ##### ----- --#--
/// ##-## ##-## ----- ##-##
/// --#-- ##### ----- --#--
/// ----- -###- ----- -----
///
/// image mask before after
///
/// ----- -###- ##### #---#
/// --#-- ##### ##### --#--
/// ##-## ##### ##### ##-##
/// --#-- ##### ##### --#--
/// ----- -###- ##### #---#
/// ```
</span><span class="kw">pub fn </span>draw_plus_mask(x: i16, y: i16, bitmap: <span class="kw-2">*const </span>u8, frame: u8) {
<span class="kw">unsafe </span>{ arduino_draw_plus_mask_raw(x, y, bitmap, frame) }
}
<span class="doccomment">///&quot;Erase&quot; a sprite.
///
///Parameters
/// - x,y The coordinates of the top left pixel location.
/// - bitmap A pointer to the array containing the image frames.
/// - frame The frame number of the image to erase.
///
///The data from the specified frame in the array is used to erase a sprite. To &quot;erase&quot; a sprite, bits set to 1 in the frame will set the corresponding pixel in the buffer to 0. Frame bits set to 0 will remain unchanged in the buffer.
///```text
/// image before after (# = 1, - = 0)
///
/// ----- ----- -----
/// --#-- ----- -----
/// ##-## ----- -----
/// --#-- ----- -----
/// ----- ----- -----
///
/// image before after
///
/// ----- ##### #####
/// --#-- ##### ##-##
/// ##-## ##### --#--
/// --#-- ##### ##-##
/// ----- ##### #####
/// ```
</span><span class="kw">pub fn </span>draw_erase(x: i16, y: i16, bitmap: <span class="kw-2">*const </span>u8, frame: u8) {
<span class="kw">unsafe </span>{ arduino_draw_erase_raw(x, y, bitmap, frame) }
}
<span class="doccomment">///Draw a sprite using only the bits set to 1.
///
///Parameters
/// - x,y The coordinates of the top left pixel location.
/// - bitmap A pointer to the array containing the image frames.
/// - frame The frame number of the image to draw.
///
///Bits set to 1 in the frame will be used to draw the sprite by setting the corresponding pixel in the buffer to 1. Bits set to 0 in the frame will remain unchanged in the buffer.
///```text
/// image before after (# = 1, - = 0)
///
/// ----- ----- -----
/// --#-- ----- --#--
/// ##-## ----- ##-##
/// --#-- ----- --#--
/// ----- ----- -----
///
/// image before after
///
/// ----- ##### ##### (no change because all pixels were
/// --#-- ##### ##### already white)
/// ##-## ##### #####
/// --#-- ##### #####
/// ----- ##### #####
/// ```
</span><span class="kw">pub fn </span>draw_self_masked(x: i16, y: i16, bitmap: <span class="kw-2">*const </span>u8, frame: u8) {
<span class="kw">unsafe </span>{ arduino_draw_self_masked_raw(x, y, bitmap, frame) }
}
</code></pre></div></section></main></body></html>

View file

@ -1,73 +0,0 @@
<!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="Source of the Rust file `arduboy-rust/src/prelude.rs`."><title>prelude.rs - source</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-47e7ab555ef2818a.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="arduboy_rust" data-themes="" data-resource-suffix="" data-rustdoc-version="1.74.0-nightly (d9c8274fb 2023-09-12)" data-channel="nightly" data-search-js="search-5d3eaacf19ebf04f.js" data-settings-js="settings-74424d7eec62a23e.js" data-settings-css="settings-8c76f75bfb6bd192.css" data-theme-light-css="light-f194925aa375ae96.css" data-theme-dark-css="dark-1dd4d1ce031e15de.css" data-theme-ayu-css="ayu-49e58d069f567085.css" ><script src="../../static.files/storage-db41da1a38ea3cb8.js"></script><script defer src="../../static.files/src-script-3280b574d94e47b4.js"></script><script defer src="../../src-files.js"></script><script defer src="../../static.files/main-8d035c8cea6edbc4.js"></script><noscript><link rel="stylesheet" media="(prefers-color-scheme:light)" href="../../static.files/light-f194925aa375ae96.css"><link rel="stylesheet" media="(prefers-color-scheme:dark)" href="../../static.files/dark-1dd4d1ce031e15de.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 src"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"></nav><main><nav class="sub"><a class="sub-logo-container" href="../../arduboy_rust/index.html"><img class="rust-logo" src="../../static.files/rust-logo-151179464ae7ed46.svg" alt="logo"></a><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="example-wrap"><div data-nosnippet><pre class="src-line-numbers"><a href="#1" id="1">1</a>
<a href="#2" id="2">2</a>
<a href="#3" id="3">3</a>
<a href="#4" id="4">4</a>
<a href="#5" id="5">5</a>
<a href="#6" id="6">6</a>
<a href="#7" id="7">7</a>
<a href="#8" id="8">8</a>
<a href="#9" id="9">9</a>
<a href="#10" id="10">10</a>
<a href="#11" id="11">11</a>
<a href="#12" id="12">12</a>
<a href="#13" id="13">13</a>
<a href="#14" id="14">14</a>
<a href="#15" id="15">15</a>
<a href="#16" id="16">16</a>
<a href="#17" id="17">17</a>
<a href="#18" id="18">18</a>
<a href="#19" id="19">19</a>
<a href="#20" id="20">20</a>
<a href="#21" id="21">21</a>
<a href="#22" id="22">22</a>
<a href="#23" id="23">23</a>
<a href="#24" id="24">24</a>
<a href="#25" id="25">25</a>
<a href="#26" id="26">26</a>
<a href="#27" id="27">27</a>
<a href="#28" id="28">28</a>
<a href="#29" id="29">29</a>
<a href="#30" id="30">30</a>
<a href="#31" id="31">31</a>
<a href="#32" id="32">32</a>
<a href="#33" id="33">33</a>
<a href="#34" id="34">34</a>
<a href="#35" id="35">35</a>
<a href="#36" id="36">36</a>
</pre></div><pre class="rust"><code><span class="doccomment">//! This is the important one to use this library effective in your project
//!
//! Import the module:
//! ```
//! use arduboy_rust::prelude::*;
//! ```
</span><span class="attr">#[doc(inline)]
</span><span class="kw">pub use </span><span class="kw">crate</span>::hardware::buttons::{<span class="self">self</span>, <span class="kw-2">*</span>};
<span class="attr">#[doc(inline)]
</span><span class="kw">pub use </span><span class="kw">crate</span>::hardware::led::{<span class="self">self</span>, <span class="kw-2">*</span>};
<span class="kw">pub use </span><span class="kw">crate</span>::heapless::{LinearMap, String, Vec};
<span class="kw">pub use </span><span class="kw">crate</span>::library::arduboy2::{<span class="self">self</span>, <span class="kw-2">*</span>};
<span class="kw">pub use </span><span class="kw">crate</span>::library::arduboy_tone::{<span class="self">self</span>, ArduboyTones};
<span class="kw">pub use </span><span class="kw">crate</span>::library::arduino::<span class="kw-2">*</span>;
<span class="kw">pub use </span><span class="kw">crate</span>::library::ardvoice::{<span class="self">self</span>, ArdVoice};
<span class="kw">pub use </span><span class="kw">crate</span>::library::c::<span class="kw-2">*</span>;
<span class="kw">pub use </span><span class="kw">crate</span>::library::eeprom::{EEPROM, EEPROMBYTE, EEPROMBYTECHECKLESS};
<span class="attr">#[doc(hidden)]
</span><span class="kw">pub use </span><span class="kw">crate</span>::library::progmem::Pstring;
<span class="kw">pub use </span><span class="kw">crate</span>::library::sprites;
<span class="kw">pub use </span><span class="kw">crate</span>::print::<span class="kw-2">*</span>;
<span class="kw">pub use crate</span>::{
f, get_ardvoice_tone_addr, get_sprite_addr, get_string_addr, get_tones_addr, progmem,
serial_print <span class="kw">as </span>serial,
};
<span class="kw">use </span>core::cmp;
<span class="kw">pub use </span>core::ffi::{
c_char, c_double, c_float, c_int, c_long, c_longlong, c_size_t, c_uchar, c_uint, c_ulong,
c_ulonglong,
};
<span class="attr">#[doc(hidden)]
</span><span class="kw">pub use </span>core::ptr::addr_of;
<span class="kw">pub fn </span>constrain&lt;T: Ord&gt;(x: T, a: T, b: T) -&gt; T {
cmp::max(cmp::min(x, b), a)
}
</code></pre></div></section></main></body></html>

View file

@ -1,255 +0,0 @@
<!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="Source of the Rust file `arduboy-rust/src/print.rs`."><title>print.rs - source</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-47e7ab555ef2818a.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="arduboy_rust" data-themes="" data-resource-suffix="" data-rustdoc-version="1.74.0-nightly (d9c8274fb 2023-09-12)" data-channel="nightly" data-search-js="search-5d3eaacf19ebf04f.js" data-settings-js="settings-74424d7eec62a23e.js" data-settings-css="settings-8c76f75bfb6bd192.css" data-theme-light-css="light-f194925aa375ae96.css" data-theme-dark-css="dark-1dd4d1ce031e15de.css" data-theme-ayu-css="ayu-49e58d069f567085.css" ><script src="../../static.files/storage-db41da1a38ea3cb8.js"></script><script defer src="../../static.files/src-script-3280b574d94e47b4.js"></script><script defer src="../../src-files.js"></script><script defer src="../../static.files/main-8d035c8cea6edbc4.js"></script><noscript><link rel="stylesheet" media="(prefers-color-scheme:light)" href="../../static.files/light-f194925aa375ae96.css"><link rel="stylesheet" media="(prefers-color-scheme:dark)" href="../../static.files/dark-1dd4d1ce031e15de.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 src"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"></nav><main><nav class="sub"><a class="sub-logo-container" href="../../arduboy_rust/index.html"><img class="rust-logo" src="../../static.files/rust-logo-151179464ae7ed46.svg" alt="logo"></a><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="example-wrap"><div data-nosnippet><pre class="src-line-numbers"><a href="#1" id="1">1</a>
<a href="#2" id="2">2</a>
<a href="#3" id="3">3</a>
<a href="#4" id="4">4</a>
<a href="#5" id="5">5</a>
<a href="#6" id="6">6</a>
<a href="#7" id="7">7</a>
<a href="#8" id="8">8</a>
<a href="#9" id="9">9</a>
<a href="#10" id="10">10</a>
<a href="#11" id="11">11</a>
<a href="#12" id="12">12</a>
<a href="#13" id="13">13</a>
<a href="#14" id="14">14</a>
<a href="#15" id="15">15</a>
<a href="#16" id="16">16</a>
<a href="#17" id="17">17</a>
<a href="#18" id="18">18</a>
<a href="#19" id="19">19</a>
<a href="#20" id="20">20</a>
<a href="#21" id="21">21</a>
<a href="#22" id="22">22</a>
<a href="#23" id="23">23</a>
<a href="#24" id="24">24</a>
<a href="#25" id="25">25</a>
<a href="#26" id="26">26</a>
<a href="#27" id="27">27</a>
<a href="#28" id="28">28</a>
<a href="#29" id="29">29</a>
<a href="#30" id="30">30</a>
<a href="#31" id="31">31</a>
<a href="#32" id="32">32</a>
<a href="#33" id="33">33</a>
<a href="#34" id="34">34</a>
<a href="#35" id="35">35</a>
<a href="#36" id="36">36</a>
<a href="#37" id="37">37</a>
<a href="#38" id="38">38</a>
<a href="#39" id="39">39</a>
<a href="#40" id="40">40</a>
<a href="#41" id="41">41</a>
<a href="#42" id="42">42</a>
<a href="#43" id="43">43</a>
<a href="#44" id="44">44</a>
<a href="#45" id="45">45</a>
<a href="#46" id="46">46</a>
<a href="#47" id="47">47</a>
<a href="#48" id="48">48</a>
<a href="#49" id="49">49</a>
<a href="#50" id="50">50</a>
<a href="#51" id="51">51</a>
<a href="#52" id="52">52</a>
<a href="#53" id="53">53</a>
<a href="#54" id="54">54</a>
<a href="#55" id="55">55</a>
<a href="#56" id="56">56</a>
<a href="#57" id="57">57</a>
<a href="#58" id="58">58</a>
<a href="#59" id="59">59</a>
<a href="#60" id="60">60</a>
<a href="#61" id="61">61</a>
<a href="#62" id="62">62</a>
<a href="#63" id="63">63</a>
<a href="#64" id="64">64</a>
<a href="#65" id="65">65</a>
<a href="#66" id="66">66</a>
<a href="#67" id="67">67</a>
<a href="#68" id="68">68</a>
<a href="#69" id="69">69</a>
<a href="#70" id="70">70</a>
<a href="#71" id="71">71</a>
<a href="#72" id="72">72</a>
<a href="#73" id="73">73</a>
<a href="#74" id="74">74</a>
<a href="#75" id="75">75</a>
<a href="#76" id="76">76</a>
<a href="#77" id="77">77</a>
<a href="#78" id="78">78</a>
<a href="#79" id="79">79</a>
<a href="#80" id="80">80</a>
<a href="#81" id="81">81</a>
<a href="#82" id="82">82</a>
<a href="#83" id="83">83</a>
<a href="#84" id="84">84</a>
<a href="#85" id="85">85</a>
<a href="#86" id="86">86</a>
<a href="#87" id="87">87</a>
<a href="#88" id="88">88</a>
<a href="#89" id="89">89</a>
<a href="#90" id="90">90</a>
<a href="#91" id="91">91</a>
<a href="#92" id="92">92</a>
<a href="#93" id="93">93</a>
<a href="#94" id="94">94</a>
<a href="#95" id="95">95</a>
<a href="#96" id="96">96</a>
<a href="#97" id="97">97</a>
<a href="#98" id="98">98</a>
<a href="#99" id="99">99</a>
<a href="#100" id="100">100</a>
<a href="#101" id="101">101</a>
<a href="#102" id="102">102</a>
<a href="#103" id="103">103</a>
<a href="#104" id="104">104</a>
<a href="#105" id="105">105</a>
<a href="#106" id="106">106</a>
<a href="#107" id="107">107</a>
<a href="#108" id="108">108</a>
<a href="#109" id="109">109</a>
<a href="#110" id="110">110</a>
<a href="#111" id="111">111</a>
<a href="#112" id="112">112</a>
<a href="#113" id="113">113</a>
<a href="#114" id="114">114</a>
<a href="#115" id="115">115</a>
<a href="#116" id="116">116</a>
<a href="#117" id="117">117</a>
<a href="#118" id="118">118</a>
<a href="#119" id="119">119</a>
<a href="#120" id="120">120</a>
<a href="#121" id="121">121</a>
<a href="#122" id="122">122</a>
<a href="#123" id="123">123</a>
<a href="#124" id="124">124</a>
<a href="#125" id="125">125</a>
<a href="#126" id="126">126</a>
<a href="#127" id="127">127</a>
</pre></div><pre class="rust"><code><span class="kw">use </span><span class="kw">crate</span>::prelude::Pstring;
<span class="kw">use </span>core::ffi::c_int;
<span class="attr">#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
</span><span class="kw">pub enum </span>Base {
Bin = <span class="number">2</span>,
Oct = <span class="number">8</span>,
Dec = <span class="number">10</span>,
Hex = <span class="number">16</span>,
}
<span class="kw">pub trait </span>Printable
<span class="kw">where
</span><span class="self">Self</span>: Sized,
{
<span class="kw">type </span>Parameters;
<span class="kw">fn </span>print_2(<span class="self">self</span>, params: <span class="self">Self</span>::Parameters);
<span class="kw">fn </span>default_parameters() -&gt; <span class="self">Self</span>::Parameters;
<span class="kw">fn </span>print(<span class="self">self</span>) {
<span class="self">self</span>.print_2(<span class="self">Self</span>::default_parameters());
}
}
<span class="kw">impl </span>Printable <span class="kw">for </span>i16 {
<span class="kw">type </span>Parameters = Base;
<span class="kw">fn </span>print_2(<span class="self">self</span>, params: <span class="self">Self</span>::Parameters) {
<span class="kw">unsafe </span>{
<span class="kw">crate</span>::library::arduboy2::print_int(<span class="self">self</span>, params <span class="kw">as </span>c_int);
}
}
<span class="kw">fn </span>default_parameters() -&gt; <span class="self">Self</span>::Parameters {
Base::Dec
}
}
<span class="kw">impl </span>Printable <span class="kw">for </span>u16 {
<span class="kw">type </span>Parameters = Base;
<span class="kw">fn </span>print_2(<span class="self">self</span>, params: <span class="self">Self</span>::Parameters) {
<span class="kw">unsafe </span>{
<span class="kw">crate</span>::library::arduboy2::print_unsigned_int(<span class="self">self</span>, params <span class="kw">as </span>c_int);
}
}
<span class="kw">fn </span>default_parameters() -&gt; <span class="self">Self</span>::Parameters {
Base::Dec
}
}
<span class="kw">impl </span>Printable <span class="kw">for </span>i32 {
<span class="kw">type </span>Parameters = Base;
<span class="kw">fn </span>print_2(<span class="self">self</span>, params: <span class="self">Self</span>::Parameters) {
<span class="kw">unsafe </span>{
<span class="kw">crate</span>::library::arduboy2::print_long(<span class="self">self</span>, params <span class="kw">as </span>c_int);
}
}
<span class="kw">fn </span>default_parameters() -&gt; <span class="self">Self</span>::Parameters {
Base::Dec
}
}
<span class="kw">impl </span>Printable <span class="kw">for </span>u32 {
<span class="kw">type </span>Parameters = Base;
<span class="kw">fn </span>print_2(<span class="self">self</span>, params: <span class="self">Self</span>::Parameters) {
<span class="kw">unsafe </span>{
<span class="kw">crate</span>::library::arduboy2::print_unsigned_long(<span class="self">self</span>, params <span class="kw">as </span>c_int);
}
}
<span class="kw">fn </span>default_parameters() -&gt; <span class="self">Self</span>::Parameters {
Base::Dec
}
}
<span class="kw">impl </span>Printable <span class="kw">for </span><span class="kw-2">&amp;</span>[u8] {
<span class="kw">type </span>Parameters = ();
<span class="kw">fn </span>print_2(<span class="self">self</span>, _params: <span class="self">Self</span>::Parameters) {
<span class="kw">unsafe </span>{
<span class="kw">crate</span>::library::arduboy2::print_chars(<span class="self">self </span><span class="kw">as </span><span class="kw-2">*const </span>[u8] <span class="kw">as </span><span class="kw-2">*const </span>i8);
}
}
<span class="kw">fn </span>default_parameters() -&gt; <span class="self">Self</span>::Parameters {}
}
<span class="kw">impl </span>Printable <span class="kw">for </span><span class="kw-2">&amp;</span>str {
<span class="kw">type </span>Parameters = ();
<span class="kw">fn </span>print_2(<span class="self">self</span>, _params: <span class="self">Self</span>::Parameters) {
<span class="kw">unsafe </span>{
<span class="kw">crate</span>::library::arduboy2::print_chars(<span class="self">self</span>.as_bytes() <span class="kw">as </span><span class="kw-2">*const </span>[u8] <span class="kw">as </span><span class="kw-2">*const </span>i8);
}
}
<span class="kw">fn </span>default_parameters() -&gt; <span class="self">Self</span>::Parameters {}
}
<span class="kw">impl</span>&lt;<span class="kw">const </span>N: usize&gt; Printable <span class="kw">for </span><span class="kw">crate</span>::heapless::String&lt;N&gt; {
<span class="kw">type </span>Parameters = ();
<span class="kw">fn </span>print_2(<span class="self">self</span>, _params: <span class="self">Self</span>::Parameters) {
<span class="kw">unsafe </span>{
<span class="kw">crate</span>::library::arduboy2::print_chars(<span class="self">self</span>.as_bytes() <span class="kw">as </span><span class="kw-2">*const </span>[u8] <span class="kw">as </span><span class="kw-2">*const </span>i8);
}
}
<span class="kw">fn </span>default_parameters() -&gt; <span class="self">Self</span>::Parameters {}
}
<span class="kw">impl </span>Printable <span class="kw">for </span>Pstring {
<span class="kw">type </span>Parameters = ();
<span class="kw">fn </span>print_2(<span class="self">self</span>, _params: <span class="self">Self</span>::Parameters) {
<span class="kw">unsafe </span>{
<span class="kw">crate</span>::library::arduboy2::print_chars_progmem(<span class="self">self</span>.pointer);
}
}
<span class="kw">fn </span>default_parameters() -&gt; <span class="self">Self</span>::Parameters {}
}
</code></pre></div></section></main></body></html>

View file

@ -1,825 +0,0 @@
<!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="Source of the Rust file `arduboy-rust/src/serial_print.rs`."><title>serial_print.rs - source</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-47e7ab555ef2818a.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="arduboy_rust" data-themes="" data-resource-suffix="" data-rustdoc-version="1.74.0-nightly (d9c8274fb 2023-09-12)" data-channel="nightly" data-search-js="search-5d3eaacf19ebf04f.js" data-settings-js="settings-74424d7eec62a23e.js" data-settings-css="settings-8c76f75bfb6bd192.css" data-theme-light-css="light-f194925aa375ae96.css" data-theme-dark-css="dark-1dd4d1ce031e15de.css" data-theme-ayu-css="ayu-49e58d069f567085.css" ><script src="../../static.files/storage-db41da1a38ea3cb8.js"></script><script defer src="../../static.files/src-script-3280b574d94e47b4.js"></script><script defer src="../../src-files.js"></script><script defer src="../../static.files/main-8d035c8cea6edbc4.js"></script><noscript><link rel="stylesheet" media="(prefers-color-scheme:light)" href="../../static.files/light-f194925aa375ae96.css"><link rel="stylesheet" media="(prefers-color-scheme:dark)" href="../../static.files/dark-1dd4d1ce031e15de.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 src"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"></nav><main><nav class="sub"><a class="sub-logo-container" href="../../arduboy_rust/index.html"><img class="rust-logo" src="../../static.files/rust-logo-151179464ae7ed46.svg" alt="logo"></a><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="example-wrap"><div data-nosnippet><pre class="src-line-numbers"><a href="#1" id="1">1</a>
<a href="#2" id="2">2</a>
<a href="#3" id="3">3</a>
<a href="#4" id="4">4</a>
<a href="#5" id="5">5</a>
<a href="#6" id="6">6</a>
<a href="#7" id="7">7</a>
<a href="#8" id="8">8</a>
<a href="#9" id="9">9</a>
<a href="#10" id="10">10</a>
<a href="#11" id="11">11</a>
<a href="#12" id="12">12</a>
<a href="#13" id="13">13</a>
<a href="#14" id="14">14</a>
<a href="#15" id="15">15</a>
<a href="#16" id="16">16</a>
<a href="#17" id="17">17</a>
<a href="#18" id="18">18</a>
<a href="#19" id="19">19</a>
<a href="#20" id="20">20</a>
<a href="#21" id="21">21</a>
<a href="#22" id="22">22</a>
<a href="#23" id="23">23</a>
<a href="#24" id="24">24</a>
<a href="#25" id="25">25</a>
<a href="#26" id="26">26</a>
<a href="#27" id="27">27</a>
<a href="#28" id="28">28</a>
<a href="#29" id="29">29</a>
<a href="#30" id="30">30</a>
<a href="#31" id="31">31</a>
<a href="#32" id="32">32</a>
<a href="#33" id="33">33</a>
<a href="#34" id="34">34</a>
<a href="#35" id="35">35</a>
<a href="#36" id="36">36</a>
<a href="#37" id="37">37</a>
<a href="#38" id="38">38</a>
<a href="#39" id="39">39</a>
<a href="#40" id="40">40</a>
<a href="#41" id="41">41</a>
<a href="#42" id="42">42</a>
<a href="#43" id="43">43</a>
<a href="#44" id="44">44</a>
<a href="#45" id="45">45</a>
<a href="#46" id="46">46</a>
<a href="#47" id="47">47</a>
<a href="#48" id="48">48</a>
<a href="#49" id="49">49</a>
<a href="#50" id="50">50</a>
<a href="#51" id="51">51</a>
<a href="#52" id="52">52</a>
<a href="#53" id="53">53</a>
<a href="#54" id="54">54</a>
<a href="#55" id="55">55</a>
<a href="#56" id="56">56</a>
<a href="#57" id="57">57</a>
<a href="#58" id="58">58</a>
<a href="#59" id="59">59</a>
<a href="#60" id="60">60</a>
<a href="#61" id="61">61</a>
<a href="#62" id="62">62</a>
<a href="#63" id="63">63</a>
<a href="#64" id="64">64</a>
<a href="#65" id="65">65</a>
<a href="#66" id="66">66</a>
<a href="#67" id="67">67</a>
<a href="#68" id="68">68</a>
<a href="#69" id="69">69</a>
<a href="#70" id="70">70</a>
<a href="#71" id="71">71</a>
<a href="#72" id="72">72</a>
<a href="#73" id="73">73</a>
<a href="#74" id="74">74</a>
<a href="#75" id="75">75</a>
<a href="#76" id="76">76</a>
<a href="#77" id="77">77</a>
<a href="#78" id="78">78</a>
<a href="#79" id="79">79</a>
<a href="#80" id="80">80</a>
<a href="#81" id="81">81</a>
<a href="#82" id="82">82</a>
<a href="#83" id="83">83</a>
<a href="#84" id="84">84</a>
<a href="#85" id="85">85</a>
<a href="#86" id="86">86</a>
<a href="#87" id="87">87</a>
<a href="#88" id="88">88</a>
<a href="#89" id="89">89</a>
<a href="#90" id="90">90</a>
<a href="#91" id="91">91</a>
<a href="#92" id="92">92</a>
<a href="#93" id="93">93</a>
<a href="#94" id="94">94</a>
<a href="#95" id="95">95</a>
<a href="#96" id="96">96</a>
<a href="#97" id="97">97</a>
<a href="#98" id="98">98</a>
<a href="#99" id="99">99</a>
<a href="#100" id="100">100</a>
<a href="#101" id="101">101</a>
<a href="#102" id="102">102</a>
<a href="#103" id="103">103</a>
<a href="#104" id="104">104</a>
<a href="#105" id="105">105</a>
<a href="#106" id="106">106</a>
<a href="#107" id="107">107</a>
<a href="#108" id="108">108</a>
<a href="#109" id="109">109</a>
<a href="#110" id="110">110</a>
<a href="#111" id="111">111</a>
<a href="#112" id="112">112</a>
<a href="#113" id="113">113</a>
<a href="#114" id="114">114</a>
<a href="#115" id="115">115</a>
<a href="#116" id="116">116</a>
<a href="#117" id="117">117</a>
<a href="#118" id="118">118</a>
<a href="#119" id="119">119</a>
<a href="#120" id="120">120</a>
<a href="#121" id="121">121</a>
<a href="#122" id="122">122</a>
<a href="#123" id="123">123</a>
<a href="#124" id="124">124</a>
<a href="#125" id="125">125</a>
<a href="#126" id="126">126</a>
<a href="#127" id="127">127</a>
<a href="#128" id="128">128</a>
<a href="#129" id="129">129</a>
<a href="#130" id="130">130</a>
<a href="#131" id="131">131</a>
<a href="#132" id="132">132</a>
<a href="#133" id="133">133</a>
<a href="#134" id="134">134</a>
<a href="#135" id="135">135</a>
<a href="#136" id="136">136</a>
<a href="#137" id="137">137</a>
<a href="#138" id="138">138</a>
<a href="#139" id="139">139</a>
<a href="#140" id="140">140</a>
<a href="#141" id="141">141</a>
<a href="#142" id="142">142</a>
<a href="#143" id="143">143</a>
<a href="#144" id="144">144</a>
<a href="#145" id="145">145</a>
<a href="#146" id="146">146</a>
<a href="#147" id="147">147</a>
<a href="#148" id="148">148</a>
<a href="#149" id="149">149</a>
<a href="#150" id="150">150</a>
<a href="#151" id="151">151</a>
<a href="#152" id="152">152</a>
<a href="#153" id="153">153</a>
<a href="#154" id="154">154</a>
<a href="#155" id="155">155</a>
<a href="#156" id="156">156</a>
<a href="#157" id="157">157</a>
<a href="#158" id="158">158</a>
<a href="#159" id="159">159</a>
<a href="#160" id="160">160</a>
<a href="#161" id="161">161</a>
<a href="#162" id="162">162</a>
<a href="#163" id="163">163</a>
<a href="#164" id="164">164</a>
<a href="#165" id="165">165</a>
<a href="#166" id="166">166</a>
<a href="#167" id="167">167</a>
<a href="#168" id="168">168</a>
<a href="#169" id="169">169</a>
<a href="#170" id="170">170</a>
<a href="#171" id="171">171</a>
<a href="#172" id="172">172</a>
<a href="#173" id="173">173</a>
<a href="#174" id="174">174</a>
<a href="#175" id="175">175</a>
<a href="#176" id="176">176</a>
<a href="#177" id="177">177</a>
<a href="#178" id="178">178</a>
<a href="#179" id="179">179</a>
<a href="#180" id="180">180</a>
<a href="#181" id="181">181</a>
<a href="#182" id="182">182</a>
<a href="#183" id="183">183</a>
<a href="#184" id="184">184</a>
<a href="#185" id="185">185</a>
<a href="#186" id="186">186</a>
<a href="#187" id="187">187</a>
<a href="#188" id="188">188</a>
<a href="#189" id="189">189</a>
<a href="#190" id="190">190</a>
<a href="#191" id="191">191</a>
<a href="#192" id="192">192</a>
<a href="#193" id="193">193</a>
<a href="#194" id="194">194</a>
<a href="#195" id="195">195</a>
<a href="#196" id="196">196</a>
<a href="#197" id="197">197</a>
<a href="#198" id="198">198</a>
<a href="#199" id="199">199</a>
<a href="#200" id="200">200</a>
<a href="#201" id="201">201</a>
<a href="#202" id="202">202</a>
<a href="#203" id="203">203</a>
<a href="#204" id="204">204</a>
<a href="#205" id="205">205</a>
<a href="#206" id="206">206</a>
<a href="#207" id="207">207</a>
<a href="#208" id="208">208</a>
<a href="#209" id="209">209</a>
<a href="#210" id="210">210</a>
<a href="#211" id="211">211</a>
<a href="#212" id="212">212</a>
<a href="#213" id="213">213</a>
<a href="#214" id="214">214</a>
<a href="#215" id="215">215</a>
<a href="#216" id="216">216</a>
<a href="#217" id="217">217</a>
<a href="#218" id="218">218</a>
<a href="#219" id="219">219</a>
<a href="#220" id="220">220</a>
<a href="#221" id="221">221</a>
<a href="#222" id="222">222</a>
<a href="#223" id="223">223</a>
<a href="#224" id="224">224</a>
<a href="#225" id="225">225</a>
<a href="#226" id="226">226</a>
<a href="#227" id="227">227</a>
<a href="#228" id="228">228</a>
<a href="#229" id="229">229</a>
<a href="#230" id="230">230</a>
<a href="#231" id="231">231</a>
<a href="#232" id="232">232</a>
<a href="#233" id="233">233</a>
<a href="#234" id="234">234</a>
<a href="#235" id="235">235</a>
<a href="#236" id="236">236</a>
<a href="#237" id="237">237</a>
<a href="#238" id="238">238</a>
<a href="#239" id="239">239</a>
<a href="#240" id="240">240</a>
<a href="#241" id="241">241</a>
<a href="#242" id="242">242</a>
<a href="#243" id="243">243</a>
<a href="#244" id="244">244</a>
<a href="#245" id="245">245</a>
<a href="#246" id="246">246</a>
<a href="#247" id="247">247</a>
<a href="#248" id="248">248</a>
<a href="#249" id="249">249</a>
<a href="#250" id="250">250</a>
<a href="#251" id="251">251</a>
<a href="#252" id="252">252</a>
<a href="#253" id="253">253</a>
<a href="#254" id="254">254</a>
<a href="#255" id="255">255</a>
<a href="#256" id="256">256</a>
<a href="#257" id="257">257</a>
<a href="#258" id="258">258</a>
<a href="#259" id="259">259</a>
<a href="#260" id="260">260</a>
<a href="#261" id="261">261</a>
<a href="#262" id="262">262</a>
<a href="#263" id="263">263</a>
<a href="#264" id="264">264</a>
<a href="#265" id="265">265</a>
<a href="#266" id="266">266</a>
<a href="#267" id="267">267</a>
<a href="#268" id="268">268</a>
<a href="#269" id="269">269</a>
<a href="#270" id="270">270</a>
<a href="#271" id="271">271</a>
<a href="#272" id="272">272</a>
<a href="#273" id="273">273</a>
<a href="#274" id="274">274</a>
<a href="#275" id="275">275</a>
<a href="#276" id="276">276</a>
<a href="#277" id="277">277</a>
<a href="#278" id="278">278</a>
<a href="#279" id="279">279</a>
<a href="#280" id="280">280</a>
<a href="#281" id="281">281</a>
<a href="#282" id="282">282</a>
<a href="#283" id="283">283</a>
<a href="#284" id="284">284</a>
<a href="#285" id="285">285</a>
<a href="#286" id="286">286</a>
<a href="#287" id="287">287</a>
<a href="#288" id="288">288</a>
<a href="#289" id="289">289</a>
<a href="#290" id="290">290</a>
<a href="#291" id="291">291</a>
<a href="#292" id="292">292</a>
<a href="#293" id="293">293</a>
<a href="#294" id="294">294</a>
<a href="#295" id="295">295</a>
<a href="#296" id="296">296</a>
<a href="#297" id="297">297</a>
<a href="#298" id="298">298</a>
<a href="#299" id="299">299</a>
<a href="#300" id="300">300</a>
<a href="#301" id="301">301</a>
<a href="#302" id="302">302</a>
<a href="#303" id="303">303</a>
<a href="#304" id="304">304</a>
<a href="#305" id="305">305</a>
<a href="#306" id="306">306</a>
<a href="#307" id="307">307</a>
<a href="#308" id="308">308</a>
<a href="#309" id="309">309</a>
<a href="#310" id="310">310</a>
<a href="#311" id="311">311</a>
<a href="#312" id="312">312</a>
<a href="#313" id="313">313</a>
<a href="#314" id="314">314</a>
<a href="#315" id="315">315</a>
<a href="#316" id="316">316</a>
<a href="#317" id="317">317</a>
<a href="#318" id="318">318</a>
<a href="#319" id="319">319</a>
<a href="#320" id="320">320</a>
<a href="#321" id="321">321</a>
<a href="#322" id="322">322</a>
<a href="#323" id="323">323</a>
<a href="#324" id="324">324</a>
<a href="#325" id="325">325</a>
<a href="#326" id="326">326</a>
<a href="#327" id="327">327</a>
<a href="#328" id="328">328</a>
<a href="#329" id="329">329</a>
<a href="#330" id="330">330</a>
<a href="#331" id="331">331</a>
<a href="#332" id="332">332</a>
<a href="#333" id="333">333</a>
<a href="#334" id="334">334</a>
<a href="#335" id="335">335</a>
<a href="#336" id="336">336</a>
<a href="#337" id="337">337</a>
<a href="#338" id="338">338</a>
<a href="#339" id="339">339</a>
<a href="#340" id="340">340</a>
<a href="#341" id="341">341</a>
<a href="#342" id="342">342</a>
<a href="#343" id="343">343</a>
<a href="#344" id="344">344</a>
<a href="#345" id="345">345</a>
<a href="#346" id="346">346</a>
<a href="#347" id="347">347</a>
<a href="#348" id="348">348</a>
<a href="#349" id="349">349</a>
<a href="#350" id="350">350</a>
<a href="#351" id="351">351</a>
<a href="#352" id="352">352</a>
<a href="#353" id="353">353</a>
<a href="#354" id="354">354</a>
<a href="#355" id="355">355</a>
<a href="#356" id="356">356</a>
<a href="#357" id="357">357</a>
<a href="#358" id="358">358</a>
<a href="#359" id="359">359</a>
<a href="#360" id="360">360</a>
<a href="#361" id="361">361</a>
<a href="#362" id="362">362</a>
<a href="#363" id="363">363</a>
<a href="#364" id="364">364</a>
<a href="#365" id="365">365</a>
<a href="#366" id="366">366</a>
<a href="#367" id="367">367</a>
<a href="#368" id="368">368</a>
<a href="#369" id="369">369</a>
<a href="#370" id="370">370</a>
<a href="#371" id="371">371</a>
<a href="#372" id="372">372</a>
<a href="#373" id="373">373</a>
<a href="#374" id="374">374</a>
<a href="#375" id="375">375</a>
<a href="#376" id="376">376</a>
<a href="#377" id="377">377</a>
<a href="#378" id="378">378</a>
<a href="#379" id="379">379</a>
<a href="#380" id="380">380</a>
<a href="#381" id="381">381</a>
<a href="#382" id="382">382</a>
<a href="#383" id="383">383</a>
<a href="#384" id="384">384</a>
<a href="#385" id="385">385</a>
<a href="#386" id="386">386</a>
<a href="#387" id="387">387</a>
<a href="#388" id="388">388</a>
<a href="#389" id="389">389</a>
<a href="#390" id="390">390</a>
<a href="#391" id="391">391</a>
<a href="#392" id="392">392</a>
<a href="#393" id="393">393</a>
<a href="#394" id="394">394</a>
<a href="#395" id="395">395</a>
<a href="#396" id="396">396</a>
<a href="#397" id="397">397</a>
<a href="#398" id="398">398</a>
<a href="#399" id="399">399</a>
<a href="#400" id="400">400</a>
<a href="#401" id="401">401</a>
<a href="#402" id="402">402</a>
<a href="#403" id="403">403</a>
<a href="#404" id="404">404</a>
<a href="#405" id="405">405</a>
<a href="#406" id="406">406</a>
<a href="#407" id="407">407</a>
<a href="#408" id="408">408</a>
<a href="#409" id="409">409</a>
<a href="#410" id="410">410</a>
<a href="#411" id="411">411</a>
<a href="#412" id="412">412</a>
</pre></div><pre class="rust"><code><span class="doccomment">//! This is the Module to interact in a save way with the Arduino Serial C++ library.
//!
//! You will need to uncomment the Arduino_Serial_Library in the import_config.h file.
</span><span class="kw">use </span><span class="kw">crate</span>::prelude::Pstring;
<span class="kw">use </span>core::ffi::{c_char, c_int, c_long, c_size_t, c_uchar, c_uint, c_ulong};
<span class="kw">use </span><span class="kw">crate</span>::print::Base;
<span class="kw">extern </span><span class="string">&quot;C&quot; </span>{
<span class="attr">#[link_name = <span class="string">&quot;arduino_serial_begin&quot;</span>]
</span><span class="kw">fn </span>serial_begin(serial: c_ulong);
<span class="attr">#[link_name = <span class="string">&quot;arduino_serial_end&quot;</span>]
</span><span class="kw">fn </span>serial_end();
<span class="attr">#[link_name = <span class="string">&quot;arduino_serial_available&quot;</span>]
</span><span class="kw">fn </span>serial_available() -&gt; c_int;
<span class="attr">#[link_name = <span class="string">&quot;arduino_serial_read&quot;</span>]
</span><span class="kw">fn </span>serial_read() -&gt; c_int;
}
<span class="doccomment">///The Arduino Serial Print class is available for writing text to the screen buffer.
///
///In the same manner as the Arduino arduboy.print(), etc., functions.
///
///
///Example
/// ```
/// let value: i16 = 42;
///
/// serial::print(b&quot;Hello World\n\0&quot;[..]); // Prints &quot;Hello World&quot; and then sets the
/// // text cursor to the start of the next line
/// serial::print(f!(b&quot;Hello World\n&quot;)); // Prints &quot;Hello World&quot; but does not use the 2kb ram
/// serial::print(value); // Prints &quot;42&quot;
/// serial::print(&quot;\n\0&quot;); // Sets the text cursor to the start of the next line
/// serial::print(&quot;hello world&quot;) // Prints normal [&amp;str]
/// ```
</span><span class="kw">pub fn </span>print(x: <span class="kw">impl </span>Serialprintable) {
x.print()
}
<span class="doccomment">///The Arduino Serial Print class is available for writing text to the screen buffer.
///
///In the same manner as the Arduino arduboy.print(), etc., functions.
///
///
///Example
/// ```
/// let value: i16 = 42;
///
/// serial::print(b&quot;Hello World\n\0&quot;[..]); // Prints &quot;Hello World&quot; and then sets the
/// // text cursor to the start of the next line
/// serial::print(f!(b&quot;Hello World\n&quot;)); // Prints &quot;Hello World&quot; but does not use the 2kb ram
/// serial::print(value); // Prints &quot;42&quot;
/// serial::print(&quot;\n\0&quot;); // Sets the text cursor to the start of the next line
/// serial::print(&quot;hello world&quot;) // Prints normal [&amp;str]
/// ```
</span><span class="kw">pub fn </span>println(x: <span class="kw">impl </span>Serialprintlnable) {
x.println()
}
<span class="doccomment">/// Sets the data rate in bits per second (baud) for serial data transmission. For communicating with Serial Monitor, make sure to use one of the baud rates listed in the menu at the bottom right corner of its screen. You can, however, specify other rates - for example, to communicate over pins 0 and 1 with a component that requires a particular baud rate.
///
/// ### Example
/// ```
/// serial::begin(9600)
/// ```
</span><span class="kw">pub fn </span>begin(baud_rates: u32) {
<span class="kw">unsafe </span>{ serial_begin(baud_rates) }
}
<span class="doccomment">/// Disables serial communication, allowing the RX and TX pins to be used for general input and output. To re-enable serial communication, call [begin()].
</span><span class="kw">pub fn </span>end() {
<span class="kw">unsafe </span>{ serial_end() }
}
<span class="doccomment">/// Reads incoming serial data.
/// Use only inside of [available()]:
/// ```
/// if (serial::available() &gt; 0) {
/// // read the incoming byte:
/// let incoming_byte: i16 = Serial::read();
///
/// // say what you got:
/// serial::print(&quot;I received: &quot;);
/// serial::println(incoming_byte);
/// }
/// ```
/// ### Returns
///
///The first byte of incoming serial data available (or -1 if no data is available). Data type: int.
</span><span class="kw">pub fn </span>read() -&gt; i16 {
<span class="kw">unsafe </span>{ serial_read() }
}
<span class="doccomment">/// Reads incoming serial data.
///
/// Use only inside of [available()]:
/// ```
/// if (Serial::available() &gt; 0) {
/// // read the incoming byte:
/// let incomingByte: &amp;str = Serial::read_as_utf8_str();
///
/// // say what you got:
/// Serial::print(&quot;I received: &quot;);
/// Serial::println(incomingByte);
/// }
/// ```
/// ### Returns
///
///The first byte of incoming serial data available (or -1 if no data is available). Data type: &amp;str.
</span><span class="kw">pub fn </span>read_as_utf8_str() -&gt; <span class="kw-2">&amp;</span><span class="lifetime">&#39;static </span>str {
<span class="kw">let </span>intcoming_byte = <span class="kw">unsafe </span>{ serial_read() };
<span class="kw">static </span><span class="kw-2">mut </span>L: [u8; <span class="number">2</span>] = [<span class="number">0</span>, <span class="number">0</span>];
<span class="kw">unsafe </span>{
L[<span class="number">0</span>] = intcoming_byte <span class="kw">as </span>u8;
}
<span class="kw">unsafe </span>{ core::str::from_utf8(<span class="kw-2">&amp;</span>L).unwrap() }
}
<span class="doccomment">/// Get the number of bytes (characters) available for reading from the serial port. This is data thats already arrived and stored in the serial receive buffer (which holds 64 bytes).
/// ### Example
/// ```
/// if (Serial::available() &gt; 0) {
/// // read the incoming byte:
/// incomingByte = Serial::read();
///
/// // say what you got:
/// Serial::print(&quot;I received: &quot;);
/// Serial::println(incomingByte);
/// }
/// ```
</span><span class="kw">pub fn </span>available() -&gt; i16 {
<span class="kw">unsafe </span>{ serial_available() }
}
<span class="kw">pub trait </span>Serialprintlnable
<span class="kw">where
</span><span class="self">Self</span>: Sized,
{
<span class="kw">type </span>Parameters;
<span class="kw">fn </span>println_2(<span class="self">self</span>, params: <span class="self">Self</span>::Parameters);
<span class="kw">fn </span>default_parameters() -&gt; <span class="self">Self</span>::Parameters;
<span class="kw">fn </span>println(<span class="self">self</span>) {
<span class="self">self</span>.println_2(<span class="self">Self</span>::default_parameters());
}
}
<span class="kw">impl </span>Serialprintlnable <span class="kw">for </span>i16 {
<span class="kw">type </span>Parameters = Base;
<span class="kw">fn </span>println_2(<span class="self">self</span>, params: <span class="self">Self</span>::Parameters) {
<span class="kw">unsafe </span>{
println_int(<span class="self">self</span>, params <span class="kw">as </span>c_int);
}
}
<span class="kw">fn </span>default_parameters() -&gt; <span class="self">Self</span>::Parameters {
Base::Dec
}
}
<span class="kw">impl </span>Serialprintlnable <span class="kw">for </span>u16 {
<span class="kw">type </span>Parameters = Base;
<span class="kw">fn </span>println_2(<span class="self">self</span>, params: <span class="self">Self</span>::Parameters) {
<span class="kw">unsafe </span>{
println_unsigned_int(<span class="self">self</span>, params <span class="kw">as </span>c_int);
}
}
<span class="kw">fn </span>default_parameters() -&gt; <span class="self">Self</span>::Parameters {
Base::Dec
}
}
<span class="kw">impl </span>Serialprintlnable <span class="kw">for </span>i32 {
<span class="kw">type </span>Parameters = Base;
<span class="kw">fn </span>println_2(<span class="self">self</span>, params: <span class="self">Self</span>::Parameters) {
<span class="kw">unsafe </span>{
println_long(<span class="self">self</span>, params <span class="kw">as </span>c_int);
}
}
<span class="kw">fn </span>default_parameters() -&gt; <span class="self">Self</span>::Parameters {
Base::Dec
}
}
<span class="kw">impl </span>Serialprintlnable <span class="kw">for </span>u32 {
<span class="kw">type </span>Parameters = Base;
<span class="kw">fn </span>println_2(<span class="self">self</span>, params: <span class="self">Self</span>::Parameters) {
<span class="kw">unsafe </span>{
println_unsigned_long(<span class="self">self</span>, params <span class="kw">as </span>c_int);
}
}
<span class="kw">fn </span>default_parameters() -&gt; <span class="self">Self</span>::Parameters {
Base::Dec
}
}
<span class="kw">impl </span>Serialprintlnable <span class="kw">for </span><span class="kw-2">&amp;</span>[u8] {
<span class="kw">type </span>Parameters = ();
<span class="kw">fn </span>println_2(<span class="self">self</span>, _params: <span class="self">Self</span>::Parameters) {
<span class="kw">unsafe </span>{
println_chars(<span class="self">self </span><span class="kw">as </span><span class="kw-2">*const </span>[u8] <span class="kw">as </span><span class="kw-2">*const </span>i8);
}
}
<span class="kw">fn </span>default_parameters() -&gt; <span class="self">Self</span>::Parameters {}
}
<span class="kw">impl </span>Serialprintlnable <span class="kw">for </span><span class="kw-2">&amp;</span>str {
<span class="kw">type </span>Parameters = ();
<span class="kw">fn </span>println_2(<span class="self">self</span>, _params: <span class="self">Self</span>::Parameters) {
<span class="kw">unsafe </span>{
println_chars(<span class="self">self</span>.as_bytes() <span class="kw">as </span><span class="kw-2">*const </span>[u8] <span class="kw">as </span><span class="kw-2">*const </span>i8);
}
}
<span class="kw">fn </span>default_parameters() -&gt; <span class="self">Self</span>::Parameters {}
}
<span class="kw">impl</span>&lt;<span class="kw">const </span>N: usize&gt; Serialprintlnable <span class="kw">for </span><span class="kw">crate</span>::heapless::String&lt;N&gt; {
<span class="kw">type </span>Parameters = ();
<span class="kw">fn </span>println_2(<span class="self">self</span>, _params: <span class="self">Self</span>::Parameters) {
<span class="kw">unsafe </span>{
println_chars(<span class="self">self</span>.as_bytes() <span class="kw">as </span><span class="kw-2">*const </span>[u8] <span class="kw">as </span><span class="kw-2">*const </span>i8);
}
}
<span class="kw">fn </span>default_parameters() -&gt; <span class="self">Self</span>::Parameters {}
}
<span class="kw">impl </span>Serialprintlnable <span class="kw">for </span>Pstring {
<span class="kw">type </span>Parameters = ();
<span class="kw">fn </span>println_2(<span class="self">self</span>, _params: <span class="self">Self</span>::Parameters) {
<span class="kw">unsafe </span>{
println_chars_progmem(<span class="self">self</span>.pointer);
}
}
<span class="kw">fn </span>default_parameters() -&gt; <span class="self">Self</span>::Parameters {}
}
<span class="kw">extern </span><span class="string">&quot;C&quot; </span>{
<span class="attr">#[link_name = <span class="string">&quot;arduino_serial_println_chars&quot;</span>]
</span><span class="kw">fn </span>println_chars(cstr: <span class="kw-2">*const </span>c_char);
<span class="attr">#[doc(hidden)]
#[link_name = <span class="string">&quot;arduino_serial_println_chars_progmem&quot;</span>]
</span><span class="kw">fn </span>println_chars_progmem(pstring: <span class="kw-2">*const </span>c_char);
<span class="comment">// #[link_name = &quot;arduino_serial_println_char&quot;]
// fn println_char(c: c_char) -&gt; c_size_t;
</span><span class="attr">#[doc(hidden)]
#[link_name = <span class="string">&quot;arduino_serial_println_int&quot;</span>]
</span><span class="kw">fn </span>println_int(n: c_int, base: c_int) -&gt; c_size_t;
<span class="attr">#[doc(hidden)]
#[link_name = <span class="string">&quot;arduino_serial_println_long&quot;</span>]
</span><span class="kw">fn </span>println_long(n: c_long, base: c_int) -&gt; c_size_t;
<span class="attr">#[allow(dead_code)]
#[doc(hidden)]
#[link_name = <span class="string">&quot;arduino_serial_println_unsigned_char&quot;</span>]
</span><span class="kw">fn </span>println_unsigned_char(n: c_uchar, base: c_int) -&gt; c_size_t;
<span class="attr">#[doc(hidden)]
#[link_name = <span class="string">&quot;arduino_serial_println_unsigned_int&quot;</span>]
</span><span class="kw">fn </span>println_unsigned_int(n: c_uint, base: c_int) -&gt; c_size_t;
<span class="attr">#[doc(hidden)]
#[link_name = <span class="string">&quot;arduino_serial_println_unsigned_long&quot;</span>]
</span><span class="kw">fn </span>println_unsigned_long(n: c_ulong, base: c_int) -&gt; c_size_t;
}
<span class="kw">pub trait </span>Serialprintable
<span class="kw">where
</span><span class="self">Self</span>: Sized,
{
<span class="kw">type </span>Parameters;
<span class="kw">fn </span>print_2(<span class="self">self</span>, params: <span class="self">Self</span>::Parameters);
<span class="kw">fn </span>default_parameters() -&gt; <span class="self">Self</span>::Parameters;
<span class="kw">fn </span>print(<span class="self">self</span>) {
<span class="self">self</span>.print_2(<span class="self">Self</span>::default_parameters());
}
}
<span class="kw">impl </span>Serialprintable <span class="kw">for </span>i16 {
<span class="kw">type </span>Parameters = Base;
<span class="kw">fn </span>print_2(<span class="self">self</span>, params: <span class="self">Self</span>::Parameters) {
<span class="kw">unsafe </span>{
print_int(<span class="self">self</span>, params <span class="kw">as </span>c_int);
}
}
<span class="kw">fn </span>default_parameters() -&gt; <span class="self">Self</span>::Parameters {
Base::Dec
}
}
<span class="kw">impl </span>Serialprintable <span class="kw">for </span>u16 {
<span class="kw">type </span>Parameters = Base;
<span class="kw">fn </span>print_2(<span class="self">self</span>, params: <span class="self">Self</span>::Parameters) {
<span class="kw">unsafe </span>{
print_unsigned_int(<span class="self">self</span>, params <span class="kw">as </span>c_int);
}
}
<span class="kw">fn </span>default_parameters() -&gt; <span class="self">Self</span>::Parameters {
Base::Dec
}
}
<span class="kw">impl </span>Serialprintable <span class="kw">for </span>i32 {
<span class="kw">type </span>Parameters = Base;
<span class="kw">fn </span>print_2(<span class="self">self</span>, params: <span class="self">Self</span>::Parameters) {
<span class="kw">unsafe </span>{
print_long(<span class="self">self</span>, params <span class="kw">as </span>c_int);
}
}
<span class="kw">fn </span>default_parameters() -&gt; <span class="self">Self</span>::Parameters {
Base::Dec
}
}
<span class="kw">impl </span>Serialprintable <span class="kw">for </span>u32 {
<span class="kw">type </span>Parameters = Base;
<span class="kw">fn </span>print_2(<span class="self">self</span>, params: <span class="self">Self</span>::Parameters) {
<span class="kw">unsafe </span>{
print_unsigned_long(<span class="self">self</span>, params <span class="kw">as </span>c_int);
}
}
<span class="kw">fn </span>default_parameters() -&gt; <span class="self">Self</span>::Parameters {
Base::Dec
}
}
<span class="kw">impl </span>Serialprintable <span class="kw">for </span><span class="kw-2">&amp;</span>[u8] {
<span class="kw">type </span>Parameters = ();
<span class="kw">fn </span>print_2(<span class="self">self</span>, _params: <span class="self">Self</span>::Parameters) {
<span class="kw">unsafe </span>{
print_chars(<span class="self">self </span><span class="kw">as </span><span class="kw-2">*const </span>[u8] <span class="kw">as </span><span class="kw-2">*const </span>i8);
}
}
<span class="kw">fn </span>default_parameters() -&gt; <span class="self">Self</span>::Parameters {}
}
<span class="kw">impl </span>Serialprintable <span class="kw">for </span><span class="kw-2">&amp;</span>str {
<span class="kw">type </span>Parameters = ();
<span class="kw">fn </span>print_2(<span class="self">self</span>, _params: <span class="self">Self</span>::Parameters) {
<span class="kw">unsafe </span>{
print_chars(<span class="self">self</span>.as_bytes() <span class="kw">as </span><span class="kw-2">*const </span>[u8] <span class="kw">as </span><span class="kw-2">*const </span>i8);
}
}
<span class="kw">fn </span>default_parameters() -&gt; <span class="self">Self</span>::Parameters {}
}
<span class="kw">impl</span>&lt;<span class="kw">const </span>N: usize&gt; Serialprintable <span class="kw">for </span><span class="kw">crate</span>::heapless::String&lt;N&gt; {
<span class="kw">type </span>Parameters = ();
<span class="kw">fn </span>print_2(<span class="self">self</span>, _params: <span class="self">Self</span>::Parameters) {
<span class="kw">unsafe </span>{
print_chars(<span class="self">self</span>.as_bytes() <span class="kw">as </span><span class="kw-2">*const </span>[u8] <span class="kw">as </span><span class="kw-2">*const </span>i8);
}
}
<span class="kw">fn </span>default_parameters() -&gt; <span class="self">Self</span>::Parameters {}
}
<span class="kw">impl </span>Serialprintable <span class="kw">for </span>Pstring {
<span class="kw">type </span>Parameters = ();
<span class="kw">fn </span>print_2(<span class="self">self</span>, _params: <span class="self">Self</span>::Parameters) {
<span class="kw">unsafe </span>{
print_chars_progmem(<span class="self">self</span>.pointer);
}
}
<span class="kw">fn </span>default_parameters() -&gt; <span class="self">Self</span>::Parameters {}
}
<span class="kw">extern </span><span class="string">&quot;C&quot; </span>{
<span class="attr">#[link_name = <span class="string">&quot;arduino_serial_print_chars&quot;</span>]
</span><span class="kw">fn </span>print_chars(cstr: <span class="kw-2">*const </span>c_char);
<span class="attr">#[doc(hidden)]
#[link_name = <span class="string">&quot;arduino_serial_print_chars_progmem&quot;</span>]
</span><span class="kw">fn </span>print_chars_progmem(pstring: <span class="kw-2">*const </span>c_char);
<span class="comment">// #[link_name = &quot;arduino_serial_print_char&quot;]
// fn print_char(c: c_char) -&gt; c_size_t;
</span><span class="attr">#[doc(hidden)]
#[link_name = <span class="string">&quot;arduino_serial_print_int&quot;</span>]
</span><span class="kw">fn </span>print_int(n: c_int, base: c_int) -&gt; c_size_t;
<span class="attr">#[doc(hidden)]
#[link_name = <span class="string">&quot;arduino_serial_print_long&quot;</span>]
</span><span class="kw">fn </span>print_long(n: c_long, base: c_int) -&gt; c_size_t;
<span class="attr">#[allow(dead_code)]
#[doc(hidden)]
#[link_name = <span class="string">&quot;arduino_serial_print_unsigned_char&quot;</span>]
</span><span class="kw">fn </span>print_unsigned_char(n: c_uchar, base: c_int) -&gt; c_size_t;
<span class="attr">#[doc(hidden)]
#[link_name = <span class="string">&quot;arduino_serial_print_unsigned_int&quot;</span>]
</span><span class="kw">fn </span>print_unsigned_int(n: c_uint, base: c_int) -&gt; c_size_t;
<span class="attr">#[doc(hidden)]
#[link_name = <span class="string">&quot;arduino_serial_print_unsigned_long&quot;</span>]
</span><span class="kw">fn </span>print_unsigned_long(n: c_ulong, base: c_int) -&gt; c_size_t;
}
</code></pre></div></section></main></body></html>

View file

@ -1,19 +0,0 @@
<!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="Source of the Rust file `/home/zenn/.cargo/registry/src/index.crates.io-6f17d22bba15001f/atomic-polyfill-0.1.11/src/lib.rs`."><title>lib.rs - source</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-47e7ab555ef2818a.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="atomic_polyfill" data-themes="" data-resource-suffix="" data-rustdoc-version="1.74.0-nightly (d9c8274fb 2023-09-12)" data-channel="nightly" data-search-js="search-5d3eaacf19ebf04f.js" data-settings-js="settings-74424d7eec62a23e.js" data-settings-css="settings-8c76f75bfb6bd192.css" data-theme-light-css="light-f194925aa375ae96.css" data-theme-dark-css="dark-1dd4d1ce031e15de.css" data-theme-ayu-css="ayu-49e58d069f567085.css" ><script src="../../static.files/storage-db41da1a38ea3cb8.js"></script><script defer src="../../static.files/src-script-3280b574d94e47b4.js"></script><script defer src="../../src-files.js"></script><script defer src="../../static.files/main-8d035c8cea6edbc4.js"></script><noscript><link rel="stylesheet" media="(prefers-color-scheme:light)" href="../../static.files/light-f194925aa375ae96.css"><link rel="stylesheet" media="(prefers-color-scheme:dark)" href="../../static.files/dark-1dd4d1ce031e15de.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 src"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"></nav><main><nav class="sub"><a class="sub-logo-container" href="../../atomic_polyfill/index.html"><img class="rust-logo" src="../../static.files/rust-logo-151179464ae7ed46.svg" alt="logo"></a><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="example-wrap"><div data-nosnippet><pre class="src-line-numbers"><a href="#1" id="1">1</a>
<a href="#2" id="2">2</a>
<a href="#3" id="3">3</a>
<a href="#4" id="4">4</a>
<a href="#5" id="5">5</a>
<a href="#6" id="6">6</a>
<a href="#7" id="7">7</a>
<a href="#8" id="8">8</a>
<a href="#9" id="9">9</a>
</pre></div><pre class="rust"><code><span class="attr">#![no_std]
#[cfg(reexport_core)]
</span><span class="kw">pub use </span>core::sync::atomic::<span class="kw-2">*</span>;
<span class="attr">#[cfg(not(reexport_core))]
</span><span class="kw">mod </span>polyfill;
<span class="attr">#[cfg(not(reexport_core))]
</span><span class="kw">pub use </span>polyfill::<span class="kw-2">*</span>;
</code></pre></div></section></main></body></html>

File diff suppressed because it is too large Load diff

View file

@ -1,579 +0,0 @@
<!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="Source of the Rust file `/home/zenn/.cargo/registry/src/index.crates.io-6f17d22bba15001f/critical-section-1.1.2/src/lib.rs`."><title>lib.rs - source</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-47e7ab555ef2818a.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="critical_section" data-themes="" data-resource-suffix="" data-rustdoc-version="1.74.0-nightly (d9c8274fb 2023-09-12)" data-channel="nightly" data-search-js="search-5d3eaacf19ebf04f.js" data-settings-js="settings-74424d7eec62a23e.js" data-settings-css="settings-8c76f75bfb6bd192.css" data-theme-light-css="light-f194925aa375ae96.css" data-theme-dark-css="dark-1dd4d1ce031e15de.css" data-theme-ayu-css="ayu-49e58d069f567085.css" ><script src="../../static.files/storage-db41da1a38ea3cb8.js"></script><script defer src="../../static.files/src-script-3280b574d94e47b4.js"></script><script defer src="../../src-files.js"></script><script defer src="../../static.files/main-8d035c8cea6edbc4.js"></script><noscript><link rel="stylesheet" media="(prefers-color-scheme:light)" href="../../static.files/light-f194925aa375ae96.css"><link rel="stylesheet" media="(prefers-color-scheme:dark)" href="../../static.files/dark-1dd4d1ce031e15de.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 src"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"></nav><main><nav class="sub"><a class="sub-logo-container" href="../../critical_section/index.html"><img class="rust-logo" src="../../static.files/rust-logo-151179464ae7ed46.svg" alt="logo"></a><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="example-wrap"><div data-nosnippet><pre class="src-line-numbers"><a href="#1" id="1">1</a>
<a href="#2" id="2">2</a>
<a href="#3" id="3">3</a>
<a href="#4" id="4">4</a>
<a href="#5" id="5">5</a>
<a href="#6" id="6">6</a>
<a href="#7" id="7">7</a>
<a href="#8" id="8">8</a>
<a href="#9" id="9">9</a>
<a href="#10" id="10">10</a>
<a href="#11" id="11">11</a>
<a href="#12" id="12">12</a>
<a href="#13" id="13">13</a>
<a href="#14" id="14">14</a>
<a href="#15" id="15">15</a>
<a href="#16" id="16">16</a>
<a href="#17" id="17">17</a>
<a href="#18" id="18">18</a>
<a href="#19" id="19">19</a>
<a href="#20" id="20">20</a>
<a href="#21" id="21">21</a>
<a href="#22" id="22">22</a>
<a href="#23" id="23">23</a>
<a href="#24" id="24">24</a>
<a href="#25" id="25">25</a>
<a href="#26" id="26">26</a>
<a href="#27" id="27">27</a>
<a href="#28" id="28">28</a>
<a href="#29" id="29">29</a>
<a href="#30" id="30">30</a>
<a href="#31" id="31">31</a>
<a href="#32" id="32">32</a>
<a href="#33" id="33">33</a>
<a href="#34" id="34">34</a>
<a href="#35" id="35">35</a>
<a href="#36" id="36">36</a>
<a href="#37" id="37">37</a>
<a href="#38" id="38">38</a>
<a href="#39" id="39">39</a>
<a href="#40" id="40">40</a>
<a href="#41" id="41">41</a>
<a href="#42" id="42">42</a>
<a href="#43" id="43">43</a>
<a href="#44" id="44">44</a>
<a href="#45" id="45">45</a>
<a href="#46" id="46">46</a>
<a href="#47" id="47">47</a>
<a href="#48" id="48">48</a>
<a href="#49" id="49">49</a>
<a href="#50" id="50">50</a>
<a href="#51" id="51">51</a>
<a href="#52" id="52">52</a>
<a href="#53" id="53">53</a>
<a href="#54" id="54">54</a>
<a href="#55" id="55">55</a>
<a href="#56" id="56">56</a>
<a href="#57" id="57">57</a>
<a href="#58" id="58">58</a>
<a href="#59" id="59">59</a>
<a href="#60" id="60">60</a>
<a href="#61" id="61">61</a>
<a href="#62" id="62">62</a>
<a href="#63" id="63">63</a>
<a href="#64" id="64">64</a>
<a href="#65" id="65">65</a>
<a href="#66" id="66">66</a>
<a href="#67" id="67">67</a>
<a href="#68" id="68">68</a>
<a href="#69" id="69">69</a>
<a href="#70" id="70">70</a>
<a href="#71" id="71">71</a>
<a href="#72" id="72">72</a>
<a href="#73" id="73">73</a>
<a href="#74" id="74">74</a>
<a href="#75" id="75">75</a>
<a href="#76" id="76">76</a>
<a href="#77" id="77">77</a>
<a href="#78" id="78">78</a>
<a href="#79" id="79">79</a>
<a href="#80" id="80">80</a>
<a href="#81" id="81">81</a>
<a href="#82" id="82">82</a>
<a href="#83" id="83">83</a>
<a href="#84" id="84">84</a>
<a href="#85" id="85">85</a>
<a href="#86" id="86">86</a>
<a href="#87" id="87">87</a>
<a href="#88" id="88">88</a>
<a href="#89" id="89">89</a>
<a href="#90" id="90">90</a>
<a href="#91" id="91">91</a>
<a href="#92" id="92">92</a>
<a href="#93" id="93">93</a>
<a href="#94" id="94">94</a>
<a href="#95" id="95">95</a>
<a href="#96" id="96">96</a>
<a href="#97" id="97">97</a>
<a href="#98" id="98">98</a>
<a href="#99" id="99">99</a>
<a href="#100" id="100">100</a>
<a href="#101" id="101">101</a>
<a href="#102" id="102">102</a>
<a href="#103" id="103">103</a>
<a href="#104" id="104">104</a>
<a href="#105" id="105">105</a>
<a href="#106" id="106">106</a>
<a href="#107" id="107">107</a>
<a href="#108" id="108">108</a>
<a href="#109" id="109">109</a>
<a href="#110" id="110">110</a>
<a href="#111" id="111">111</a>
<a href="#112" id="112">112</a>
<a href="#113" id="113">113</a>
<a href="#114" id="114">114</a>
<a href="#115" id="115">115</a>
<a href="#116" id="116">116</a>
<a href="#117" id="117">117</a>
<a href="#118" id="118">118</a>
<a href="#119" id="119">119</a>
<a href="#120" id="120">120</a>
<a href="#121" id="121">121</a>
<a href="#122" id="122">122</a>
<a href="#123" id="123">123</a>
<a href="#124" id="124">124</a>
<a href="#125" id="125">125</a>
<a href="#126" id="126">126</a>
<a href="#127" id="127">127</a>
<a href="#128" id="128">128</a>
<a href="#129" id="129">129</a>
<a href="#130" id="130">130</a>
<a href="#131" id="131">131</a>
<a href="#132" id="132">132</a>
<a href="#133" id="133">133</a>
<a href="#134" id="134">134</a>
<a href="#135" id="135">135</a>
<a href="#136" id="136">136</a>
<a href="#137" id="137">137</a>
<a href="#138" id="138">138</a>
<a href="#139" id="139">139</a>
<a href="#140" id="140">140</a>
<a href="#141" id="141">141</a>
<a href="#142" id="142">142</a>
<a href="#143" id="143">143</a>
<a href="#144" id="144">144</a>
<a href="#145" id="145">145</a>
<a href="#146" id="146">146</a>
<a href="#147" id="147">147</a>
<a href="#148" id="148">148</a>
<a href="#149" id="149">149</a>
<a href="#150" id="150">150</a>
<a href="#151" id="151">151</a>
<a href="#152" id="152">152</a>
<a href="#153" id="153">153</a>
<a href="#154" id="154">154</a>
<a href="#155" id="155">155</a>
<a href="#156" id="156">156</a>
<a href="#157" id="157">157</a>
<a href="#158" id="158">158</a>
<a href="#159" id="159">159</a>
<a href="#160" id="160">160</a>
<a href="#161" id="161">161</a>
<a href="#162" id="162">162</a>
<a href="#163" id="163">163</a>
<a href="#164" id="164">164</a>
<a href="#165" id="165">165</a>
<a href="#166" id="166">166</a>
<a href="#167" id="167">167</a>
<a href="#168" id="168">168</a>
<a href="#169" id="169">169</a>
<a href="#170" id="170">170</a>
<a href="#171" id="171">171</a>
<a href="#172" id="172">172</a>
<a href="#173" id="173">173</a>
<a href="#174" id="174">174</a>
<a href="#175" id="175">175</a>
<a href="#176" id="176">176</a>
<a href="#177" id="177">177</a>
<a href="#178" id="178">178</a>
<a href="#179" id="179">179</a>
<a href="#180" id="180">180</a>
<a href="#181" id="181">181</a>
<a href="#182" id="182">182</a>
<a href="#183" id="183">183</a>
<a href="#184" id="184">184</a>
<a href="#185" id="185">185</a>
<a href="#186" id="186">186</a>
<a href="#187" id="187">187</a>
<a href="#188" id="188">188</a>
<a href="#189" id="189">189</a>
<a href="#190" id="190">190</a>
<a href="#191" id="191">191</a>
<a href="#192" id="192">192</a>
<a href="#193" id="193">193</a>
<a href="#194" id="194">194</a>
<a href="#195" id="195">195</a>
<a href="#196" id="196">196</a>
<a href="#197" id="197">197</a>
<a href="#198" id="198">198</a>
<a href="#199" id="199">199</a>
<a href="#200" id="200">200</a>
<a href="#201" id="201">201</a>
<a href="#202" id="202">202</a>
<a href="#203" id="203">203</a>
<a href="#204" id="204">204</a>
<a href="#205" id="205">205</a>
<a href="#206" id="206">206</a>
<a href="#207" id="207">207</a>
<a href="#208" id="208">208</a>
<a href="#209" id="209">209</a>
<a href="#210" id="210">210</a>
<a href="#211" id="211">211</a>
<a href="#212" id="212">212</a>
<a href="#213" id="213">213</a>
<a href="#214" id="214">214</a>
<a href="#215" id="215">215</a>
<a href="#216" id="216">216</a>
<a href="#217" id="217">217</a>
<a href="#218" id="218">218</a>
<a href="#219" id="219">219</a>
<a href="#220" id="220">220</a>
<a href="#221" id="221">221</a>
<a href="#222" id="222">222</a>
<a href="#223" id="223">223</a>
<a href="#224" id="224">224</a>
<a href="#225" id="225">225</a>
<a href="#226" id="226">226</a>
<a href="#227" id="227">227</a>
<a href="#228" id="228">228</a>
<a href="#229" id="229">229</a>
<a href="#230" id="230">230</a>
<a href="#231" id="231">231</a>
<a href="#232" id="232">232</a>
<a href="#233" id="233">233</a>
<a href="#234" id="234">234</a>
<a href="#235" id="235">235</a>
<a href="#236" id="236">236</a>
<a href="#237" id="237">237</a>
<a href="#238" id="238">238</a>
<a href="#239" id="239">239</a>
<a href="#240" id="240">240</a>
<a href="#241" id="241">241</a>
<a href="#242" id="242">242</a>
<a href="#243" id="243">243</a>
<a href="#244" id="244">244</a>
<a href="#245" id="245">245</a>
<a href="#246" id="246">246</a>
<a href="#247" id="247">247</a>
<a href="#248" id="248">248</a>
<a href="#249" id="249">249</a>
<a href="#250" id="250">250</a>
<a href="#251" id="251">251</a>
<a href="#252" id="252">252</a>
<a href="#253" id="253">253</a>
<a href="#254" id="254">254</a>
<a href="#255" id="255">255</a>
<a href="#256" id="256">256</a>
<a href="#257" id="257">257</a>
<a href="#258" id="258">258</a>
<a href="#259" id="259">259</a>
<a href="#260" id="260">260</a>
<a href="#261" id="261">261</a>
<a href="#262" id="262">262</a>
<a href="#263" id="263">263</a>
<a href="#264" id="264">264</a>
<a href="#265" id="265">265</a>
<a href="#266" id="266">266</a>
<a href="#267" id="267">267</a>
<a href="#268" id="268">268</a>
<a href="#269" id="269">269</a>
<a href="#270" id="270">270</a>
<a href="#271" id="271">271</a>
<a href="#272" id="272">272</a>
<a href="#273" id="273">273</a>
<a href="#274" id="274">274</a>
<a href="#275" id="275">275</a>
<a href="#276" id="276">276</a>
<a href="#277" id="277">277</a>
<a href="#278" id="278">278</a>
<a href="#279" id="279">279</a>
<a href="#280" id="280">280</a>
<a href="#281" id="281">281</a>
<a href="#282" id="282">282</a>
<a href="#283" id="283">283</a>
<a href="#284" id="284">284</a>
<a href="#285" id="285">285</a>
<a href="#286" id="286">286</a>
<a href="#287" id="287">287</a>
<a href="#288" id="288">288</a>
<a href="#289" id="289">289</a>
</pre></div><pre class="rust"><code><span class="attr">#![cfg_attr(not(feature = <span class="string">&quot;std&quot;</span>), no_std)]
#![doc = <span class="macro">include_str!</span>(<span class="string">&quot;../README.md&quot;</span>)]
</span><span class="kw">mod </span>mutex;
<span class="attr">#[cfg(feature = <span class="string">&quot;std&quot;</span>)]
</span><span class="kw">mod </span>std;
<span class="kw">use </span>core::marker::PhantomData;
<span class="kw">pub use </span><span class="self">self</span>::mutex::Mutex;
<span class="doccomment">/// Critical section token.
///
/// An instance of this type indicates that the current thread is executing code within a critical
/// section.
</span><span class="attr">#[derive(Clone, Copy, Debug)]
</span><span class="kw">pub struct </span>CriticalSection&lt;<span class="lifetime">&#39;cs</span>&gt; {
_private: PhantomData&lt;<span class="kw-2">&amp;</span><span class="lifetime">&#39;cs </span>()&gt;,
}
<span class="kw">impl</span>&lt;<span class="lifetime">&#39;cs</span>&gt; CriticalSection&lt;<span class="lifetime">&#39;cs</span>&gt; {
<span class="doccomment">/// Creates a critical section token.
///
/// This method is meant to be used to create safe abstractions rather than being directly used
/// in applications.
///
/// # Safety
///
/// This must only be called when the current thread is in a critical section. The caller must
/// ensure that the returned instance will not live beyond the end of the critical section.
///
/// The caller must use adequate fences to prevent the compiler from moving the
/// instructions inside the critical section to the outside of it. Sequentially consistent fences are
/// suggested immediately after entry and immediately before exit from the critical section.
///
/// Note that the lifetime `&#39;cs` of the returned instance is unconstrained. User code must not
/// be able to influence the lifetime picked for this type, since that might cause it to be
/// inferred to `&#39;static`.
</span><span class="attr">#[inline(always)]
</span><span class="kw">pub unsafe fn </span>new() -&gt; <span class="self">Self </span>{
CriticalSection {
_private: PhantomData,
}
}
}
<span class="attr">#[cfg(any(
all(feature = <span class="string">&quot;restore-state-none&quot;</span>, feature = <span class="string">&quot;restore-state-bool&quot;</span>),
all(feature = <span class="string">&quot;restore-state-none&quot;</span>, feature = <span class="string">&quot;restore-state-u8&quot;</span>),
all(feature = <span class="string">&quot;restore-state-none&quot;</span>, feature = <span class="string">&quot;restore-state-u16&quot;</span>),
all(feature = <span class="string">&quot;restore-state-none&quot;</span>, feature = <span class="string">&quot;restore-state-u32&quot;</span>),
all(feature = <span class="string">&quot;restore-state-none&quot;</span>, feature = <span class="string">&quot;restore-state-u64&quot;</span>),
all(feature = <span class="string">&quot;restore-state-bool&quot;</span>, feature = <span class="string">&quot;restore-state-u8&quot;</span>),
all(feature = <span class="string">&quot;restore-state-bool&quot;</span>, feature = <span class="string">&quot;restore-state-u16&quot;</span>),
all(feature = <span class="string">&quot;restore-state-bool&quot;</span>, feature = <span class="string">&quot;restore-state-u32&quot;</span>),
all(feature = <span class="string">&quot;restore-state-bool&quot;</span>, feature = <span class="string">&quot;restore-state-u64&quot;</span>),
all(feature = <span class="string">&quot;restore-state-u8&quot;</span>, feature = <span class="string">&quot;restore-state-u16&quot;</span>),
all(feature = <span class="string">&quot;restore-state-u8&quot;</span>, feature = <span class="string">&quot;restore-state-u32&quot;</span>),
all(feature = <span class="string">&quot;restore-state-u8&quot;</span>, feature = <span class="string">&quot;restore-state-u64&quot;</span>),
all(feature = <span class="string">&quot;restore-state-u16&quot;</span>, feature = <span class="string">&quot;restore-state-u32&quot;</span>),
all(feature = <span class="string">&quot;restore-state-u16&quot;</span>, feature = <span class="string">&quot;restore-state-u64&quot;</span>),
all(feature = <span class="string">&quot;restore-state-u32&quot;</span>, feature = <span class="string">&quot;restore-state-u64&quot;</span>),
))]
</span><span class="macro">compile_error!</span>(<span class="string">&quot;You must set at most one of these Cargo features: restore-state-none, restore-state-bool, restore-state-u8, restore-state-u16, restore-state-u32, restore-state-u64&quot;</span>);
<span class="attr">#[cfg(not(any(
feature = <span class="string">&quot;restore-state-bool&quot;</span>,
feature = <span class="string">&quot;restore-state-u8&quot;</span>,
feature = <span class="string">&quot;restore-state-u16&quot;</span>,
feature = <span class="string">&quot;restore-state-u32&quot;</span>,
feature = <span class="string">&quot;restore-state-u64&quot;
</span>)))]
</span><span class="kw">type </span>RawRestoreStateInner = ();
<span class="attr">#[cfg(feature = <span class="string">&quot;restore-state-bool&quot;</span>)]
</span><span class="kw">type </span>RawRestoreStateInner = bool;
<span class="attr">#[cfg(feature = <span class="string">&quot;restore-state-u8&quot;</span>)]
</span><span class="kw">type </span>RawRestoreStateInner = u8;
<span class="attr">#[cfg(feature = <span class="string">&quot;restore-state-u16&quot;</span>)]
</span><span class="kw">type </span>RawRestoreStateInner = u16;
<span class="attr">#[cfg(feature = <span class="string">&quot;restore-state-u32&quot;</span>)]
</span><span class="kw">type </span>RawRestoreStateInner = u32;
<span class="attr">#[cfg(feature = <span class="string">&quot;restore-state-u64&quot;</span>)]
</span><span class="kw">type </span>RawRestoreStateInner = u64;
<span class="comment">// We have RawRestoreStateInner and RawRestoreState so that we don&#39;t have to copypaste the docs 5 times.
// In the docs this shows as `pub type RawRestoreState = u8` or whatever the selected type is, because
// the &quot;inner&quot; type alias is private.
</span><span class="doccomment">/// Raw, transparent &quot;restore state&quot;.
///
/// This type changes based on which Cargo feature is selected, out of
/// - `restore-state-none` (default, makes the type be `()`)
/// - `restore-state-bool`
/// - `restore-state-u8`
/// - `restore-state-u16`
/// - `restore-state-u32`
/// - `restore-state-u64`
///
/// See [`RestoreState`].
///
/// User code uses [`RestoreState`] opaquely, critical section implementations
/// use [`RawRestoreState`] so that they can use the inner value.
</span><span class="kw">pub type </span>RawRestoreState = RawRestoreStateInner;
<span class="doccomment">/// Opaque &quot;restore state&quot;.
///
/// Implementations use this to &quot;carry over&quot; information between acquiring and releasing
/// a critical section. For example, when nesting two critical sections of an
/// implementation that disables interrupts globally, acquiring the inner one won&#39;t disable
/// the interrupts since they&#39;re already disabled. The impl would use the restore state to &quot;tell&quot;
/// the corresponding release that it does *not* have to reenable interrupts yet, only the
/// outer release should do so.
///
/// User code uses [`RestoreState`] opaquely, critical section implementations
/// use [`RawRestoreState`] so that they can use the inner value.
</span><span class="attr">#[derive(Clone, Copy, Debug)]
</span><span class="kw">pub struct </span>RestoreState(RawRestoreState);
<span class="kw">impl </span>RestoreState {
<span class="doccomment">/// Create an invalid, dummy `RestoreState`.
///
/// This can be useful to avoid `Option` when storing a `RestoreState` in a
/// struct field, or a `static`.
///
/// Note that due to the safety contract of [`acquire`]/[`release`], you must not pass
/// a `RestoreState` obtained from this method to [`release`].
</span><span class="kw">pub const fn </span>invalid() -&gt; <span class="self">Self </span>{
<span class="attr">#[cfg(not(any(
feature = <span class="string">&quot;restore-state-bool&quot;</span>,
feature = <span class="string">&quot;restore-state-u8&quot;</span>,
feature = <span class="string">&quot;restore-state-u16&quot;</span>,
feature = <span class="string">&quot;restore-state-u32&quot;</span>,
feature = <span class="string">&quot;restore-state-u64&quot;
</span>)))]
</span><span class="kw">return </span><span class="self">Self</span>(());
<span class="attr">#[cfg(feature = <span class="string">&quot;restore-state-bool&quot;</span>)]
</span><span class="kw">return </span><span class="self">Self</span>(<span class="bool-val">false</span>);
<span class="attr">#[cfg(feature = <span class="string">&quot;restore-state-u8&quot;</span>)]
</span><span class="kw">return </span><span class="self">Self</span>(<span class="number">0</span>);
<span class="attr">#[cfg(feature = <span class="string">&quot;restore-state-u16&quot;</span>)]
</span><span class="kw">return </span><span class="self">Self</span>(<span class="number">0</span>);
<span class="attr">#[cfg(feature = <span class="string">&quot;restore-state-u32&quot;</span>)]
</span><span class="kw">return </span><span class="self">Self</span>(<span class="number">0</span>);
<span class="attr">#[cfg(feature = <span class="string">&quot;restore-state-u64&quot;</span>)]
</span><span class="kw">return </span><span class="self">Self</span>(<span class="number">0</span>);
}
}
<span class="doccomment">/// Acquire a critical section in the current thread.
///
/// This function is extremely low level. Strongly prefer using [`with`] instead.
///
/// Nesting critical sections is allowed. The inner critical sections
/// are mostly no-ops since they&#39;re already protected by the outer one.
///
/// # Safety
///
/// - Each `acquire` call must be paired with exactly one `release` call in the same thread.
/// - `acquire` returns a &quot;restore state&quot; that you must pass to the corresponding `release` call.
/// - `acquire`/`release` pairs must be &quot;properly nested&quot;, ie it&#39;s not OK to do `a=acquire(); b=acquire(); release(a); release(b);`.
/// - It is UB to call `release` if the critical section is not acquired in the current thread.
/// - It is UB to call `release` with a &quot;restore state&quot; that does not come from the corresponding `acquire` call.
/// - It must provide ordering guarantees at least equivalent to a [`core::sync::atomic::Ordering::Acquire`]
/// on a memory location shared by all critical sections, on which the `release` call will do a
/// [`core::sync::atomic::Ordering::Release`] operation.
</span><span class="attr">#[inline(always)]
</span><span class="kw">pub unsafe fn </span>acquire() -&gt; RestoreState {
<span class="kw">extern </span><span class="string">&quot;Rust&quot; </span>{
<span class="kw">fn </span>_critical_section_1_0_acquire() -&gt; RawRestoreState;
}
<span class="attr">#[allow(clippy::unit_arg)]
</span>RestoreState(_critical_section_1_0_acquire())
}
<span class="doccomment">/// Release the critical section.
///
/// This function is extremely low level. Strongly prefer using [`with`] instead.
///
/// # Safety
///
/// See [`acquire`] for the safety contract description.
</span><span class="attr">#[inline(always)]
</span><span class="kw">pub unsafe fn </span>release(restore_state: RestoreState) {
<span class="kw">extern </span><span class="string">&quot;Rust&quot; </span>{
<span class="kw">fn </span>_critical_section_1_0_release(restore_state: RawRestoreState);
}
<span class="attr">#[allow(clippy::unit_arg)]
</span>_critical_section_1_0_release(restore_state.<span class="number">0</span>)
}
<span class="doccomment">/// Execute closure `f` in a critical section.
///
/// Nesting critical sections is allowed. The inner critical sections
/// are mostly no-ops since they&#39;re already protected by the outer one.
///
/// # Panics
///
/// This function panics if the given closure `f` panics. In this case
/// the critical section is released before unwinding.
</span><span class="attr">#[inline]
</span><span class="kw">pub fn </span>with&lt;R&gt;(f: <span class="kw">impl </span>FnOnce(CriticalSection) -&gt; R) -&gt; R {
<span class="comment">// Helper for making sure `release` is called even if `f` panics.
</span><span class="kw">struct </span>Guard {
state: RestoreState,
}
<span class="kw">impl </span>Drop <span class="kw">for </span>Guard {
<span class="attr">#[inline(always)]
</span><span class="kw">fn </span>drop(<span class="kw-2">&amp;mut </span><span class="self">self</span>) {
<span class="kw">unsafe </span>{ release(<span class="self">self</span>.state) }
}
}
<span class="kw">let </span>state = <span class="kw">unsafe </span>{ acquire() };
<span class="kw">let </span>_guard = Guard { state };
<span class="kw">unsafe </span>{ f(CriticalSection::new()) }
}
<span class="doccomment">/// Methods required for a critical section implementation.
///
/// This trait is not intended to be used except when implementing a critical section.
///
/// # Safety
///
/// Implementations must uphold the contract specified in [`crate::acquire`] and [`crate::release`].
</span><span class="kw">pub unsafe trait </span>Impl {
<span class="doccomment">/// Acquire the critical section.
///
/// # Safety
///
/// Callers must uphold the contract specified in [`crate::acquire`] and [`crate::release`].
</span><span class="kw">unsafe fn </span>acquire() -&gt; RawRestoreState;
<span class="doccomment">/// Release the critical section.
///
/// # Safety
///
/// Callers must uphold the contract specified in [`crate::acquire`] and [`crate::release`].
</span><span class="kw">unsafe fn </span>release(restore_state: RawRestoreState);
}
<span class="doccomment">/// Set the critical section implementation.
///
/// # Example
///
/// ```
/// # #[cfg(not(feature = &quot;std&quot;))] // needed for `cargo test --features std`
/// # mod no_std {
/// use critical_section::RawRestoreState;
///
/// struct MyCriticalSection;
/// critical_section::set_impl!(MyCriticalSection);
///
/// unsafe impl critical_section::Impl for MyCriticalSection {
/// unsafe fn acquire() -&gt; RawRestoreState {
/// // ...
/// }
///
/// unsafe fn release(restore_state: RawRestoreState) {
/// // ...
/// }
/// }
/// # }
</span><span class="attr">#[macro_export]
</span><span class="macro">macro_rules! </span>set_impl {
(<span class="macro-nonterminal">$t</span>: ty) =&gt; {
<span class="attr">#[no_mangle]
</span><span class="kw">unsafe fn </span>_critical_section_1_0_acquire() -&gt; <span class="macro-nonterminal">$crate::RawRestoreState </span>{
&lt;<span class="macro-nonterminal">$t </span><span class="kw">as </span><span class="macro-nonterminal">$crate::Impl</span>&gt;::acquire()
}
<span class="attr">#[no_mangle]
</span><span class="kw">unsafe fn </span>_critical_section_1_0_release(restore_state: <span class="macro-nonterminal">$crate::RawRestoreState</span>) {
&lt;<span class="macro-nonterminal">$t </span><span class="kw">as </span><span class="macro-nonterminal">$crate::Impl</span>&gt;::release(restore_state)
}
};
}
</code></pre></div></section></main></body></html>

View file

@ -1,401 +0,0 @@
<!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="Source of the Rust file `/home/zenn/.cargo/registry/src/index.crates.io-6f17d22bba15001f/critical-section-1.1.2/src/mutex.rs`."><title>mutex.rs - source</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-47e7ab555ef2818a.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="critical_section" data-themes="" data-resource-suffix="" data-rustdoc-version="1.74.0-nightly (d9c8274fb 2023-09-12)" data-channel="nightly" data-search-js="search-5d3eaacf19ebf04f.js" data-settings-js="settings-74424d7eec62a23e.js" data-settings-css="settings-8c76f75bfb6bd192.css" data-theme-light-css="light-f194925aa375ae96.css" data-theme-dark-css="dark-1dd4d1ce031e15de.css" data-theme-ayu-css="ayu-49e58d069f567085.css" ><script src="../../static.files/storage-db41da1a38ea3cb8.js"></script><script defer src="../../static.files/src-script-3280b574d94e47b4.js"></script><script defer src="../../src-files.js"></script><script defer src="../../static.files/main-8d035c8cea6edbc4.js"></script><noscript><link rel="stylesheet" media="(prefers-color-scheme:light)" href="../../static.files/light-f194925aa375ae96.css"><link rel="stylesheet" media="(prefers-color-scheme:dark)" href="../../static.files/dark-1dd4d1ce031e15de.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 src"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"></nav><main><nav class="sub"><a class="sub-logo-container" href="../../critical_section/index.html"><img class="rust-logo" src="../../static.files/rust-logo-151179464ae7ed46.svg" alt="logo"></a><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="example-wrap"><div data-nosnippet><pre class="src-line-numbers"><a href="#1" id="1">1</a>
<a href="#2" id="2">2</a>
<a href="#3" id="3">3</a>
<a href="#4" id="4">4</a>
<a href="#5" id="5">5</a>
<a href="#6" id="6">6</a>
<a href="#7" id="7">7</a>
<a href="#8" id="8">8</a>
<a href="#9" id="9">9</a>
<a href="#10" id="10">10</a>
<a href="#11" id="11">11</a>
<a href="#12" id="12">12</a>
<a href="#13" id="13">13</a>
<a href="#14" id="14">14</a>
<a href="#15" id="15">15</a>
<a href="#16" id="16">16</a>
<a href="#17" id="17">17</a>
<a href="#18" id="18">18</a>
<a href="#19" id="19">19</a>
<a href="#20" id="20">20</a>
<a href="#21" id="21">21</a>
<a href="#22" id="22">22</a>
<a href="#23" id="23">23</a>
<a href="#24" id="24">24</a>
<a href="#25" id="25">25</a>
<a href="#26" id="26">26</a>
<a href="#27" id="27">27</a>
<a href="#28" id="28">28</a>
<a href="#29" id="29">29</a>
<a href="#30" id="30">30</a>
<a href="#31" id="31">31</a>
<a href="#32" id="32">32</a>
<a href="#33" id="33">33</a>
<a href="#34" id="34">34</a>
<a href="#35" id="35">35</a>
<a href="#36" id="36">36</a>
<a href="#37" id="37">37</a>
<a href="#38" id="38">38</a>
<a href="#39" id="39">39</a>
<a href="#40" id="40">40</a>
<a href="#41" id="41">41</a>
<a href="#42" id="42">42</a>
<a href="#43" id="43">43</a>
<a href="#44" id="44">44</a>
<a href="#45" id="45">45</a>
<a href="#46" id="46">46</a>
<a href="#47" id="47">47</a>
<a href="#48" id="48">48</a>
<a href="#49" id="49">49</a>
<a href="#50" id="50">50</a>
<a href="#51" id="51">51</a>
<a href="#52" id="52">52</a>
<a href="#53" id="53">53</a>
<a href="#54" id="54">54</a>
<a href="#55" id="55">55</a>
<a href="#56" id="56">56</a>
<a href="#57" id="57">57</a>
<a href="#58" id="58">58</a>
<a href="#59" id="59">59</a>
<a href="#60" id="60">60</a>
<a href="#61" id="61">61</a>
<a href="#62" id="62">62</a>
<a href="#63" id="63">63</a>
<a href="#64" id="64">64</a>
<a href="#65" id="65">65</a>
<a href="#66" id="66">66</a>
<a href="#67" id="67">67</a>
<a href="#68" id="68">68</a>
<a href="#69" id="69">69</a>
<a href="#70" id="70">70</a>
<a href="#71" id="71">71</a>
<a href="#72" id="72">72</a>
<a href="#73" id="73">73</a>
<a href="#74" id="74">74</a>
<a href="#75" id="75">75</a>
<a href="#76" id="76">76</a>
<a href="#77" id="77">77</a>
<a href="#78" id="78">78</a>
<a href="#79" id="79">79</a>
<a href="#80" id="80">80</a>
<a href="#81" id="81">81</a>
<a href="#82" id="82">82</a>
<a href="#83" id="83">83</a>
<a href="#84" id="84">84</a>
<a href="#85" id="85">85</a>
<a href="#86" id="86">86</a>
<a href="#87" id="87">87</a>
<a href="#88" id="88">88</a>
<a href="#89" id="89">89</a>
<a href="#90" id="90">90</a>
<a href="#91" id="91">91</a>
<a href="#92" id="92">92</a>
<a href="#93" id="93">93</a>
<a href="#94" id="94">94</a>
<a href="#95" id="95">95</a>
<a href="#96" id="96">96</a>
<a href="#97" id="97">97</a>
<a href="#98" id="98">98</a>
<a href="#99" id="99">99</a>
<a href="#100" id="100">100</a>
<a href="#101" id="101">101</a>
<a href="#102" id="102">102</a>
<a href="#103" id="103">103</a>
<a href="#104" id="104">104</a>
<a href="#105" id="105">105</a>
<a href="#106" id="106">106</a>
<a href="#107" id="107">107</a>
<a href="#108" id="108">108</a>
<a href="#109" id="109">109</a>
<a href="#110" id="110">110</a>
<a href="#111" id="111">111</a>
<a href="#112" id="112">112</a>
<a href="#113" id="113">113</a>
<a href="#114" id="114">114</a>
<a href="#115" id="115">115</a>
<a href="#116" id="116">116</a>
<a href="#117" id="117">117</a>
<a href="#118" id="118">118</a>
<a href="#119" id="119">119</a>
<a href="#120" id="120">120</a>
<a href="#121" id="121">121</a>
<a href="#122" id="122">122</a>
<a href="#123" id="123">123</a>
<a href="#124" id="124">124</a>
<a href="#125" id="125">125</a>
<a href="#126" id="126">126</a>
<a href="#127" id="127">127</a>
<a href="#128" id="128">128</a>
<a href="#129" id="129">129</a>
<a href="#130" id="130">130</a>
<a href="#131" id="131">131</a>
<a href="#132" id="132">132</a>
<a href="#133" id="133">133</a>
<a href="#134" id="134">134</a>
<a href="#135" id="135">135</a>
<a href="#136" id="136">136</a>
<a href="#137" id="137">137</a>
<a href="#138" id="138">138</a>
<a href="#139" id="139">139</a>
<a href="#140" id="140">140</a>
<a href="#141" id="141">141</a>
<a href="#142" id="142">142</a>
<a href="#143" id="143">143</a>
<a href="#144" id="144">144</a>
<a href="#145" id="145">145</a>
<a href="#146" id="146">146</a>
<a href="#147" id="147">147</a>
<a href="#148" id="148">148</a>
<a href="#149" id="149">149</a>
<a href="#150" id="150">150</a>
<a href="#151" id="151">151</a>
<a href="#152" id="152">152</a>
<a href="#153" id="153">153</a>
<a href="#154" id="154">154</a>
<a href="#155" id="155">155</a>
<a href="#156" id="156">156</a>
<a href="#157" id="157">157</a>
<a href="#158" id="158">158</a>
<a href="#159" id="159">159</a>
<a href="#160" id="160">160</a>
<a href="#161" id="161">161</a>
<a href="#162" id="162">162</a>
<a href="#163" id="163">163</a>
<a href="#164" id="164">164</a>
<a href="#165" id="165">165</a>
<a href="#166" id="166">166</a>
<a href="#167" id="167">167</a>
<a href="#168" id="168">168</a>
<a href="#169" id="169">169</a>
<a href="#170" id="170">170</a>
<a href="#171" id="171">171</a>
<a href="#172" id="172">172</a>
<a href="#173" id="173">173</a>
<a href="#174" id="174">174</a>
<a href="#175" id="175">175</a>
<a href="#176" id="176">176</a>
<a href="#177" id="177">177</a>
<a href="#178" id="178">178</a>
<a href="#179" id="179">179</a>
<a href="#180" id="180">180</a>
<a href="#181" id="181">181</a>
<a href="#182" id="182">182</a>
<a href="#183" id="183">183</a>
<a href="#184" id="184">184</a>
<a href="#185" id="185">185</a>
<a href="#186" id="186">186</a>
<a href="#187" id="187">187</a>
<a href="#188" id="188">188</a>
<a href="#189" id="189">189</a>
<a href="#190" id="190">190</a>
<a href="#191" id="191">191</a>
<a href="#192" id="192">192</a>
<a href="#193" id="193">193</a>
<a href="#194" id="194">194</a>
<a href="#195" id="195">195</a>
<a href="#196" id="196">196</a>
<a href="#197" id="197">197</a>
<a href="#198" id="198">198</a>
<a href="#199" id="199">199</a>
<a href="#200" id="200">200</a>
</pre></div><pre class="rust"><code><span class="kw">use </span><span class="kw">super</span>::CriticalSection;
<span class="kw">use </span>core::cell::{Ref, RefCell, RefMut, UnsafeCell};
<span class="doccomment">/// A mutex based on critical sections.
///
/// # Example
///
/// ```no_run
/// # use critical_section::Mutex;
/// # use std::cell::Cell;
///
/// static FOO: Mutex&lt;Cell&lt;i32&gt;&gt; = Mutex::new(Cell::new(42));
///
/// fn main() {
/// critical_section::with(|cs| {
/// FOO.borrow(cs).set(43);
/// });
/// }
///
/// fn interrupt_handler() {
/// let _x = critical_section::with(|cs| FOO.borrow(cs).get());
/// }
/// ```
///
///
/// # Design
///
/// [`std::sync::Mutex`] has two purposes. It converts types that are [`Send`]
/// but not [`Sync`] into types that are both; and it provides
/// [interior mutability]. `critical_section::Mutex`, on the other hand, only adds
/// `Sync`. It does *not* provide interior mutability.
///
/// This was a conscious design choice. It is possible to create multiple
/// [`CriticalSection`] tokens, either by nesting critical sections or `Copy`ing
/// an existing token. As a result, it would not be sound for [`Mutex::borrow`]
/// to return `&amp;mut T`, because there would be nothing to prevent calling
/// `borrow` multiple times to create aliased `&amp;mut T` references.
///
/// The solution is to include a runtime check to ensure that each resource is
/// borrowed only once. This is what `std::sync::Mutex` does. However, this is
/// a runtime cost that may not be required in all circumstances. For instance,
/// `Mutex&lt;Cell&lt;T&gt;&gt;` never needs to create `&amp;mut T` or equivalent.
///
/// If `&amp;mut T` is needed, the simplest solution is to use `Mutex&lt;RefCell&lt;T&gt;&gt;`,
/// which is the closest analogy to `std::sync::Mutex`. [`RefCell`] inserts the
/// exact runtime check necessary to guarantee that the `&amp;mut T` reference is
/// unique.
///
/// To reduce verbosity when using `Mutex&lt;RefCell&lt;T&gt;&gt;`, we reimplement some of
/// `RefCell`&#39;s methods on it directly.
///
/// ```no_run
/// # use critical_section::Mutex;
/// # use std::cell::RefCell;
///
/// static FOO: Mutex&lt;RefCell&lt;i32&gt;&gt; = Mutex::new(RefCell::new(42));
///
/// fn main() {
/// critical_section::with(|cs| {
/// // Instead of calling this
/// let _ = FOO.borrow(cs).take();
/// // Call this
/// let _ = FOO.take(cs);
/// // `RefCell::borrow` and `RefCell::borrow_mut` are renamed to
/// // `borrow_ref` and `borrow_ref_mut` to avoid name collisions
/// let _: &amp;mut i32 = &amp;mut *FOO.borrow_ref_mut(cs);
/// })
/// }
/// ```
///
/// [`std::sync::Mutex`]: https://doc.rust-lang.org/std/sync/struct.Mutex.html
/// [interior mutability]: https://doc.rust-lang.org/reference/interior-mutability.html
</span><span class="attr">#[derive(Debug)]
</span><span class="kw">pub struct </span>Mutex&lt;T&gt; {
inner: UnsafeCell&lt;T&gt;,
}
<span class="kw">impl</span>&lt;T&gt; Mutex&lt;T&gt; {
<span class="doccomment">/// Creates a new mutex.
</span><span class="attr">#[inline]
</span><span class="kw">pub const fn </span>new(value: T) -&gt; <span class="self">Self </span>{
Mutex {
inner: UnsafeCell::new(value),
}
}
<span class="doccomment">/// Gets a mutable reference to the contained value when the mutex is already uniquely borrowed.
///
/// This does not require locking or a critical section since it takes `&amp;mut self`, which
/// guarantees unique ownership already. Care must be taken when using this method to
/// **unsafely** access `static mut` variables, appropriate fences must be used to prevent
/// unwanted optimizations.
</span><span class="attr">#[inline]
</span><span class="kw">pub fn </span>get_mut(<span class="kw-2">&amp;mut </span><span class="self">self</span>) -&gt; <span class="kw-2">&amp;mut </span>T {
<span class="kw">unsafe </span>{ <span class="kw-2">&amp;mut *</span><span class="self">self</span>.inner.get() }
}
<span class="doccomment">/// Unwraps the contained value, consuming the mutex.
</span><span class="attr">#[inline]
</span><span class="kw">pub fn </span>into_inner(<span class="self">self</span>) -&gt; T {
<span class="self">self</span>.inner.into_inner()
}
<span class="doccomment">/// Borrows the data for the duration of the critical section.
</span><span class="attr">#[inline]
</span><span class="kw">pub fn </span>borrow&lt;<span class="lifetime">&#39;cs</span>&gt;(<span class="kw-2">&amp;</span><span class="lifetime">&#39;cs </span><span class="self">self</span>, _cs: CriticalSection&lt;<span class="lifetime">&#39;cs</span>&gt;) -&gt; <span class="kw-2">&amp;</span><span class="lifetime">&#39;cs </span>T {
<span class="kw">unsafe </span>{ <span class="kw-2">&amp;*</span><span class="self">self</span>.inner.get() }
}
}
<span class="kw">impl</span>&lt;T&gt; Mutex&lt;RefCell&lt;T&gt;&gt; {
<span class="doccomment">/// Borrow the data and call [`RefCell::replace`]
///
/// This is equivalent to `self.borrow(cs).replace(t)`
///
/// # Panics
///
/// This call could panic. See the documentation for [`RefCell::replace`]
/// for more details.
</span><span class="attr">#[inline]
#[track_caller]
</span><span class="kw">pub fn </span>replace&lt;<span class="lifetime">&#39;cs</span>&gt;(<span class="kw-2">&amp;</span><span class="lifetime">&#39;cs </span><span class="self">self</span>, cs: CriticalSection&lt;<span class="lifetime">&#39;cs</span>&gt;, t: T) -&gt; T {
<span class="self">self</span>.borrow(cs).replace(t)
}
<span class="doccomment">/// Borrow the data and call [`RefCell::replace_with`]
///
/// This is equivalent to `self.borrow(cs).replace_with(f)`
///
/// # Panics
///
/// This call could panic. See the documentation for
/// [`RefCell::replace_with`] for more details.
</span><span class="attr">#[inline]
#[track_caller]
</span><span class="kw">pub fn </span>replace_with&lt;<span class="lifetime">&#39;cs</span>, F&gt;(<span class="kw-2">&amp;</span><span class="lifetime">&#39;cs </span><span class="self">self</span>, cs: CriticalSection&lt;<span class="lifetime">&#39;cs</span>&gt;, f: F) -&gt; T
<span class="kw">where
</span>F: FnOnce(<span class="kw-2">&amp;mut </span>T) -&gt; T,
{
<span class="self">self</span>.borrow(cs).replace_with(f)
}
<span class="doccomment">/// Borrow the data and call [`RefCell::borrow`]
///
/// This is equivalent to `self.borrow(cs).borrow()`
///
/// # Panics
///
/// This call could panic. See the documentation for [`RefCell::borrow`]
/// for more details.
</span><span class="attr">#[inline]
#[track_caller]
</span><span class="kw">pub fn </span>borrow_ref&lt;<span class="lifetime">&#39;cs</span>&gt;(<span class="kw-2">&amp;</span><span class="lifetime">&#39;cs </span><span class="self">self</span>, cs: CriticalSection&lt;<span class="lifetime">&#39;cs</span>&gt;) -&gt; Ref&lt;<span class="lifetime">&#39;cs</span>, T&gt; {
<span class="self">self</span>.borrow(cs).borrow()
}
<span class="doccomment">/// Borrow the data and call [`RefCell::borrow_mut`]
///
/// This is equivalent to `self.borrow(cs).borrow_mut()`
///
/// # Panics
///
/// This call could panic. See the documentation for [`RefCell::borrow_mut`]
/// for more details.
</span><span class="attr">#[inline]
#[track_caller]
</span><span class="kw">pub fn </span>borrow_ref_mut&lt;<span class="lifetime">&#39;cs</span>&gt;(<span class="kw-2">&amp;</span><span class="lifetime">&#39;cs </span><span class="self">self</span>, cs: CriticalSection&lt;<span class="lifetime">&#39;cs</span>&gt;) -&gt; RefMut&lt;<span class="lifetime">&#39;cs</span>, T&gt; {
<span class="self">self</span>.borrow(cs).borrow_mut()
}
}
<span class="kw">impl</span>&lt;T: Default&gt; Mutex&lt;RefCell&lt;T&gt;&gt; {
<span class="doccomment">/// Borrow the data and call [`RefCell::take`]
///
/// This is equivalent to `self.borrow(cs).take()`
///
/// # Panics
///
/// This call could panic. See the documentation for [`RefCell::take`]
/// for more details.
</span><span class="attr">#[inline]
#[track_caller]
</span><span class="kw">pub fn </span>take&lt;<span class="lifetime">&#39;cs</span>&gt;(<span class="kw-2">&amp;</span><span class="lifetime">&#39;cs </span><span class="self">self</span>, cs: CriticalSection&lt;<span class="lifetime">&#39;cs</span>&gt;) -&gt; T {
<span class="self">self</span>.borrow(cs).take()
}
}
<span class="comment">// NOTE A `Mutex` can be used as a channel so the protected data must be `Send`
// to prevent sending non-Sendable stuff (e.g. access tokens) across different
// threads.
</span><span class="kw">unsafe impl</span>&lt;T&gt; Sync <span class="kw">for </span>Mutex&lt;T&gt; <span class="kw">where </span>T: Send {}
<span class="doccomment">/// ``` compile_fail
/// fn bad(cs: critical_section::CriticalSection) -&gt; &amp;u32 {
/// let x = critical_section::Mutex::new(42u32);
/// x.borrow(cs)
/// }
/// ```
</span><span class="attr">#[cfg(doctest)]
</span><span class="kw">const </span>BorrowMustNotOutliveMutexTest: () = ();
</code></pre></div></section></main></body></html>

View file

@ -1,57 +0,0 @@
<!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="Source of the Rust file `/home/zenn/.cargo/registry/src/index.crates.io-6f17d22bba15001f/hash32-0.2.1/src/fnv.rs`."><title>fnv.rs - source</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-47e7ab555ef2818a.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="hash32" data-themes="" data-resource-suffix="" data-rustdoc-version="1.74.0-nightly (d9c8274fb 2023-09-12)" data-channel="nightly" data-search-js="search-5d3eaacf19ebf04f.js" data-settings-js="settings-74424d7eec62a23e.js" data-settings-css="settings-8c76f75bfb6bd192.css" data-theme-light-css="light-f194925aa375ae96.css" data-theme-dark-css="dark-1dd4d1ce031e15de.css" data-theme-ayu-css="ayu-49e58d069f567085.css" ><script src="../../static.files/storage-db41da1a38ea3cb8.js"></script><script defer src="../../static.files/src-script-3280b574d94e47b4.js"></script><script defer src="../../src-files.js"></script><script defer src="../../static.files/main-8d035c8cea6edbc4.js"></script><noscript><link rel="stylesheet" media="(prefers-color-scheme:light)" href="../../static.files/light-f194925aa375ae96.css"><link rel="stylesheet" media="(prefers-color-scheme:dark)" href="../../static.files/dark-1dd4d1ce031e15de.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 src"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"></nav><main><nav class="sub"><a class="sub-logo-container" href="../../hash32/index.html"><img class="rust-logo" src="../../static.files/rust-logo-151179464ae7ed46.svg" alt="logo"></a><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="example-wrap"><div data-nosnippet><pre class="src-line-numbers"><a href="#1" id="1">1</a>
<a href="#2" id="2">2</a>
<a href="#3" id="3">3</a>
<a href="#4" id="4">4</a>
<a href="#5" id="5">5</a>
<a href="#6" id="6">6</a>
<a href="#7" id="7">7</a>
<a href="#8" id="8">8</a>
<a href="#9" id="9">9</a>
<a href="#10" id="10">10</a>
<a href="#11" id="11">11</a>
<a href="#12" id="12">12</a>
<a href="#13" id="13">13</a>
<a href="#14" id="14">14</a>
<a href="#15" id="15">15</a>
<a href="#16" id="16">16</a>
<a href="#17" id="17">17</a>
<a href="#18" id="18">18</a>
<a href="#19" id="19">19</a>
<a href="#20" id="20">20</a>
<a href="#21" id="21">21</a>
<a href="#22" id="22">22</a>
<a href="#23" id="23">23</a>
<a href="#24" id="24">24</a>
<a href="#25" id="25">25</a>
<a href="#26" id="26">26</a>
<a href="#27" id="27">27</a>
<a href="#28" id="28">28</a>
</pre></div><pre class="rust"><code><span class="kw">const </span>BASIS: u32 = <span class="number">0x811c9dc5</span>;
<span class="kw">const </span>PRIME: u32 = <span class="number">0x1000193</span>;
<span class="doccomment">/// 32-bit Fowler-Noll-Vo hasher
</span><span class="kw">pub struct </span>Hasher {
state: u32,
}
<span class="kw">impl </span>Default <span class="kw">for </span>Hasher {
<span class="kw">fn </span>default() -&gt; <span class="self">Self </span>{
Hasher { state: BASIS }
}
}
<span class="kw">impl </span>::Hasher <span class="kw">for </span>Hasher {
<span class="attr">#[inline]
</span><span class="kw">fn </span>finish(<span class="kw-2">&amp;</span><span class="self">self</span>) -&gt; u32 {
<span class="self">self</span>.state
}
<span class="attr">#[inline]
</span><span class="kw">fn </span>write(<span class="kw-2">&amp;mut </span><span class="self">self</span>, bytes: <span class="kw-2">&amp;</span>[u8]) {
<span class="kw">for </span>byte <span class="kw">in </span>bytes {
<span class="self">self</span>.state ^= u32::from(<span class="kw-2">*</span>byte);
<span class="self">self</span>.state = <span class="self">self</span>.state.wrapping_mul(PRIME);
}
}
}
</code></pre></div></section></main></body></html>

View file

@ -1,727 +0,0 @@
<!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="Source of the Rust file `/home/zenn/.cargo/registry/src/index.crates.io-6f17d22bba15001f/hash32-0.2.1/src/lib.rs`."><title>lib.rs - source</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-47e7ab555ef2818a.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="hash32" data-themes="" data-resource-suffix="" data-rustdoc-version="1.74.0-nightly (d9c8274fb 2023-09-12)" data-channel="nightly" data-search-js="search-5d3eaacf19ebf04f.js" data-settings-js="settings-74424d7eec62a23e.js" data-settings-css="settings-8c76f75bfb6bd192.css" data-theme-light-css="light-f194925aa375ae96.css" data-theme-dark-css="dark-1dd4d1ce031e15de.css" data-theme-ayu-css="ayu-49e58d069f567085.css" ><script src="../../static.files/storage-db41da1a38ea3cb8.js"></script><script defer src="../../static.files/src-script-3280b574d94e47b4.js"></script><script defer src="../../src-files.js"></script><script defer src="../../static.files/main-8d035c8cea6edbc4.js"></script><noscript><link rel="stylesheet" media="(prefers-color-scheme:light)" href="../../static.files/light-f194925aa375ae96.css"><link rel="stylesheet" media="(prefers-color-scheme:dark)" href="../../static.files/dark-1dd4d1ce031e15de.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 src"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"></nav><main><nav class="sub"><a class="sub-logo-container" href="../../hash32/index.html"><img class="rust-logo" src="../../static.files/rust-logo-151179464ae7ed46.svg" alt="logo"></a><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="example-wrap"><div data-nosnippet><pre class="src-line-numbers"><a href="#1" id="1">1</a>
<a href="#2" id="2">2</a>
<a href="#3" id="3">3</a>
<a href="#4" id="4">4</a>
<a href="#5" id="5">5</a>
<a href="#6" id="6">6</a>
<a href="#7" id="7">7</a>
<a href="#8" id="8">8</a>
<a href="#9" id="9">9</a>
<a href="#10" id="10">10</a>
<a href="#11" id="11">11</a>
<a href="#12" id="12">12</a>
<a href="#13" id="13">13</a>
<a href="#14" id="14">14</a>
<a href="#15" id="15">15</a>
<a href="#16" id="16">16</a>
<a href="#17" id="17">17</a>
<a href="#18" id="18">18</a>
<a href="#19" id="19">19</a>
<a href="#20" id="20">20</a>
<a href="#21" id="21">21</a>
<a href="#22" id="22">22</a>
<a href="#23" id="23">23</a>
<a href="#24" id="24">24</a>
<a href="#25" id="25">25</a>
<a href="#26" id="26">26</a>
<a href="#27" id="27">27</a>
<a href="#28" id="28">28</a>
<a href="#29" id="29">29</a>
<a href="#30" id="30">30</a>
<a href="#31" id="31">31</a>
<a href="#32" id="32">32</a>
<a href="#33" id="33">33</a>
<a href="#34" id="34">34</a>
<a href="#35" id="35">35</a>
<a href="#36" id="36">36</a>
<a href="#37" id="37">37</a>
<a href="#38" id="38">38</a>
<a href="#39" id="39">39</a>
<a href="#40" id="40">40</a>
<a href="#41" id="41">41</a>
<a href="#42" id="42">42</a>
<a href="#43" id="43">43</a>
<a href="#44" id="44">44</a>
<a href="#45" id="45">45</a>
<a href="#46" id="46">46</a>
<a href="#47" id="47">47</a>
<a href="#48" id="48">48</a>
<a href="#49" id="49">49</a>
<a href="#50" id="50">50</a>
<a href="#51" id="51">51</a>
<a href="#52" id="52">52</a>
<a href="#53" id="53">53</a>
<a href="#54" id="54">54</a>
<a href="#55" id="55">55</a>
<a href="#56" id="56">56</a>
<a href="#57" id="57">57</a>
<a href="#58" id="58">58</a>
<a href="#59" id="59">59</a>
<a href="#60" id="60">60</a>
<a href="#61" id="61">61</a>
<a href="#62" id="62">62</a>
<a href="#63" id="63">63</a>
<a href="#64" id="64">64</a>
<a href="#65" id="65">65</a>
<a href="#66" id="66">66</a>
<a href="#67" id="67">67</a>
<a href="#68" id="68">68</a>
<a href="#69" id="69">69</a>
<a href="#70" id="70">70</a>
<a href="#71" id="71">71</a>
<a href="#72" id="72">72</a>
<a href="#73" id="73">73</a>
<a href="#74" id="74">74</a>
<a href="#75" id="75">75</a>
<a href="#76" id="76">76</a>
<a href="#77" id="77">77</a>
<a href="#78" id="78">78</a>
<a href="#79" id="79">79</a>
<a href="#80" id="80">80</a>
<a href="#81" id="81">81</a>
<a href="#82" id="82">82</a>
<a href="#83" id="83">83</a>
<a href="#84" id="84">84</a>
<a href="#85" id="85">85</a>
<a href="#86" id="86">86</a>
<a href="#87" id="87">87</a>
<a href="#88" id="88">88</a>
<a href="#89" id="89">89</a>
<a href="#90" id="90">90</a>
<a href="#91" id="91">91</a>
<a href="#92" id="92">92</a>
<a href="#93" id="93">93</a>
<a href="#94" id="94">94</a>
<a href="#95" id="95">95</a>
<a href="#96" id="96">96</a>
<a href="#97" id="97">97</a>
<a href="#98" id="98">98</a>
<a href="#99" id="99">99</a>
<a href="#100" id="100">100</a>
<a href="#101" id="101">101</a>
<a href="#102" id="102">102</a>
<a href="#103" id="103">103</a>
<a href="#104" id="104">104</a>
<a href="#105" id="105">105</a>
<a href="#106" id="106">106</a>
<a href="#107" id="107">107</a>
<a href="#108" id="108">108</a>
<a href="#109" id="109">109</a>
<a href="#110" id="110">110</a>
<a href="#111" id="111">111</a>
<a href="#112" id="112">112</a>
<a href="#113" id="113">113</a>
<a href="#114" id="114">114</a>
<a href="#115" id="115">115</a>
<a href="#116" id="116">116</a>
<a href="#117" id="117">117</a>
<a href="#118" id="118">118</a>
<a href="#119" id="119">119</a>
<a href="#120" id="120">120</a>
<a href="#121" id="121">121</a>
<a href="#122" id="122">122</a>
<a href="#123" id="123">123</a>
<a href="#124" id="124">124</a>
<a href="#125" id="125">125</a>
<a href="#126" id="126">126</a>
<a href="#127" id="127">127</a>
<a href="#128" id="128">128</a>
<a href="#129" id="129">129</a>
<a href="#130" id="130">130</a>
<a href="#131" id="131">131</a>
<a href="#132" id="132">132</a>
<a href="#133" id="133">133</a>
<a href="#134" id="134">134</a>
<a href="#135" id="135">135</a>
<a href="#136" id="136">136</a>
<a href="#137" id="137">137</a>
<a href="#138" id="138">138</a>
<a href="#139" id="139">139</a>
<a href="#140" id="140">140</a>
<a href="#141" id="141">141</a>
<a href="#142" id="142">142</a>
<a href="#143" id="143">143</a>
<a href="#144" id="144">144</a>
<a href="#145" id="145">145</a>
<a href="#146" id="146">146</a>
<a href="#147" id="147">147</a>
<a href="#148" id="148">148</a>
<a href="#149" id="149">149</a>
<a href="#150" id="150">150</a>
<a href="#151" id="151">151</a>
<a href="#152" id="152">152</a>
<a href="#153" id="153">153</a>
<a href="#154" id="154">154</a>
<a href="#155" id="155">155</a>
<a href="#156" id="156">156</a>
<a href="#157" id="157">157</a>
<a href="#158" id="158">158</a>
<a href="#159" id="159">159</a>
<a href="#160" id="160">160</a>
<a href="#161" id="161">161</a>
<a href="#162" id="162">162</a>
<a href="#163" id="163">163</a>
<a href="#164" id="164">164</a>
<a href="#165" id="165">165</a>
<a href="#166" id="166">166</a>
<a href="#167" id="167">167</a>
<a href="#168" id="168">168</a>
<a href="#169" id="169">169</a>
<a href="#170" id="170">170</a>
<a href="#171" id="171">171</a>
<a href="#172" id="172">172</a>
<a href="#173" id="173">173</a>
<a href="#174" id="174">174</a>
<a href="#175" id="175">175</a>
<a href="#176" id="176">176</a>
<a href="#177" id="177">177</a>
<a href="#178" id="178">178</a>
<a href="#179" id="179">179</a>
<a href="#180" id="180">180</a>
<a href="#181" id="181">181</a>
<a href="#182" id="182">182</a>
<a href="#183" id="183">183</a>
<a href="#184" id="184">184</a>
<a href="#185" id="185">185</a>
<a href="#186" id="186">186</a>
<a href="#187" id="187">187</a>
<a href="#188" id="188">188</a>
<a href="#189" id="189">189</a>
<a href="#190" id="190">190</a>
<a href="#191" id="191">191</a>
<a href="#192" id="192">192</a>
<a href="#193" id="193">193</a>
<a href="#194" id="194">194</a>
<a href="#195" id="195">195</a>
<a href="#196" id="196">196</a>
<a href="#197" id="197">197</a>
<a href="#198" id="198">198</a>
<a href="#199" id="199">199</a>
<a href="#200" id="200">200</a>
<a href="#201" id="201">201</a>
<a href="#202" id="202">202</a>
<a href="#203" id="203">203</a>
<a href="#204" id="204">204</a>
<a href="#205" id="205">205</a>
<a href="#206" id="206">206</a>
<a href="#207" id="207">207</a>
<a href="#208" id="208">208</a>
<a href="#209" id="209">209</a>
<a href="#210" id="210">210</a>
<a href="#211" id="211">211</a>
<a href="#212" id="212">212</a>
<a href="#213" id="213">213</a>
<a href="#214" id="214">214</a>
<a href="#215" id="215">215</a>
<a href="#216" id="216">216</a>
<a href="#217" id="217">217</a>
<a href="#218" id="218">218</a>
<a href="#219" id="219">219</a>
<a href="#220" id="220">220</a>
<a href="#221" id="221">221</a>
<a href="#222" id="222">222</a>
<a href="#223" id="223">223</a>
<a href="#224" id="224">224</a>
<a href="#225" id="225">225</a>
<a href="#226" id="226">226</a>
<a href="#227" id="227">227</a>
<a href="#228" id="228">228</a>
<a href="#229" id="229">229</a>
<a href="#230" id="230">230</a>
<a href="#231" id="231">231</a>
<a href="#232" id="232">232</a>
<a href="#233" id="233">233</a>
<a href="#234" id="234">234</a>
<a href="#235" id="235">235</a>
<a href="#236" id="236">236</a>
<a href="#237" id="237">237</a>
<a href="#238" id="238">238</a>
<a href="#239" id="239">239</a>
<a href="#240" id="240">240</a>
<a href="#241" id="241">241</a>
<a href="#242" id="242">242</a>
<a href="#243" id="243">243</a>
<a href="#244" id="244">244</a>
<a href="#245" id="245">245</a>
<a href="#246" id="246">246</a>
<a href="#247" id="247">247</a>
<a href="#248" id="248">248</a>
<a href="#249" id="249">249</a>
<a href="#250" id="250">250</a>
<a href="#251" id="251">251</a>
<a href="#252" id="252">252</a>
<a href="#253" id="253">253</a>
<a href="#254" id="254">254</a>
<a href="#255" id="255">255</a>
<a href="#256" id="256">256</a>
<a href="#257" id="257">257</a>
<a href="#258" id="258">258</a>
<a href="#259" id="259">259</a>
<a href="#260" id="260">260</a>
<a href="#261" id="261">261</a>
<a href="#262" id="262">262</a>
<a href="#263" id="263">263</a>
<a href="#264" id="264">264</a>
<a href="#265" id="265">265</a>
<a href="#266" id="266">266</a>
<a href="#267" id="267">267</a>
<a href="#268" id="268">268</a>
<a href="#269" id="269">269</a>
<a href="#270" id="270">270</a>
<a href="#271" id="271">271</a>
<a href="#272" id="272">272</a>
<a href="#273" id="273">273</a>
<a href="#274" id="274">274</a>
<a href="#275" id="275">275</a>
<a href="#276" id="276">276</a>
<a href="#277" id="277">277</a>
<a href="#278" id="278">278</a>
<a href="#279" id="279">279</a>
<a href="#280" id="280">280</a>
<a href="#281" id="281">281</a>
<a href="#282" id="282">282</a>
<a href="#283" id="283">283</a>
<a href="#284" id="284">284</a>
<a href="#285" id="285">285</a>
<a href="#286" id="286">286</a>
<a href="#287" id="287">287</a>
<a href="#288" id="288">288</a>
<a href="#289" id="289">289</a>
<a href="#290" id="290">290</a>
<a href="#291" id="291">291</a>
<a href="#292" id="292">292</a>
<a href="#293" id="293">293</a>
<a href="#294" id="294">294</a>
<a href="#295" id="295">295</a>
<a href="#296" id="296">296</a>
<a href="#297" id="297">297</a>
<a href="#298" id="298">298</a>
<a href="#299" id="299">299</a>
<a href="#300" id="300">300</a>
<a href="#301" id="301">301</a>
<a href="#302" id="302">302</a>
<a href="#303" id="303">303</a>
<a href="#304" id="304">304</a>
<a href="#305" id="305">305</a>
<a href="#306" id="306">306</a>
<a href="#307" id="307">307</a>
<a href="#308" id="308">308</a>
<a href="#309" id="309">309</a>
<a href="#310" id="310">310</a>
<a href="#311" id="311">311</a>
<a href="#312" id="312">312</a>
<a href="#313" id="313">313</a>
<a href="#314" id="314">314</a>
<a href="#315" id="315">315</a>
<a href="#316" id="316">316</a>
<a href="#317" id="317">317</a>
<a href="#318" id="318">318</a>
<a href="#319" id="319">319</a>
<a href="#320" id="320">320</a>
<a href="#321" id="321">321</a>
<a href="#322" id="322">322</a>
<a href="#323" id="323">323</a>
<a href="#324" id="324">324</a>
<a href="#325" id="325">325</a>
<a href="#326" id="326">326</a>
<a href="#327" id="327">327</a>
<a href="#328" id="328">328</a>
<a href="#329" id="329">329</a>
<a href="#330" id="330">330</a>
<a href="#331" id="331">331</a>
<a href="#332" id="332">332</a>
<a href="#333" id="333">333</a>
<a href="#334" id="334">334</a>
<a href="#335" id="335">335</a>
<a href="#336" id="336">336</a>
<a href="#337" id="337">337</a>
<a href="#338" id="338">338</a>
<a href="#339" id="339">339</a>
<a href="#340" id="340">340</a>
<a href="#341" id="341">341</a>
<a href="#342" id="342">342</a>
<a href="#343" id="343">343</a>
<a href="#344" id="344">344</a>
<a href="#345" id="345">345</a>
<a href="#346" id="346">346</a>
<a href="#347" id="347">347</a>
<a href="#348" id="348">348</a>
<a href="#349" id="349">349</a>
<a href="#350" id="350">350</a>
<a href="#351" id="351">351</a>
<a href="#352" id="352">352</a>
<a href="#353" id="353">353</a>
<a href="#354" id="354">354</a>
<a href="#355" id="355">355</a>
<a href="#356" id="356">356</a>
<a href="#357" id="357">357</a>
<a href="#358" id="358">358</a>
<a href="#359" id="359">359</a>
<a href="#360" id="360">360</a>
<a href="#361" id="361">361</a>
<a href="#362" id="362">362</a>
<a href="#363" id="363">363</a>
</pre></div><pre class="rust"><code><span class="doccomment">//! 32-bit hashing machinery
//!
//! # Why?
//!
//! Because 32-bit architectures are a thing (e.g. ARM Cortex-M) and you don&#39;t want your hashing
//! function to pull in a bunch of slow 64-bit compiler intrinsics (software implementations of
//! 64-bit operations).
//!
//! # Relationship to `core::hash`
//!
//! This crate exposes the same interfaces you&#39;ll find in [`core::hash`]: `Hash`, `Hasher`,
//! `BuildHasher` and `BuildHasherDefault`. The main difference is that `hash32::Hasher::finish`
//! returns a `u32` instead of `u64`, and the contract of `hash32::Hasher` forbids the implementer
//! from performing 64-bit (or 128-bit) operations while computing the hash.
//!
//! [`core::hash`]: https://doc.rust-lang.org/std/hash/index.html
//!
//! # `#[derive(Hash32)]`
//!
//! The easiest way to implement `hash32::Hash` for a `struct` is to use the `#[derive(Hash32)]`.
//!
//! Note that you need to *explicitly* depend on both `hash32` *and* `hash32_derive`; both crates
//! must appear in your `Cargo.toml`.
//!
//! ``` ignore
//! use hash32_derive::Hash32;
//!
//! #[derive(Hash32)]
//! struct Ipv4Addr([u8; 4]);
//!
//! # fn main() {}
//!
//! ```
//! # Hashers
//!
//! This crate provides implementations of the following 32-bit hashing algorithms:
//!
//! - [Fowler-Noll-Vo](struct.FnvHasher.html)
//! - [MurmurHash3](struct.Murmur3Hasher.html)
//!
//! # MSRV
//!
//! This crate is guaranteed to compile on latest stable Rust. It *might* compile on older
//! versions but that may change in any new patch release.
//!
//! # Future
//!
//! In the future we&#39;d like to deprecate this crate in favor of making `core::hash::Hasher` generic
//! over the size of the computed hash. Below is shown the planned change (but it doesn&#39;t work due
//! to limitations in the `associated_type_defaults` feature):
//!
//! ``` ignore
//! #![feature(associated_type_defaults)]
//!
//! trait Hasher {
//! type Hash = u64; // default type for backwards compatibility
//!
//! fn finish(&amp;self) -&gt; Self::Hash; // changed
//! fn write(&amp;mut self, bytes: &amp;[u8]);
//! }
//! ```
//!
//! With this change a single `#[derive(Hash)]` would enough to make a type hashable with 32-bit and
//! 64-bit hashers.
</span><span class="attr">#![deny(missing_docs)]
#![deny(warnings)]
#![no_std]
</span><span class="kw">extern crate </span>byteorder;
<span class="kw">use </span>core::marker::PhantomData;
<span class="kw">use </span>core::{mem, slice, fmt};
<span class="kw">pub use </span>fnv::Hasher <span class="kw">as </span>FnvHasher;
<span class="kw">pub use </span>murmur3::Hasher <span class="kw">as </span>Murmur3Hasher;
<span class="kw">mod </span>fnv;
<span class="kw">mod </span>murmur3;
<span class="doccomment">/// See [`core::hash::BuildHasherDefault`][0] for details
///
/// [0]: https://doc.rust-lang.org/core/hash/struct.BuildHasherDefault.html
</span><span class="kw">pub struct </span>BuildHasherDefault&lt;H&gt;
{
_marker: PhantomData&lt;H&gt;,
}
<span class="kw">impl</span>&lt;H&gt; Default <span class="kw">for </span>BuildHasherDefault&lt;H&gt;
<span class="kw">where
</span>H: Default + Hasher,
{
<span class="kw">fn </span>default() -&gt; <span class="self">Self </span>{
BuildHasherDefault {
_marker: PhantomData,
}
}
}
<span class="kw">impl</span>&lt;H&gt; Clone <span class="kw">for </span>BuildHasherDefault&lt;H&gt;
<span class="kw">where
</span>H: Default + Hasher,
{
<span class="kw">fn </span>clone(<span class="kw-2">&amp;</span><span class="self">self</span>) -&gt; <span class="self">Self </span>{
BuildHasherDefault::default()
}
}
<span class="kw">impl</span>&lt;H&gt; PartialEq <span class="kw">for </span>BuildHasherDefault&lt;H&gt;
<span class="kw">where
</span>H: Default + Hasher,
{
<span class="kw">fn </span>eq(<span class="kw-2">&amp;</span><span class="self">self</span>, _other: <span class="kw-2">&amp;</span>BuildHasherDefault&lt;H&gt;) -&gt; bool {
<span class="bool-val">true
</span>}
}
<span class="kw">impl</span>&lt;H: Default + Hasher&gt; Eq <span class="kw">for </span>BuildHasherDefault&lt;H&gt; {}
<span class="kw">impl</span>&lt;H: Default + Hasher&gt; fmt::Debug <span class="kw">for </span>BuildHasherDefault&lt;H&gt; {
<span class="kw">fn </span>fmt(<span class="kw-2">&amp;</span><span class="self">self</span>, f: <span class="kw-2">&amp;mut </span>fmt::Formatter&lt;<span class="lifetime">&#39;_</span>&gt;) -&gt; fmt::Result {
f.pad(<span class="string">&quot;BuildHasherDefault&quot;</span>)
}
}
<span class="kw">impl</span>&lt;H&gt; BuildHasherDefault&lt;H&gt;
{
<span class="doccomment">/// `const` constructor
</span><span class="kw">pub const fn </span>new() -&gt; <span class="self">Self </span>{
BuildHasherDefault {
_marker: PhantomData,
}
}
}
<span class="kw">impl</span>&lt;H&gt; BuildHasher <span class="kw">for </span>BuildHasherDefault&lt;H&gt;
<span class="kw">where
</span>H: Default + Hasher,
{
<span class="kw">type </span>Hasher = H;
<span class="kw">fn </span>build_hasher(<span class="kw-2">&amp;</span><span class="self">self</span>) -&gt; <span class="self">Self</span>::Hasher {
H::default()
}
}
<span class="doccomment">/// See [`core::hash::BuildHasher`][0] for details
///
/// [0]: https://doc.rust-lang.org/core/hash/trait.BuildHasher.html
</span><span class="kw">pub trait </span>BuildHasher {
<span class="doccomment">/// See [`core::hash::BuildHasher::Hasher`][0]
///
/// [0]: https://doc.rust-lang.org/std/hash/trait.BuildHasher.html#associatedtype.Hasher
</span><span class="kw">type </span>Hasher: Hasher;
<span class="doccomment">/// See [`core::hash::BuildHasher.build_hasher`][0]
///
/// [0]: https://doc.rust-lang.org/std/hash/trait.BuildHasher.html#tymethod.build_hasher
</span><span class="kw">fn </span>build_hasher(<span class="kw-2">&amp;</span><span class="self">self</span>) -&gt; <span class="self">Self</span>::Hasher;
}
<span class="doccomment">/// See [`core::hash::Hasher`][0] for details
///
/// [0]: https://doc.rust-lang.org/core/hash/trait.Hasher.html
///
/// # Contract
///
/// Implementers of this trait must *not* perform any 64-bit (or 128-bit) operation while computing
/// the hash.
</span><span class="kw">pub trait </span>Hasher {
<span class="doccomment">/// See [`core::hash::Hasher.finish`][0]
///
/// [0]: https://doc.rust-lang.org/std/hash/trait.Hasher.html#tymethod.finish
</span><span class="kw">fn </span>finish(<span class="kw-2">&amp;</span><span class="self">self</span>) -&gt; u32;
<span class="doccomment">/// See [`core::hash::Hasher.write`][0]
///
/// [0]: https://doc.rust-lang.org/std/hash/trait.Hasher.html#tymethod.write
</span><span class="kw">fn </span>write(<span class="kw-2">&amp;mut </span><span class="self">self</span>, bytes: <span class="kw-2">&amp;</span>[u8]);
}
<span class="doccomment">/// See [`core::hash::Hash`][0] for details
///
/// [0]: https://doc.rust-lang.org/core/hash/trait.Hash.html
</span><span class="kw">pub trait </span>Hash {
<span class="doccomment">/// Feeds this value into the given `Hasher`.
</span><span class="kw">fn </span>hash&lt;H&gt;(<span class="kw-2">&amp;</span><span class="self">self</span>, state: <span class="kw-2">&amp;mut </span>H)
<span class="kw">where
</span>H: Hasher;
<span class="doccomment">/// Feeds a slice of this type into the given `Hasher`.
</span><span class="kw">fn </span>hash_slice&lt;H&gt;(data: <span class="kw-2">&amp;</span>[<span class="self">Self</span>], state: <span class="kw-2">&amp;mut </span>H)
<span class="kw">where
</span>H: Hasher,
<span class="self">Self</span>: Sized,
{
<span class="kw">for </span>piece <span class="kw">in </span>data {
piece.hash(state);
}
}
}
<span class="macro">macro_rules! </span>int {
(<span class="macro-nonterminal">$ty</span>:ident) =&gt; {
<span class="kw">impl </span>Hash <span class="kw">for </span><span class="macro-nonterminal">$ty </span>{
<span class="kw">fn </span>hash&lt;H&gt;(<span class="kw-2">&amp;</span><span class="self">self</span>, state: <span class="kw-2">&amp;mut </span>H)
<span class="kw">where
</span>H: Hasher,
{
<span class="kw">unsafe </span>{ state.write(<span class="kw-2">&amp;</span>mem::transmute::&lt;<span class="macro-nonterminal">$ty</span>, [u8; mem::size_of::&lt;<span class="macro-nonterminal">$ty</span>&gt;()]&gt;(<span class="kw-2">*</span><span class="self">self</span>)) }
}
<span class="kw">fn </span>hash_slice&lt;H&gt;(data: <span class="kw-2">&amp;</span>[<span class="self">Self</span>], state: <span class="kw-2">&amp;mut </span>H)
<span class="kw">where
</span>H: Hasher,
{
<span class="kw">let </span>newlen = data.len() * mem::size_of::&lt;<span class="macro-nonterminal">$ty</span>&gt;();
<span class="kw">let </span>ptr = data.as_ptr() <span class="kw">as </span><span class="kw-2">*const </span>u8;
<span class="kw">unsafe </span>{ state.write(slice::from_raw_parts(ptr, newlen)) }
}
}
};
}
<span class="macro">int!</span>(i16);
<span class="macro">int!</span>(i32);
<span class="macro">int!</span>(i64);
<span class="macro">int!</span>(i8);
<span class="macro">int!</span>(isize);
<span class="macro">int!</span>(u16);
<span class="macro">int!</span>(u32);
<span class="macro">int!</span>(u64);
<span class="macro">int!</span>(u8);
<span class="macro">int!</span>(usize);
<span class="kw">impl </span>Hash <span class="kw">for </span>bool {
<span class="kw">fn </span>hash&lt;H&gt;(<span class="kw-2">&amp;</span><span class="self">self</span>, state: <span class="kw-2">&amp;mut </span>H)
<span class="kw">where
</span>H: Hasher,
{
(<span class="kw-2">*</span><span class="self">self </span><span class="kw">as </span>u8).hash(state)
}
}
<span class="kw">impl </span>Hash <span class="kw">for </span>char {
<span class="kw">fn </span>hash&lt;H&gt;(<span class="kw-2">&amp;</span><span class="self">self</span>, state: <span class="kw-2">&amp;mut </span>H)
<span class="kw">where
</span>H: Hasher,
{
(<span class="kw-2">*</span><span class="self">self </span><span class="kw">as </span>u32).hash(state)
}
}
<span class="kw">impl </span>Hash <span class="kw">for </span>str {
<span class="kw">fn </span>hash&lt;H&gt;(<span class="kw-2">&amp;</span><span class="self">self</span>, state: <span class="kw-2">&amp;mut </span>H)
<span class="kw">where
</span>H: Hasher,
{
state.write(<span class="self">self</span>.as_bytes());
state.write(<span class="kw-2">&amp;</span>[<span class="number">0xff</span>]);
}
}
<span class="kw">impl</span>&lt;T&gt; Hash <span class="kw">for </span>[T]
<span class="kw">where
</span>T: Hash,
{
<span class="kw">fn </span>hash&lt;H&gt;(<span class="kw-2">&amp;</span><span class="self">self</span>, state: <span class="kw-2">&amp;mut </span>H)
<span class="kw">where
</span>H: Hasher,
{
<span class="self">self</span>.len().hash(state);
T::hash_slice(<span class="self">self</span>, state);
}
}
<span class="macro">macro_rules! </span>array {
($(<span class="macro-nonterminal">$n</span>:expr),+) =&gt; {
$(
<span class="kw">impl</span>&lt;T&gt; Hash <span class="kw">for </span>[T; <span class="macro-nonterminal">$n</span>]
<span class="kw">where
</span>T: Hash,
{
<span class="kw">fn </span>hash&lt;H&gt;(<span class="kw-2">&amp;</span><span class="self">self</span>, state: <span class="kw-2">&amp;mut </span>H)
<span class="kw">where
</span>H: Hasher,
{
Hash::hash(<span class="kw-2">&amp;</span><span class="self">self</span>[..], state)
}
}
)+
};
}
<span class="macro">array!</span>(
<span class="number">0</span>, <span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>, <span class="number">6</span>, <span class="number">7</span>, <span class="number">8</span>, <span class="number">9</span>, <span class="number">10</span>, <span class="number">11</span>, <span class="number">12</span>, <span class="number">13</span>, <span class="number">14</span>, <span class="number">15</span>, <span class="number">16</span>, <span class="number">17</span>, <span class="number">18</span>, <span class="number">19</span>, <span class="number">20</span>, <span class="number">21</span>, <span class="number">22</span>, <span class="number">23</span>, <span class="number">24</span>, <span class="number">25</span>,
<span class="number">26</span>, <span class="number">27</span>, <span class="number">28</span>, <span class="number">29</span>, <span class="number">30</span>, <span class="number">31</span>, <span class="number">32
</span>);
<span class="kw">impl</span>&lt;<span class="lifetime">&#39;a</span>, T: <span class="question-mark">?</span>Sized + Hash&gt; Hash <span class="kw">for </span><span class="kw-2">&amp;</span><span class="lifetime">&#39;a </span>T {
<span class="kw">fn </span>hash&lt;H: Hasher&gt;(<span class="kw-2">&amp;</span><span class="self">self</span>, state: <span class="kw-2">&amp;mut </span>H) {
(<span class="kw-2">**</span><span class="self">self</span>).hash(state);
}
}
<span class="kw">impl</span>&lt;<span class="lifetime">&#39;a</span>, T: <span class="question-mark">?</span>Sized + Hash&gt; Hash <span class="kw">for </span><span class="kw-2">&amp;</span><span class="lifetime">&#39;a </span><span class="kw-2">mut </span>T {
<span class="kw">fn </span>hash&lt;H: Hasher&gt;(<span class="kw-2">&amp;</span><span class="self">self</span>, state: <span class="kw-2">&amp;mut </span>H) {
(<span class="kw-2">**</span><span class="self">self</span>).hash(state);
}
}
<span class="kw">impl </span>Hash <span class="kw">for </span>() {
<span class="kw">fn </span>hash&lt;H: Hasher&gt;(<span class="kw-2">&amp;</span><span class="self">self</span>, _state: <span class="kw-2">&amp;mut </span>H) {}
}
<span class="macro">macro_rules! </span>tuple {
( $(<span class="macro-nonterminal">$name</span>:ident)+) =&gt; (
<span class="kw">impl</span>&lt;$(<span class="macro-nonterminal">$name</span>: Hash),<span class="kw-2">*</span>&gt; Hash <span class="kw">for </span>($(<span class="macro-nonterminal">$name</span>,)<span class="kw-2">*</span>)
<span class="kw">where
</span><span class="macro">last_type!</span>($(<span class="macro-nonterminal">$name</span>,)+): <span class="question-mark">?</span>Sized
{
<span class="attr">#[allow(non_snake_case)]
</span><span class="kw">fn </span>hash&lt;S: Hasher&gt;(<span class="kw-2">&amp;</span><span class="self">self</span>, state: <span class="kw-2">&amp;mut </span>S) {
<span class="kw">let </span>($(<span class="kw-2">ref </span><span class="macro-nonterminal">$name</span>,)<span class="kw-2">*</span>) = <span class="kw-2">*</span><span class="self">self</span>;
$(<span class="macro-nonterminal">$name</span>.hash(state);)*
}
}
);
}
<span class="macro">macro_rules! </span>last_type {
(<span class="macro-nonterminal">$a</span>:ident,) =&gt; { <span class="macro-nonterminal">$a </span>};
(<span class="macro-nonterminal">$a</span>:ident, $(<span class="macro-nonterminal">$rest_a</span>:ident,)+) =&gt; { <span class="macro">last_type!</span>($(<span class="macro-nonterminal">$rest_a</span>,)+) };
}
<span class="macro">tuple! </span>{ A }
<span class="macro">tuple! </span>{ A B }
<span class="macro">tuple! </span>{ A B C }
<span class="macro">tuple! </span>{ A B C D }
<span class="macro">tuple! </span>{ A B C D E }
<span class="macro">tuple! </span>{ A B C D E F }
<span class="macro">tuple! </span>{ A B C D E F G }
<span class="macro">tuple! </span>{ A B C D E F G H }
<span class="macro">tuple! </span>{ A B C D E F G H I }
<span class="macro">tuple! </span>{ A B C D E F G H I J }
<span class="macro">tuple! </span>{ A B C D E F G H I J K }
<span class="macro">tuple! </span>{ A B C D E F G H I J K L }
<span class="attr">#[cfg(test)]
</span><span class="kw">mod </span>test {
<span class="kw">use super</span>::{FnvHasher, Hash, Hasher};
<span class="attr">#[test]
</span><span class="kw">fn </span>hashes_tuples() {
<span class="kw">let </span><span class="kw-2">mut </span>h = FnvHasher::default();
().hash(<span class="kw-2">&amp;mut </span>h);
(<span class="number">1_usize</span>,).hash(<span class="kw-2">&amp;mut </span>h);
(<span class="number">1_u8</span>, <span class="number">2_i8</span>).hash(<span class="kw-2">&amp;mut </span>h);
(<span class="number">1_u16</span>, <span class="number">2_i16</span>, <span class="number">3_u32</span>).hash(<span class="kw-2">&amp;mut </span>h);
(<span class="number">1_i32</span>, <span class="number">2_u64</span>, <span class="number">3_i64</span>, <span class="bool-val">true</span>).hash(<span class="kw-2">&amp;mut </span>h);
(<span class="number">1_isize</span>, <span class="string">&#39;a&#39;</span>, <span class="string">&quot;abc&quot;</span>, [<span class="number">1u32</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>], <span class="bool-val">false</span>).hash(<span class="kw-2">&amp;mut </span>h);
h.finish();
}
}
</code></pre></div></section></main></body></html>

View file

@ -1,381 +0,0 @@
<!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="Source of the Rust file `/home/zenn/.cargo/registry/src/index.crates.io-6f17d22bba15001f/hash32-0.2.1/src/murmur3.rs`."><title>murmur3.rs - source</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-47e7ab555ef2818a.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="hash32" data-themes="" data-resource-suffix="" data-rustdoc-version="1.74.0-nightly (d9c8274fb 2023-09-12)" data-channel="nightly" data-search-js="search-5d3eaacf19ebf04f.js" data-settings-js="settings-74424d7eec62a23e.js" data-settings-css="settings-8c76f75bfb6bd192.css" data-theme-light-css="light-f194925aa375ae96.css" data-theme-dark-css="dark-1dd4d1ce031e15de.css" data-theme-ayu-css="ayu-49e58d069f567085.css" ><script src="../../static.files/storage-db41da1a38ea3cb8.js"></script><script defer src="../../static.files/src-script-3280b574d94e47b4.js"></script><script defer src="../../src-files.js"></script><script defer src="../../static.files/main-8d035c8cea6edbc4.js"></script><noscript><link rel="stylesheet" media="(prefers-color-scheme:light)" href="../../static.files/light-f194925aa375ae96.css"><link rel="stylesheet" media="(prefers-color-scheme:dark)" href="../../static.files/dark-1dd4d1ce031e15de.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 src"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"></nav><main><nav class="sub"><a class="sub-logo-container" href="../../hash32/index.html"><img class="rust-logo" src="../../static.files/rust-logo-151179464ae7ed46.svg" alt="logo"></a><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="example-wrap"><div data-nosnippet><pre class="src-line-numbers"><a href="#1" id="1">1</a>
<a href="#2" id="2">2</a>
<a href="#3" id="3">3</a>
<a href="#4" id="4">4</a>
<a href="#5" id="5">5</a>
<a href="#6" id="6">6</a>
<a href="#7" id="7">7</a>
<a href="#8" id="8">8</a>
<a href="#9" id="9">9</a>
<a href="#10" id="10">10</a>
<a href="#11" id="11">11</a>
<a href="#12" id="12">12</a>
<a href="#13" id="13">13</a>
<a href="#14" id="14">14</a>
<a href="#15" id="15">15</a>
<a href="#16" id="16">16</a>
<a href="#17" id="17">17</a>
<a href="#18" id="18">18</a>
<a href="#19" id="19">19</a>
<a href="#20" id="20">20</a>
<a href="#21" id="21">21</a>
<a href="#22" id="22">22</a>
<a href="#23" id="23">23</a>
<a href="#24" id="24">24</a>
<a href="#25" id="25">25</a>
<a href="#26" id="26">26</a>
<a href="#27" id="27">27</a>
<a href="#28" id="28">28</a>
<a href="#29" id="29">29</a>
<a href="#30" id="30">30</a>
<a href="#31" id="31">31</a>
<a href="#32" id="32">32</a>
<a href="#33" id="33">33</a>
<a href="#34" id="34">34</a>
<a href="#35" id="35">35</a>
<a href="#36" id="36">36</a>
<a href="#37" id="37">37</a>
<a href="#38" id="38">38</a>
<a href="#39" id="39">39</a>
<a href="#40" id="40">40</a>
<a href="#41" id="41">41</a>
<a href="#42" id="42">42</a>
<a href="#43" id="43">43</a>
<a href="#44" id="44">44</a>
<a href="#45" id="45">45</a>
<a href="#46" id="46">46</a>
<a href="#47" id="47">47</a>
<a href="#48" id="48">48</a>
<a href="#49" id="49">49</a>
<a href="#50" id="50">50</a>
<a href="#51" id="51">51</a>
<a href="#52" id="52">52</a>
<a href="#53" id="53">53</a>
<a href="#54" id="54">54</a>
<a href="#55" id="55">55</a>
<a href="#56" id="56">56</a>
<a href="#57" id="57">57</a>
<a href="#58" id="58">58</a>
<a href="#59" id="59">59</a>
<a href="#60" id="60">60</a>
<a href="#61" id="61">61</a>
<a href="#62" id="62">62</a>
<a href="#63" id="63">63</a>
<a href="#64" id="64">64</a>
<a href="#65" id="65">65</a>
<a href="#66" id="66">66</a>
<a href="#67" id="67">67</a>
<a href="#68" id="68">68</a>
<a href="#69" id="69">69</a>
<a href="#70" id="70">70</a>
<a href="#71" id="71">71</a>
<a href="#72" id="72">72</a>
<a href="#73" id="73">73</a>
<a href="#74" id="74">74</a>
<a href="#75" id="75">75</a>
<a href="#76" id="76">76</a>
<a href="#77" id="77">77</a>
<a href="#78" id="78">78</a>
<a href="#79" id="79">79</a>
<a href="#80" id="80">80</a>
<a href="#81" id="81">81</a>
<a href="#82" id="82">82</a>
<a href="#83" id="83">83</a>
<a href="#84" id="84">84</a>
<a href="#85" id="85">85</a>
<a href="#86" id="86">86</a>
<a href="#87" id="87">87</a>
<a href="#88" id="88">88</a>
<a href="#89" id="89">89</a>
<a href="#90" id="90">90</a>
<a href="#91" id="91">91</a>
<a href="#92" id="92">92</a>
<a href="#93" id="93">93</a>
<a href="#94" id="94">94</a>
<a href="#95" id="95">95</a>
<a href="#96" id="96">96</a>
<a href="#97" id="97">97</a>
<a href="#98" id="98">98</a>
<a href="#99" id="99">99</a>
<a href="#100" id="100">100</a>
<a href="#101" id="101">101</a>
<a href="#102" id="102">102</a>
<a href="#103" id="103">103</a>
<a href="#104" id="104">104</a>
<a href="#105" id="105">105</a>
<a href="#106" id="106">106</a>
<a href="#107" id="107">107</a>
<a href="#108" id="108">108</a>
<a href="#109" id="109">109</a>
<a href="#110" id="110">110</a>
<a href="#111" id="111">111</a>
<a href="#112" id="112">112</a>
<a href="#113" id="113">113</a>
<a href="#114" id="114">114</a>
<a href="#115" id="115">115</a>
<a href="#116" id="116">116</a>
<a href="#117" id="117">117</a>
<a href="#118" id="118">118</a>
<a href="#119" id="119">119</a>
<a href="#120" id="120">120</a>
<a href="#121" id="121">121</a>
<a href="#122" id="122">122</a>
<a href="#123" id="123">123</a>
<a href="#124" id="124">124</a>
<a href="#125" id="125">125</a>
<a href="#126" id="126">126</a>
<a href="#127" id="127">127</a>
<a href="#128" id="128">128</a>
<a href="#129" id="129">129</a>
<a href="#130" id="130">130</a>
<a href="#131" id="131">131</a>
<a href="#132" id="132">132</a>
<a href="#133" id="133">133</a>
<a href="#134" id="134">134</a>
<a href="#135" id="135">135</a>
<a href="#136" id="136">136</a>
<a href="#137" id="137">137</a>
<a href="#138" id="138">138</a>
<a href="#139" id="139">139</a>
<a href="#140" id="140">140</a>
<a href="#141" id="141">141</a>
<a href="#142" id="142">142</a>
<a href="#143" id="143">143</a>
<a href="#144" id="144">144</a>
<a href="#145" id="145">145</a>
<a href="#146" id="146">146</a>
<a href="#147" id="147">147</a>
<a href="#148" id="148">148</a>
<a href="#149" id="149">149</a>
<a href="#150" id="150">150</a>
<a href="#151" id="151">151</a>
<a href="#152" id="152">152</a>
<a href="#153" id="153">153</a>
<a href="#154" id="154">154</a>
<a href="#155" id="155">155</a>
<a href="#156" id="156">156</a>
<a href="#157" id="157">157</a>
<a href="#158" id="158">158</a>
<a href="#159" id="159">159</a>
<a href="#160" id="160">160</a>
<a href="#161" id="161">161</a>
<a href="#162" id="162">162</a>
<a href="#163" id="163">163</a>
<a href="#164" id="164">164</a>
<a href="#165" id="165">165</a>
<a href="#166" id="166">166</a>
<a href="#167" id="167">167</a>
<a href="#168" id="168">168</a>
<a href="#169" id="169">169</a>
<a href="#170" id="170">170</a>
<a href="#171" id="171">171</a>
<a href="#172" id="172">172</a>
<a href="#173" id="173">173</a>
<a href="#174" id="174">174</a>
<a href="#175" id="175">175</a>
<a href="#176" id="176">176</a>
<a href="#177" id="177">177</a>
<a href="#178" id="178">178</a>
<a href="#179" id="179">179</a>
<a href="#180" id="180">180</a>
<a href="#181" id="181">181</a>
<a href="#182" id="182">182</a>
<a href="#183" id="183">183</a>
<a href="#184" id="184">184</a>
<a href="#185" id="185">185</a>
<a href="#186" id="186">186</a>
<a href="#187" id="187">187</a>
<a href="#188" id="188">188</a>
<a href="#189" id="189">189</a>
<a href="#190" id="190">190</a>
</pre></div><pre class="rust"><code><span class="kw">use </span>core::{mem, slice};
<span class="kw">use </span>byteorder::{ByteOrder, LE};
<span class="doccomment">/// 32-bit MurmurHash3 hasher
</span><span class="kw">pub struct </span>Hasher {
buf: Buffer,
index: Index,
processed: u32,
state: State,
}
<span class="kw">struct </span>State(u32);
<span class="attr">#[derive(Clone, Copy)]
#[repr(align(<span class="number">4</span>))]
</span><span class="kw">struct </span>Buffer {
bytes: [u8; <span class="number">4</span>],
}
<span class="attr">#[derive(Clone, Copy, PartialEq)]
</span><span class="kw">enum </span>Index {
_0,
_1,
_2,
_3,
}
<span class="kw">impl </span>Index {
<span class="kw">fn </span>usize(<span class="kw-2">&amp;</span><span class="self">self</span>) -&gt; usize {
<span class="kw">match </span><span class="kw-2">*</span><span class="self">self </span>{
Index::_0 =&gt; <span class="number">0</span>,
Index::_1 =&gt; <span class="number">1</span>,
Index::_2 =&gt; <span class="number">2</span>,
Index::_3 =&gt; <span class="number">3</span>,
}
}
}
<span class="kw">impl </span>From&lt;usize&gt; <span class="kw">for </span>Index {
<span class="kw">fn </span>from(x: usize) -&gt; <span class="self">Self </span>{
<span class="kw">match </span>x % <span class="number">4 </span>{
<span class="number">0 </span>=&gt; Index::_0,
<span class="number">1 </span>=&gt; Index::_1,
<span class="number">2 </span>=&gt; Index::_2,
<span class="number">3 </span>=&gt; Index::_3,
<span class="kw">_ </span>=&gt; <span class="macro">unreachable!</span>(),
}
}
}
<span class="kw">impl </span>Hasher {
<span class="kw">fn </span>push(<span class="kw-2">&amp;mut </span><span class="self">self</span>, buf: <span class="kw-2">&amp;</span>[u8]) {
<span class="kw">let </span>start = <span class="self">self</span>.index.usize();
<span class="kw">let </span>len = buf.len();
<span class="comment">// NOTE(unsafe) avoid calling `memcpy` on a 0-3 byte copy
// self.buf.bytes[start..start+len].copy_from(buf);
</span><span class="kw">for </span>i <span class="kw">in </span><span class="number">0</span>..len {
<span class="kw">unsafe </span>{
<span class="kw-2">*</span><span class="self">self</span>.buf.bytes.get_unchecked_mut(start + i) = <span class="kw-2">*</span>buf.get_unchecked(i);
}
}
<span class="self">self</span>.index = Index::from(start + len);
}
}
<span class="kw">impl </span>Default <span class="kw">for </span>Hasher {
<span class="attr">#[allow(deprecated)]
</span><span class="kw">fn </span>default() -&gt; <span class="self">Self </span>{
Hasher {
buf: <span class="kw">unsafe </span>{ mem::uninitialized() },
index: Index::_0,
processed: <span class="number">0</span>,
state: State(<span class="number">0</span>),
}
}
}
<span class="kw">impl </span>::Hasher <span class="kw">for </span>Hasher {
<span class="kw">fn </span>finish(<span class="kw-2">&amp;</span><span class="self">self</span>) -&gt; u32 {
<span class="comment">// tail
</span><span class="kw">let </span><span class="kw-2">mut </span>state = <span class="kw">match </span><span class="self">self</span>.index {
Index::_3 =&gt; {
<span class="kw">let </span><span class="kw-2">mut </span>block = <span class="number">0</span>;
block ^= u32::from(<span class="self">self</span>.buf.bytes[<span class="number">2</span>]) &lt;&lt; <span class="number">16</span>;
block ^= u32::from(<span class="self">self</span>.buf.bytes[<span class="number">1</span>]) &lt;&lt; <span class="number">8</span>;
block ^= u32::from(<span class="self">self</span>.buf.bytes[<span class="number">0</span>]);
<span class="self">self</span>.state.<span class="number">0 </span>^ pre_mix(block)
}
Index::_2 =&gt; {
<span class="kw">let </span><span class="kw-2">mut </span>block = <span class="number">0</span>;
block ^= u32::from(<span class="self">self</span>.buf.bytes[<span class="number">1</span>]) &lt;&lt; <span class="number">8</span>;
block ^= u32::from(<span class="self">self</span>.buf.bytes[<span class="number">0</span>]);
<span class="self">self</span>.state.<span class="number">0 </span>^ pre_mix(block)
}
Index::_1 =&gt; {
<span class="kw">let </span><span class="kw-2">mut </span>block = <span class="number">0</span>;
block ^= u32::from(<span class="self">self</span>.buf.bytes[<span class="number">0</span>]);
<span class="self">self</span>.state.<span class="number">0 </span>^ pre_mix(block)
}
Index::_0 =&gt; <span class="self">self</span>.state.<span class="number">0</span>,
};
<span class="comment">// finalization mix
</span>state ^= <span class="self">self</span>.processed;
state ^= state &gt;&gt; <span class="number">16</span>;
state = state.wrapping_mul(<span class="number">0x85ebca6b</span>);
state ^= state &gt;&gt; <span class="number">13</span>;
state = state.wrapping_mul(<span class="number">0xc2b2ae35</span>);
state ^= state &gt;&gt; <span class="number">16</span>;
state
}
<span class="attr">#[inline]
</span><span class="kw">fn </span>write(<span class="kw-2">&amp;mut </span><span class="self">self</span>, bytes: <span class="kw-2">&amp;</span>[u8]) {
<span class="kw">let </span>len = bytes.len();
<span class="self">self</span>.processed += len <span class="kw">as </span>u32;
<span class="kw">let </span>body = <span class="kw">if </span><span class="self">self</span>.index == Index::_0 {
bytes
} <span class="kw">else </span>{
<span class="kw">let </span>index = <span class="self">self</span>.index.usize();
<span class="kw">if </span>len + index &gt;= <span class="number">4 </span>{
<span class="comment">// we can complete a block using the data left in the buffer
// NOTE(unsafe) avoid panicking branch (`slice_index_len_fail`)
// let (head, body) = bytes.split_at(4 - index);
</span><span class="kw">let </span>mid = <span class="number">4 </span>- index;
<span class="kw">let </span>head = <span class="kw">unsafe </span>{ slice::from_raw_parts(bytes.as_ptr(), mid) };
<span class="kw">let </span>body = <span class="kw">unsafe </span>{
slice::from_raw_parts(bytes.as_ptr().offset(mid <span class="kw">as </span>isize), len - mid)
};
<span class="comment">// NOTE(unsafe) avoid calling `memcpy` on a 0-3 byte copy
// self.buf.bytes[index..].copy_from_slice(head);
</span><span class="kw">for </span>i <span class="kw">in </span><span class="number">0</span>..<span class="number">4 </span>- index {
<span class="kw">unsafe </span>{
<span class="kw-2">*</span><span class="self">self</span>.buf.bytes.get_unchecked_mut(index + i) = <span class="kw-2">*</span>head.get_unchecked(i);
}
}
<span class="self">self</span>.index = Index::_0;
<span class="self">self</span>.state.process_block(<span class="kw-2">&amp;</span><span class="self">self</span>.buf.bytes);
body
} <span class="kw">else </span>{
bytes
}
};
<span class="kw">for </span>block <span class="kw">in </span>body.chunks(<span class="number">4</span>) {
<span class="kw">if </span>block.len() == <span class="number">4 </span>{
<span class="self">self</span>.state
.process_block(<span class="kw">unsafe </span>{ <span class="kw-2">&amp;*</span>(block.as_ptr() <span class="kw">as </span><span class="kw-2">*const </span><span class="kw">_</span>) });
} <span class="kw">else </span>{
<span class="self">self</span>.push(block);
}
}
<span class="comment">// XXX is this faster?
// for block in body.exact_chunks(4) {
// self.state
// .process_block(unsafe { &amp;*(block.as_ptr() as *const _) });
// }
// let tail = body.split_at(body.len() / 4 * 4).1;
// self.push(tail);
</span>}
}
<span class="kw">const </span>C1: u32 = <span class="number">0xcc9e2d51</span>;
<span class="kw">const </span>C2: u32 = <span class="number">0x1b873593</span>;
<span class="kw">const </span>R1: u32 = <span class="number">15</span>;
<span class="kw">impl </span>State {
<span class="kw">fn </span>process_block(<span class="kw-2">&amp;mut </span><span class="self">self</span>, block: <span class="kw-2">&amp;</span>[u8; <span class="number">4</span>]) {
<span class="self">self</span>.<span class="number">0 </span>^= pre_mix(LE::read_u32(block));
<span class="self">self</span>.<span class="number">0 </span>= <span class="self">self</span>.<span class="number">0</span>.rotate_left(<span class="number">13</span>);
<span class="self">self</span>.<span class="number">0 </span>= <span class="number">5u32</span>.wrapping_mul(<span class="self">self</span>.<span class="number">0</span>).wrapping_add(<span class="number">0xe6546b64</span>);
}
}
<span class="kw">fn </span>pre_mix(<span class="kw-2">mut </span>block: u32) -&gt; u32 {
block = block.wrapping_mul(C1);
block = block.rotate_left(R1);
block = block.wrapping_mul(C2);
block
}
</code></pre></div></section></main></body></html>

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1,867 +0,0 @@
<!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="Source of the Rust file `/home/zenn/.cargo/registry/src/index.crates.io-6f17d22bba15001f/heapless-0.7.16/src/histbuf.rs`."><title>histbuf.rs - source</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-47e7ab555ef2818a.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="heapless" data-themes="" data-resource-suffix="" data-rustdoc-version="1.74.0-nightly (d9c8274fb 2023-09-12)" data-channel="nightly" data-search-js="search-5d3eaacf19ebf04f.js" data-settings-js="settings-74424d7eec62a23e.js" data-settings-css="settings-8c76f75bfb6bd192.css" data-theme-light-css="light-f194925aa375ae96.css" data-theme-dark-css="dark-1dd4d1ce031e15de.css" data-theme-ayu-css="ayu-49e58d069f567085.css" ><script src="../../static.files/storage-db41da1a38ea3cb8.js"></script><script defer src="../../static.files/src-script-3280b574d94e47b4.js"></script><script defer src="../../src-files.js"></script><script defer src="../../static.files/main-8d035c8cea6edbc4.js"></script><noscript><link rel="stylesheet" media="(prefers-color-scheme:light)" href="../../static.files/light-f194925aa375ae96.css"><link rel="stylesheet" media="(prefers-color-scheme:dark)" href="../../static.files/dark-1dd4d1ce031e15de.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 src"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"></nav><main><nav class="sub"><a class="sub-logo-container" href="../../heapless/index.html"><img class="rust-logo" src="../../static.files/rust-logo-151179464ae7ed46.svg" alt="logo"></a><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="example-wrap"><div data-nosnippet><pre class="src-line-numbers"><a href="#1" id="1">1</a>
<a href="#2" id="2">2</a>
<a href="#3" id="3">3</a>
<a href="#4" id="4">4</a>
<a href="#5" id="5">5</a>
<a href="#6" id="6">6</a>
<a href="#7" id="7">7</a>
<a href="#8" id="8">8</a>
<a href="#9" id="9">9</a>
<a href="#10" id="10">10</a>
<a href="#11" id="11">11</a>
<a href="#12" id="12">12</a>
<a href="#13" id="13">13</a>
<a href="#14" id="14">14</a>
<a href="#15" id="15">15</a>
<a href="#16" id="16">16</a>
<a href="#17" id="17">17</a>
<a href="#18" id="18">18</a>
<a href="#19" id="19">19</a>
<a href="#20" id="20">20</a>
<a href="#21" id="21">21</a>
<a href="#22" id="22">22</a>
<a href="#23" id="23">23</a>
<a href="#24" id="24">24</a>
<a href="#25" id="25">25</a>
<a href="#26" id="26">26</a>
<a href="#27" id="27">27</a>
<a href="#28" id="28">28</a>
<a href="#29" id="29">29</a>
<a href="#30" id="30">30</a>
<a href="#31" id="31">31</a>
<a href="#32" id="32">32</a>
<a href="#33" id="33">33</a>
<a href="#34" id="34">34</a>
<a href="#35" id="35">35</a>
<a href="#36" id="36">36</a>
<a href="#37" id="37">37</a>
<a href="#38" id="38">38</a>
<a href="#39" id="39">39</a>
<a href="#40" id="40">40</a>
<a href="#41" id="41">41</a>
<a href="#42" id="42">42</a>
<a href="#43" id="43">43</a>
<a href="#44" id="44">44</a>
<a href="#45" id="45">45</a>
<a href="#46" id="46">46</a>
<a href="#47" id="47">47</a>
<a href="#48" id="48">48</a>
<a href="#49" id="49">49</a>
<a href="#50" id="50">50</a>
<a href="#51" id="51">51</a>
<a href="#52" id="52">52</a>
<a href="#53" id="53">53</a>
<a href="#54" id="54">54</a>
<a href="#55" id="55">55</a>
<a href="#56" id="56">56</a>
<a href="#57" id="57">57</a>
<a href="#58" id="58">58</a>
<a href="#59" id="59">59</a>
<a href="#60" id="60">60</a>
<a href="#61" id="61">61</a>
<a href="#62" id="62">62</a>
<a href="#63" id="63">63</a>
<a href="#64" id="64">64</a>
<a href="#65" id="65">65</a>
<a href="#66" id="66">66</a>
<a href="#67" id="67">67</a>
<a href="#68" id="68">68</a>
<a href="#69" id="69">69</a>
<a href="#70" id="70">70</a>
<a href="#71" id="71">71</a>
<a href="#72" id="72">72</a>
<a href="#73" id="73">73</a>
<a href="#74" id="74">74</a>
<a href="#75" id="75">75</a>
<a href="#76" id="76">76</a>
<a href="#77" id="77">77</a>
<a href="#78" id="78">78</a>
<a href="#79" id="79">79</a>
<a href="#80" id="80">80</a>
<a href="#81" id="81">81</a>
<a href="#82" id="82">82</a>
<a href="#83" id="83">83</a>
<a href="#84" id="84">84</a>
<a href="#85" id="85">85</a>
<a href="#86" id="86">86</a>
<a href="#87" id="87">87</a>
<a href="#88" id="88">88</a>
<a href="#89" id="89">89</a>
<a href="#90" id="90">90</a>
<a href="#91" id="91">91</a>
<a href="#92" id="92">92</a>
<a href="#93" id="93">93</a>
<a href="#94" id="94">94</a>
<a href="#95" id="95">95</a>
<a href="#96" id="96">96</a>
<a href="#97" id="97">97</a>
<a href="#98" id="98">98</a>
<a href="#99" id="99">99</a>
<a href="#100" id="100">100</a>
<a href="#101" id="101">101</a>
<a href="#102" id="102">102</a>
<a href="#103" id="103">103</a>
<a href="#104" id="104">104</a>
<a href="#105" id="105">105</a>
<a href="#106" id="106">106</a>
<a href="#107" id="107">107</a>
<a href="#108" id="108">108</a>
<a href="#109" id="109">109</a>
<a href="#110" id="110">110</a>
<a href="#111" id="111">111</a>
<a href="#112" id="112">112</a>
<a href="#113" id="113">113</a>
<a href="#114" id="114">114</a>
<a href="#115" id="115">115</a>
<a href="#116" id="116">116</a>
<a href="#117" id="117">117</a>
<a href="#118" id="118">118</a>
<a href="#119" id="119">119</a>
<a href="#120" id="120">120</a>
<a href="#121" id="121">121</a>
<a href="#122" id="122">122</a>
<a href="#123" id="123">123</a>
<a href="#124" id="124">124</a>
<a href="#125" id="125">125</a>
<a href="#126" id="126">126</a>
<a href="#127" id="127">127</a>
<a href="#128" id="128">128</a>
<a href="#129" id="129">129</a>
<a href="#130" id="130">130</a>
<a href="#131" id="131">131</a>
<a href="#132" id="132">132</a>
<a href="#133" id="133">133</a>
<a href="#134" id="134">134</a>
<a href="#135" id="135">135</a>
<a href="#136" id="136">136</a>
<a href="#137" id="137">137</a>
<a href="#138" id="138">138</a>
<a href="#139" id="139">139</a>
<a href="#140" id="140">140</a>
<a href="#141" id="141">141</a>
<a href="#142" id="142">142</a>
<a href="#143" id="143">143</a>
<a href="#144" id="144">144</a>
<a href="#145" id="145">145</a>
<a href="#146" id="146">146</a>
<a href="#147" id="147">147</a>
<a href="#148" id="148">148</a>
<a href="#149" id="149">149</a>
<a href="#150" id="150">150</a>
<a href="#151" id="151">151</a>
<a href="#152" id="152">152</a>
<a href="#153" id="153">153</a>
<a href="#154" id="154">154</a>
<a href="#155" id="155">155</a>
<a href="#156" id="156">156</a>
<a href="#157" id="157">157</a>
<a href="#158" id="158">158</a>
<a href="#159" id="159">159</a>
<a href="#160" id="160">160</a>
<a href="#161" id="161">161</a>
<a href="#162" id="162">162</a>
<a href="#163" id="163">163</a>
<a href="#164" id="164">164</a>
<a href="#165" id="165">165</a>
<a href="#166" id="166">166</a>
<a href="#167" id="167">167</a>
<a href="#168" id="168">168</a>
<a href="#169" id="169">169</a>
<a href="#170" id="170">170</a>
<a href="#171" id="171">171</a>
<a href="#172" id="172">172</a>
<a href="#173" id="173">173</a>
<a href="#174" id="174">174</a>
<a href="#175" id="175">175</a>
<a href="#176" id="176">176</a>
<a href="#177" id="177">177</a>
<a href="#178" id="178">178</a>
<a href="#179" id="179">179</a>
<a href="#180" id="180">180</a>
<a href="#181" id="181">181</a>
<a href="#182" id="182">182</a>
<a href="#183" id="183">183</a>
<a href="#184" id="184">184</a>
<a href="#185" id="185">185</a>
<a href="#186" id="186">186</a>
<a href="#187" id="187">187</a>
<a href="#188" id="188">188</a>
<a href="#189" id="189">189</a>
<a href="#190" id="190">190</a>
<a href="#191" id="191">191</a>
<a href="#192" id="192">192</a>
<a href="#193" id="193">193</a>
<a href="#194" id="194">194</a>
<a href="#195" id="195">195</a>
<a href="#196" id="196">196</a>
<a href="#197" id="197">197</a>
<a href="#198" id="198">198</a>
<a href="#199" id="199">199</a>
<a href="#200" id="200">200</a>
<a href="#201" id="201">201</a>
<a href="#202" id="202">202</a>
<a href="#203" id="203">203</a>
<a href="#204" id="204">204</a>
<a href="#205" id="205">205</a>
<a href="#206" id="206">206</a>
<a href="#207" id="207">207</a>
<a href="#208" id="208">208</a>
<a href="#209" id="209">209</a>
<a href="#210" id="210">210</a>
<a href="#211" id="211">211</a>
<a href="#212" id="212">212</a>
<a href="#213" id="213">213</a>
<a href="#214" id="214">214</a>
<a href="#215" id="215">215</a>
<a href="#216" id="216">216</a>
<a href="#217" id="217">217</a>
<a href="#218" id="218">218</a>
<a href="#219" id="219">219</a>
<a href="#220" id="220">220</a>
<a href="#221" id="221">221</a>
<a href="#222" id="222">222</a>
<a href="#223" id="223">223</a>
<a href="#224" id="224">224</a>
<a href="#225" id="225">225</a>
<a href="#226" id="226">226</a>
<a href="#227" id="227">227</a>
<a href="#228" id="228">228</a>
<a href="#229" id="229">229</a>
<a href="#230" id="230">230</a>
<a href="#231" id="231">231</a>
<a href="#232" id="232">232</a>
<a href="#233" id="233">233</a>
<a href="#234" id="234">234</a>
<a href="#235" id="235">235</a>
<a href="#236" id="236">236</a>
<a href="#237" id="237">237</a>
<a href="#238" id="238">238</a>
<a href="#239" id="239">239</a>
<a href="#240" id="240">240</a>
<a href="#241" id="241">241</a>
<a href="#242" id="242">242</a>
<a href="#243" id="243">243</a>
<a href="#244" id="244">244</a>
<a href="#245" id="245">245</a>
<a href="#246" id="246">246</a>
<a href="#247" id="247">247</a>
<a href="#248" id="248">248</a>
<a href="#249" id="249">249</a>
<a href="#250" id="250">250</a>
<a href="#251" id="251">251</a>
<a href="#252" id="252">252</a>
<a href="#253" id="253">253</a>
<a href="#254" id="254">254</a>
<a href="#255" id="255">255</a>
<a href="#256" id="256">256</a>
<a href="#257" id="257">257</a>
<a href="#258" id="258">258</a>
<a href="#259" id="259">259</a>
<a href="#260" id="260">260</a>
<a href="#261" id="261">261</a>
<a href="#262" id="262">262</a>
<a href="#263" id="263">263</a>
<a href="#264" id="264">264</a>
<a href="#265" id="265">265</a>
<a href="#266" id="266">266</a>
<a href="#267" id="267">267</a>
<a href="#268" id="268">268</a>
<a href="#269" id="269">269</a>
<a href="#270" id="270">270</a>
<a href="#271" id="271">271</a>
<a href="#272" id="272">272</a>
<a href="#273" id="273">273</a>
<a href="#274" id="274">274</a>
<a href="#275" id="275">275</a>
<a href="#276" id="276">276</a>
<a href="#277" id="277">277</a>
<a href="#278" id="278">278</a>
<a href="#279" id="279">279</a>
<a href="#280" id="280">280</a>
<a href="#281" id="281">281</a>
<a href="#282" id="282">282</a>
<a href="#283" id="283">283</a>
<a href="#284" id="284">284</a>
<a href="#285" id="285">285</a>
<a href="#286" id="286">286</a>
<a href="#287" id="287">287</a>
<a href="#288" id="288">288</a>
<a href="#289" id="289">289</a>
<a href="#290" id="290">290</a>
<a href="#291" id="291">291</a>
<a href="#292" id="292">292</a>
<a href="#293" id="293">293</a>
<a href="#294" id="294">294</a>
<a href="#295" id="295">295</a>
<a href="#296" id="296">296</a>
<a href="#297" id="297">297</a>
<a href="#298" id="298">298</a>
<a href="#299" id="299">299</a>
<a href="#300" id="300">300</a>
<a href="#301" id="301">301</a>
<a href="#302" id="302">302</a>
<a href="#303" id="303">303</a>
<a href="#304" id="304">304</a>
<a href="#305" id="305">305</a>
<a href="#306" id="306">306</a>
<a href="#307" id="307">307</a>
<a href="#308" id="308">308</a>
<a href="#309" id="309">309</a>
<a href="#310" id="310">310</a>
<a href="#311" id="311">311</a>
<a href="#312" id="312">312</a>
<a href="#313" id="313">313</a>
<a href="#314" id="314">314</a>
<a href="#315" id="315">315</a>
<a href="#316" id="316">316</a>
<a href="#317" id="317">317</a>
<a href="#318" id="318">318</a>
<a href="#319" id="319">319</a>
<a href="#320" id="320">320</a>
<a href="#321" id="321">321</a>
<a href="#322" id="322">322</a>
<a href="#323" id="323">323</a>
<a href="#324" id="324">324</a>
<a href="#325" id="325">325</a>
<a href="#326" id="326">326</a>
<a href="#327" id="327">327</a>
<a href="#328" id="328">328</a>
<a href="#329" id="329">329</a>
<a href="#330" id="330">330</a>
<a href="#331" id="331">331</a>
<a href="#332" id="332">332</a>
<a href="#333" id="333">333</a>
<a href="#334" id="334">334</a>
<a href="#335" id="335">335</a>
<a href="#336" id="336">336</a>
<a href="#337" id="337">337</a>
<a href="#338" id="338">338</a>
<a href="#339" id="339">339</a>
<a href="#340" id="340">340</a>
<a href="#341" id="341">341</a>
<a href="#342" id="342">342</a>
<a href="#343" id="343">343</a>
<a href="#344" id="344">344</a>
<a href="#345" id="345">345</a>
<a href="#346" id="346">346</a>
<a href="#347" id="347">347</a>
<a href="#348" id="348">348</a>
<a href="#349" id="349">349</a>
<a href="#350" id="350">350</a>
<a href="#351" id="351">351</a>
<a href="#352" id="352">352</a>
<a href="#353" id="353">353</a>
<a href="#354" id="354">354</a>
<a href="#355" id="355">355</a>
<a href="#356" id="356">356</a>
<a href="#357" id="357">357</a>
<a href="#358" id="358">358</a>
<a href="#359" id="359">359</a>
<a href="#360" id="360">360</a>
<a href="#361" id="361">361</a>
<a href="#362" id="362">362</a>
<a href="#363" id="363">363</a>
<a href="#364" id="364">364</a>
<a href="#365" id="365">365</a>
<a href="#366" id="366">366</a>
<a href="#367" id="367">367</a>
<a href="#368" id="368">368</a>
<a href="#369" id="369">369</a>
<a href="#370" id="370">370</a>
<a href="#371" id="371">371</a>
<a href="#372" id="372">372</a>
<a href="#373" id="373">373</a>
<a href="#374" id="374">374</a>
<a href="#375" id="375">375</a>
<a href="#376" id="376">376</a>
<a href="#377" id="377">377</a>
<a href="#378" id="378">378</a>
<a href="#379" id="379">379</a>
<a href="#380" id="380">380</a>
<a href="#381" id="381">381</a>
<a href="#382" id="382">382</a>
<a href="#383" id="383">383</a>
<a href="#384" id="384">384</a>
<a href="#385" id="385">385</a>
<a href="#386" id="386">386</a>
<a href="#387" id="387">387</a>
<a href="#388" id="388">388</a>
<a href="#389" id="389">389</a>
<a href="#390" id="390">390</a>
<a href="#391" id="391">391</a>
<a href="#392" id="392">392</a>
<a href="#393" id="393">393</a>
<a href="#394" id="394">394</a>
<a href="#395" id="395">395</a>
<a href="#396" id="396">396</a>
<a href="#397" id="397">397</a>
<a href="#398" id="398">398</a>
<a href="#399" id="399">399</a>
<a href="#400" id="400">400</a>
<a href="#401" id="401">401</a>
<a href="#402" id="402">402</a>
<a href="#403" id="403">403</a>
<a href="#404" id="404">404</a>
<a href="#405" id="405">405</a>
<a href="#406" id="406">406</a>
<a href="#407" id="407">407</a>
<a href="#408" id="408">408</a>
<a href="#409" id="409">409</a>
<a href="#410" id="410">410</a>
<a href="#411" id="411">411</a>
<a href="#412" id="412">412</a>
<a href="#413" id="413">413</a>
<a href="#414" id="414">414</a>
<a href="#415" id="415">415</a>
<a href="#416" id="416">416</a>
<a href="#417" id="417">417</a>
<a href="#418" id="418">418</a>
<a href="#419" id="419">419</a>
<a href="#420" id="420">420</a>
<a href="#421" id="421">421</a>
<a href="#422" id="422">422</a>
<a href="#423" id="423">423</a>
<a href="#424" id="424">424</a>
<a href="#425" id="425">425</a>
<a href="#426" id="426">426</a>
<a href="#427" id="427">427</a>
<a href="#428" id="428">428</a>
<a href="#429" id="429">429</a>
<a href="#430" id="430">430</a>
<a href="#431" id="431">431</a>
<a href="#432" id="432">432</a>
<a href="#433" id="433">433</a>
</pre></div><pre class="rust"><code><span class="kw">use </span>core::fmt;
<span class="kw">use </span>core::mem::MaybeUninit;
<span class="kw">use </span>core::ops::Deref;
<span class="kw">use </span>core::ptr;
<span class="kw">use </span>core::slice;
<span class="doccomment">/// A &quot;history buffer&quot;, similar to a write-only ring buffer of fixed length.
///
/// This buffer keeps a fixed number of elements. On write, the oldest element
/// is overwritten. Thus, the buffer is useful to keep a history of values with
/// some desired depth, and for example calculate a rolling average.
///
/// # Examples
/// ```
/// use heapless::HistoryBuffer;
///
/// // Initialize a new buffer with 8 elements.
/// let mut buf = HistoryBuffer::&lt;_, 8&gt;::new();
///
/// // Starts with no data
/// assert_eq!(buf.recent(), None);
///
/// buf.write(3);
/// buf.write(5);
/// buf.extend(&amp;[4, 4]);
///
/// // The most recent written element is a four.
/// assert_eq!(buf.recent(), Some(&amp;4));
///
/// // To access all elements in an unspecified order, use `as_slice()`.
/// for el in buf.as_slice() { println!(&quot;{:?}&quot;, el); }
///
/// // Now we can prepare an average of all values, which comes out to 4.
/// let avg = buf.as_slice().iter().sum::&lt;usize&gt;() / buf.len();
/// assert_eq!(avg, 4);
/// ```
</span><span class="kw">pub struct </span>HistoryBuffer&lt;T, <span class="kw">const </span>N: usize&gt; {
data: [MaybeUninit&lt;T&gt;; N],
write_at: usize,
filled: bool,
}
<span class="kw">impl</span>&lt;T, <span class="kw">const </span>N: usize&gt; HistoryBuffer&lt;T, N&gt; {
<span class="kw">const </span>INIT: MaybeUninit&lt;T&gt; = MaybeUninit::uninit();
<span class="doccomment">/// Constructs a new history buffer.
///
/// The construction of a `HistoryBuffer` works in `const` contexts.
///
/// # Examples
///
/// ```
/// use heapless::HistoryBuffer;
///
/// // Allocate a 16-element buffer on the stack
/// let x: HistoryBuffer&lt;u8, 16&gt; = HistoryBuffer::new();
/// assert_eq!(x.len(), 0);
/// ```
</span><span class="attr">#[inline]
</span><span class="kw">pub const fn </span>new() -&gt; <span class="self">Self </span>{
<span class="comment">// Const assert
</span><span class="kw">crate</span>::sealed::greater_than_0::&lt;N&gt;();
<span class="self">Self </span>{
data: [<span class="self">Self</span>::INIT; N],
write_at: <span class="number">0</span>,
filled: <span class="bool-val">false</span>,
}
}
<span class="doccomment">/// Clears the buffer, replacing every element with the default value of
/// type `T`.
</span><span class="kw">pub fn </span>clear(<span class="kw-2">&amp;mut </span><span class="self">self</span>) {
<span class="kw-2">*</span><span class="self">self </span>= <span class="self">Self</span>::new();
}
}
<span class="kw">impl</span>&lt;T, <span class="kw">const </span>N: usize&gt; HistoryBuffer&lt;T, N&gt;
<span class="kw">where
</span>T: Copy + Clone,
{
<span class="doccomment">/// Constructs a new history buffer, where every element is the given value.
///
/// # Examples
///
/// ```
/// use heapless::HistoryBuffer;
///
/// // Allocate a 16-element buffer on the stack
/// let mut x: HistoryBuffer&lt;u8, 16&gt; = HistoryBuffer::new_with(4);
/// // All elements are four
/// assert_eq!(x.as_slice(), [4; 16]);
/// ```
</span><span class="attr">#[inline]
</span><span class="kw">pub fn </span>new_with(t: T) -&gt; <span class="self">Self </span>{
<span class="self">Self </span>{
data: [MaybeUninit::new(t); N],
write_at: <span class="number">0</span>,
filled: <span class="bool-val">true</span>,
}
}
<span class="doccomment">/// Clears the buffer, replacing every element with the given value.
</span><span class="kw">pub fn </span>clear_with(<span class="kw-2">&amp;mut </span><span class="self">self</span>, t: T) {
<span class="kw-2">*</span><span class="self">self </span>= <span class="self">Self</span>::new_with(t);
}
}
<span class="kw">impl</span>&lt;T, <span class="kw">const </span>N: usize&gt; HistoryBuffer&lt;T, N&gt; {
<span class="doccomment">/// Returns the current fill level of the buffer.
</span><span class="attr">#[inline]
</span><span class="kw">pub fn </span>len(<span class="kw-2">&amp;</span><span class="self">self</span>) -&gt; usize {
<span class="kw">if </span><span class="self">self</span>.filled {
N
} <span class="kw">else </span>{
<span class="self">self</span>.write_at
}
}
<span class="doccomment">/// Returns the capacity of the buffer, which is the length of the
/// underlying backing array.
</span><span class="attr">#[inline]
</span><span class="kw">pub fn </span>capacity(<span class="kw-2">&amp;</span><span class="self">self</span>) -&gt; usize {
N
}
<span class="doccomment">/// Writes an element to the buffer, overwriting the oldest value.
</span><span class="kw">pub fn </span>write(<span class="kw-2">&amp;mut </span><span class="self">self</span>, t: T) {
<span class="kw">if </span><span class="self">self</span>.filled {
<span class="comment">// Drop the old before we overwrite it.
</span><span class="kw">unsafe </span>{ ptr::drop_in_place(<span class="self">self</span>.data[<span class="self">self</span>.write_at].as_mut_ptr()) }
}
<span class="self">self</span>.data[<span class="self">self</span>.write_at] = MaybeUninit::new(t);
<span class="self">self</span>.write_at += <span class="number">1</span>;
<span class="kw">if </span><span class="self">self</span>.write_at == <span class="self">self</span>.capacity() {
<span class="self">self</span>.write_at = <span class="number">0</span>;
<span class="self">self</span>.filled = <span class="bool-val">true</span>;
}
}
<span class="doccomment">/// Clones and writes all elements in a slice to the buffer.
///
/// If the slice is longer than the buffer, only the last `self.len()`
/// elements will actually be stored.
</span><span class="kw">pub fn </span>extend_from_slice(<span class="kw-2">&amp;mut </span><span class="self">self</span>, other: <span class="kw-2">&amp;</span>[T])
<span class="kw">where
</span>T: Clone,
{
<span class="kw">for </span>item <span class="kw">in </span>other {
<span class="self">self</span>.write(item.clone());
}
}
<span class="doccomment">/// Returns a reference to the most recently written value.
///
/// # Examples
///
/// ```
/// use heapless::HistoryBuffer;
///
/// let mut x: HistoryBuffer&lt;u8, 16&gt; = HistoryBuffer::new();
/// x.write(4);
/// x.write(10);
/// assert_eq!(x.recent(), Some(&amp;10));
/// ```
</span><span class="kw">pub fn </span>recent(<span class="kw-2">&amp;</span><span class="self">self</span>) -&gt; <span class="prelude-ty">Option</span>&lt;<span class="kw-2">&amp;</span>T&gt; {
<span class="kw">if </span><span class="self">self</span>.write_at == <span class="number">0 </span>{
<span class="kw">if </span><span class="self">self</span>.filled {
<span class="prelude-val">Some</span>(<span class="kw">unsafe </span>{ <span class="kw-2">&amp;*</span><span class="self">self</span>.data[<span class="self">self</span>.capacity() - <span class="number">1</span>].as_ptr() })
} <span class="kw">else </span>{
<span class="prelude-val">None
</span>}
} <span class="kw">else </span>{
<span class="prelude-val">Some</span>(<span class="kw">unsafe </span>{ <span class="kw-2">&amp;*</span><span class="self">self</span>.data[<span class="self">self</span>.write_at - <span class="number">1</span>].as_ptr() })
}
}
<span class="doccomment">/// Returns the array slice backing the buffer, without keeping track
/// of the write position. Therefore, the element order is unspecified.
</span><span class="kw">pub fn </span>as_slice(<span class="kw-2">&amp;</span><span class="self">self</span>) -&gt; <span class="kw-2">&amp;</span>[T] {
<span class="kw">unsafe </span>{ slice::from_raw_parts(<span class="self">self</span>.data.as_ptr() <span class="kw">as </span><span class="kw-2">*const </span><span class="kw">_</span>, <span class="self">self</span>.len()) }
}
<span class="doccomment">/// Returns an iterator for iterating over the buffer from oldest to newest.
///
/// # Examples
///
/// ```
/// use heapless::HistoryBuffer;
///
/// let mut buffer: HistoryBuffer&lt;u8, 6&gt; = HistoryBuffer::new();
/// buffer.extend([0, 0, 0, 1, 2, 3, 4, 5, 6]);
/// let expected = [1, 2, 3, 4, 5, 6];
/// for (x, y) in buffer.oldest_ordered().zip(expected.iter()) {
/// assert_eq!(x, y)
/// }
///
/// ```
</span><span class="kw">pub fn </span>oldest_ordered&lt;<span class="lifetime">&#39;a</span>&gt;(<span class="kw-2">&amp;</span><span class="lifetime">&#39;a </span><span class="self">self</span>) -&gt; OldestOrdered&lt;<span class="lifetime">&#39;a</span>, T, N&gt; {
<span class="kw">if </span><span class="self">self</span>.filled {
OldestOrdered {
buf: <span class="self">self</span>,
cur: <span class="self">self</span>.write_at,
wrapped: <span class="bool-val">false</span>,
}
} <span class="kw">else </span>{
<span class="comment">// special case: act like we wrapped already to handle empty buffer.
</span>OldestOrdered {
buf: <span class="self">self</span>,
cur: <span class="number">0</span>,
wrapped: <span class="bool-val">true</span>,
}
}
}
}
<span class="kw">impl</span>&lt;T, <span class="kw">const </span>N: usize&gt; Extend&lt;T&gt; <span class="kw">for </span>HistoryBuffer&lt;T, N&gt; {
<span class="kw">fn </span>extend&lt;I&gt;(<span class="kw-2">&amp;mut </span><span class="self">self</span>, iter: I)
<span class="kw">where
</span>I: IntoIterator&lt;Item = T&gt;,
{
<span class="kw">for </span>item <span class="kw">in </span>iter.into_iter() {
<span class="self">self</span>.write(item);
}
}
}
<span class="kw">impl</span>&lt;<span class="lifetime">&#39;a</span>, T, <span class="kw">const </span>N: usize&gt; Extend&lt;<span class="kw-2">&amp;</span><span class="lifetime">&#39;a </span>T&gt; <span class="kw">for </span>HistoryBuffer&lt;T, N&gt;
<span class="kw">where
</span>T: <span class="lifetime">&#39;a </span>+ Clone,
{
<span class="kw">fn </span>extend&lt;I&gt;(<span class="kw-2">&amp;mut </span><span class="self">self</span>, iter: I)
<span class="kw">where
</span>I: IntoIterator&lt;Item = <span class="kw-2">&amp;</span><span class="lifetime">&#39;a </span>T&gt;,
{
<span class="self">self</span>.extend(iter.into_iter().cloned())
}
}
<span class="kw">impl</span>&lt;T, <span class="kw">const </span>N: usize&gt; Drop <span class="kw">for </span>HistoryBuffer&lt;T, N&gt; {
<span class="kw">fn </span>drop(<span class="kw-2">&amp;mut </span><span class="self">self</span>) {
<span class="kw">unsafe </span>{
ptr::drop_in_place(ptr::slice_from_raw_parts_mut(
<span class="self">self</span>.data.as_mut_ptr() <span class="kw">as </span><span class="kw-2">*mut </span>T,
<span class="self">self</span>.len(),
))
}
}
}
<span class="kw">impl</span>&lt;T, <span class="kw">const </span>N: usize&gt; Deref <span class="kw">for </span>HistoryBuffer&lt;T, N&gt; {
<span class="kw">type </span>Target = [T];
<span class="kw">fn </span>deref(<span class="kw-2">&amp;</span><span class="self">self</span>) -&gt; <span class="kw-2">&amp;</span>[T] {
<span class="self">self</span>.as_slice()
}
}
<span class="kw">impl</span>&lt;T, <span class="kw">const </span>N: usize&gt; AsRef&lt;[T]&gt; <span class="kw">for </span>HistoryBuffer&lt;T, N&gt; {
<span class="attr">#[inline]
</span><span class="kw">fn </span>as_ref(<span class="kw-2">&amp;</span><span class="self">self</span>) -&gt; <span class="kw-2">&amp;</span>[T] {
<span class="self">self
</span>}
}
<span class="kw">impl</span>&lt;T, <span class="kw">const </span>N: usize&gt; fmt::Debug <span class="kw">for </span>HistoryBuffer&lt;T, N&gt;
<span class="kw">where
</span>T: fmt::Debug,
{
<span class="kw">fn </span>fmt(<span class="kw-2">&amp;</span><span class="self">self</span>, f: <span class="kw-2">&amp;mut </span>fmt::Formatter&lt;<span class="lifetime">&#39;_</span>&gt;) -&gt; fmt::Result {
&lt;[T] <span class="kw">as </span>fmt::Debug&gt;::fmt(<span class="self">self</span>, f)
}
}
<span class="kw">impl</span>&lt;T, <span class="kw">const </span>N: usize&gt; Default <span class="kw">for </span>HistoryBuffer&lt;T, N&gt; {
<span class="kw">fn </span>default() -&gt; <span class="self">Self </span>{
<span class="self">Self</span>::new()
}
}
<span class="doccomment">/// An iterator on the underlying buffer ordered from oldest data to newest
</span><span class="attr">#[derive(Clone)]
</span><span class="kw">pub struct </span>OldestOrdered&lt;<span class="lifetime">&#39;a</span>, T, <span class="kw">const </span>N: usize&gt; {
buf: <span class="kw-2">&amp;</span><span class="lifetime">&#39;a </span>HistoryBuffer&lt;T, N&gt;,
cur: usize,
wrapped: bool,
}
<span class="kw">impl</span>&lt;<span class="lifetime">&#39;a</span>, T, <span class="kw">const </span>N: usize&gt; Iterator <span class="kw">for </span>OldestOrdered&lt;<span class="lifetime">&#39;a</span>, T, N&gt; {
<span class="kw">type </span>Item = <span class="kw-2">&amp;</span><span class="lifetime">&#39;a </span>T;
<span class="kw">fn </span>next(<span class="kw-2">&amp;mut </span><span class="self">self</span>) -&gt; <span class="prelude-ty">Option</span>&lt;<span class="kw-2">&amp;</span><span class="lifetime">&#39;a </span>T&gt; {
<span class="kw">if </span><span class="self">self</span>.cur == <span class="self">self</span>.buf.len() &amp;&amp; <span class="self">self</span>.buf.filled {
<span class="comment">// roll-over
</span><span class="self">self</span>.cur = <span class="number">0</span>;
<span class="self">self</span>.wrapped = <span class="bool-val">true</span>;
}
<span class="kw">if </span><span class="self">self</span>.cur == <span class="self">self</span>.buf.write_at &amp;&amp; <span class="self">self</span>.wrapped {
<span class="kw">return </span><span class="prelude-val">None</span>;
}
<span class="kw">let </span>item = <span class="kw-2">&amp;</span><span class="self">self</span>.buf[<span class="self">self</span>.cur];
<span class="self">self</span>.cur += <span class="number">1</span>;
<span class="prelude-val">Some</span>(item)
}
}
<span class="attr">#[cfg(test)]
</span><span class="kw">mod </span>tests {
<span class="kw">use </span><span class="kw">crate</span>::HistoryBuffer;
<span class="kw">use </span>core::fmt::Debug;
<span class="attr">#[test]
</span><span class="kw">fn </span>new() {
<span class="kw">let </span>x: HistoryBuffer&lt;u8, <span class="number">4</span>&gt; = HistoryBuffer::new_with(<span class="number">1</span>);
<span class="macro">assert_eq!</span>(x.len(), <span class="number">4</span>);
<span class="macro">assert_eq!</span>(x.as_slice(), [<span class="number">1</span>; <span class="number">4</span>]);
<span class="macro">assert_eq!</span>(<span class="kw-2">*</span>x, [<span class="number">1</span>; <span class="number">4</span>]);
<span class="kw">let </span>x: HistoryBuffer&lt;u8, <span class="number">4</span>&gt; = HistoryBuffer::new();
<span class="macro">assert_eq!</span>(x.as_slice(), []);
}
<span class="attr">#[test]
</span><span class="kw">fn </span>write() {
<span class="kw">let </span><span class="kw-2">mut </span>x: HistoryBuffer&lt;u8, <span class="number">4</span>&gt; = HistoryBuffer::new();
x.write(<span class="number">1</span>);
x.write(<span class="number">4</span>);
<span class="macro">assert_eq!</span>(x.as_slice(), [<span class="number">1</span>, <span class="number">4</span>]);
x.write(<span class="number">5</span>);
x.write(<span class="number">6</span>);
x.write(<span class="number">10</span>);
<span class="macro">assert_eq!</span>(x.as_slice(), [<span class="number">10</span>, <span class="number">4</span>, <span class="number">5</span>, <span class="number">6</span>]);
x.extend([<span class="number">11</span>, <span class="number">12</span>].iter());
<span class="macro">assert_eq!</span>(x.as_slice(), [<span class="number">10</span>, <span class="number">11</span>, <span class="number">12</span>, <span class="number">6</span>]);
}
<span class="attr">#[test]
</span><span class="kw">fn </span>clear() {
<span class="kw">let </span><span class="kw-2">mut </span>x: HistoryBuffer&lt;u8, <span class="number">4</span>&gt; = HistoryBuffer::new_with(<span class="number">1</span>);
x.clear();
<span class="macro">assert_eq!</span>(x.as_slice(), []);
<span class="kw">let </span><span class="kw-2">mut </span>x: HistoryBuffer&lt;u8, <span class="number">4</span>&gt; = HistoryBuffer::new();
x.clear_with(<span class="number">1</span>);
<span class="macro">assert_eq!</span>(x.as_slice(), [<span class="number">1</span>; <span class="number">4</span>]);
}
<span class="attr">#[test]
</span><span class="kw">fn </span>recent() {
<span class="kw">let </span><span class="kw-2">mut </span>x: HistoryBuffer&lt;u8, <span class="number">4</span>&gt; = HistoryBuffer::new();
<span class="macro">assert_eq!</span>(x.recent(), <span class="prelude-val">None</span>);
x.write(<span class="number">1</span>);
x.write(<span class="number">4</span>);
<span class="macro">assert_eq!</span>(x.recent(), <span class="prelude-val">Some</span>(<span class="kw-2">&amp;</span><span class="number">4</span>));
x.write(<span class="number">5</span>);
x.write(<span class="number">6</span>);
x.write(<span class="number">10</span>);
<span class="macro">assert_eq!</span>(x.recent(), <span class="prelude-val">Some</span>(<span class="kw-2">&amp;</span><span class="number">10</span>));
}
<span class="attr">#[test]
</span><span class="kw">fn </span>as_slice() {
<span class="kw">let </span><span class="kw-2">mut </span>x: HistoryBuffer&lt;u8, <span class="number">4</span>&gt; = HistoryBuffer::new();
<span class="macro">assert_eq!</span>(x.as_slice(), []);
x.extend([<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>].iter());
<span class="macro">assert_eq!</span>(x.as_slice(), [<span class="number">5</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>]);
}
<span class="attr">#[test]
</span><span class="kw">fn </span>ordered() {
<span class="comment">// test on an empty buffer
</span><span class="kw">let </span>buffer: HistoryBuffer&lt;u8, <span class="number">6</span>&gt; = HistoryBuffer::new();
<span class="kw">let </span><span class="kw-2">mut </span>iter = buffer.oldest_ordered();
<span class="macro">assert_eq!</span>(iter.next(), <span class="prelude-val">None</span>);
<span class="macro">assert_eq!</span>(iter.next(), <span class="prelude-val">None</span>);
<span class="comment">// test on a un-filled buffer
</span><span class="kw">let </span><span class="kw-2">mut </span>buffer: HistoryBuffer&lt;u8, <span class="number">6</span>&gt; = HistoryBuffer::new();
buffer.extend([<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>]);
<span class="macro">assert_eq!</span>(buffer.len(), <span class="number">3</span>);
assert_eq_iter(buffer.oldest_ordered(), <span class="kw-2">&amp;</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>]);
<span class="comment">// test on a filled buffer
</span><span class="kw">let </span><span class="kw-2">mut </span>buffer: HistoryBuffer&lt;u8, <span class="number">6</span>&gt; = HistoryBuffer::new();
buffer.extend([<span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>, <span class="number">6</span>]);
<span class="macro">assert_eq!</span>(buffer.len(), <span class="number">6</span>);
assert_eq_iter(buffer.oldest_ordered(), <span class="kw-2">&amp;</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>, <span class="number">6</span>]);
<span class="comment">// comprehensive test all cases
</span><span class="kw">for </span>n <span class="kw">in </span><span class="number">0</span>..<span class="number">50 </span>{
<span class="kw">const </span>N: usize = <span class="number">7</span>;
<span class="kw">let </span><span class="kw-2">mut </span>buffer: HistoryBuffer&lt;u8, N&gt; = HistoryBuffer::new();
buffer.extend(<span class="number">0</span>..n);
assert_eq_iter(
buffer.oldest_ordered().copied(),
n.saturating_sub(N <span class="kw">as </span>u8)..n,
);
}
}
<span class="doccomment">/// Compares two iterators item by item, making sure they stop at the same time.
</span><span class="kw">fn </span>assert_eq_iter&lt;I: Eq + Debug&gt;(
a: <span class="kw">impl </span>IntoIterator&lt;Item = I&gt;,
b: <span class="kw">impl </span>IntoIterator&lt;Item = I&gt;,
) {
<span class="kw">let </span><span class="kw-2">mut </span>a = a.into_iter();
<span class="kw">let </span><span class="kw-2">mut </span>b = b.into_iter();
<span class="kw">let </span><span class="kw-2">mut </span>i = <span class="number">0</span>;
<span class="kw">loop </span>{
<span class="kw">let </span>a_item = a.next();
<span class="kw">let </span>b_item = b.next();
<span class="macro">assert_eq!</span>(a_item, b_item, <span class="string">&quot;{}&quot;</span>, i);
i += <span class="number">1</span>;
<span class="kw">if </span>b_item.is_none() {
<span class="kw">break</span>;
}
}
}
}
</code></pre></div></section></main></body></html>

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1,239 +0,0 @@
<!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="Source of the Rust file `/home/zenn/.cargo/registry/src/index.crates.io-6f17d22bba15001f/heapless-0.7.16/src/lib.rs`."><title>lib.rs - source</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-47e7ab555ef2818a.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="heapless" data-themes="" data-resource-suffix="" data-rustdoc-version="1.74.0-nightly (d9c8274fb 2023-09-12)" data-channel="nightly" data-search-js="search-5d3eaacf19ebf04f.js" data-settings-js="settings-74424d7eec62a23e.js" data-settings-css="settings-8c76f75bfb6bd192.css" data-theme-light-css="light-f194925aa375ae96.css" data-theme-dark-css="dark-1dd4d1ce031e15de.css" data-theme-ayu-css="ayu-49e58d069f567085.css" ><script src="../../static.files/storage-db41da1a38ea3cb8.js"></script><script defer src="../../static.files/src-script-3280b574d94e47b4.js"></script><script defer src="../../src-files.js"></script><script defer src="../../static.files/main-8d035c8cea6edbc4.js"></script><noscript><link rel="stylesheet" media="(prefers-color-scheme:light)" href="../../static.files/light-f194925aa375ae96.css"><link rel="stylesheet" media="(prefers-color-scheme:dark)" href="../../static.files/dark-1dd4d1ce031e15de.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 src"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"></nav><main><nav class="sub"><a class="sub-logo-container" href="../../heapless/index.html"><img class="rust-logo" src="../../static.files/rust-logo-151179464ae7ed46.svg" alt="logo"></a><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="example-wrap"><div data-nosnippet><pre class="src-line-numbers"><a href="#1" id="1">1</a>
<a href="#2" id="2">2</a>
<a href="#3" id="3">3</a>
<a href="#4" id="4">4</a>
<a href="#5" id="5">5</a>
<a href="#6" id="6">6</a>
<a href="#7" id="7">7</a>
<a href="#8" id="8">8</a>
<a href="#9" id="9">9</a>
<a href="#10" id="10">10</a>
<a href="#11" id="11">11</a>
<a href="#12" id="12">12</a>
<a href="#13" id="13">13</a>
<a href="#14" id="14">14</a>
<a href="#15" id="15">15</a>
<a href="#16" id="16">16</a>
<a href="#17" id="17">17</a>
<a href="#18" id="18">18</a>
<a href="#19" id="19">19</a>
<a href="#20" id="20">20</a>
<a href="#21" id="21">21</a>
<a href="#22" id="22">22</a>
<a href="#23" id="23">23</a>
<a href="#24" id="24">24</a>
<a href="#25" id="25">25</a>
<a href="#26" id="26">26</a>
<a href="#27" id="27">27</a>
<a href="#28" id="28">28</a>
<a href="#29" id="29">29</a>
<a href="#30" id="30">30</a>
<a href="#31" id="31">31</a>
<a href="#32" id="32">32</a>
<a href="#33" id="33">33</a>
<a href="#34" id="34">34</a>
<a href="#35" id="35">35</a>
<a href="#36" id="36">36</a>
<a href="#37" id="37">37</a>
<a href="#38" id="38">38</a>
<a href="#39" id="39">39</a>
<a href="#40" id="40">40</a>
<a href="#41" id="41">41</a>
<a href="#42" id="42">42</a>
<a href="#43" id="43">43</a>
<a href="#44" id="44">44</a>
<a href="#45" id="45">45</a>
<a href="#46" id="46">46</a>
<a href="#47" id="47">47</a>
<a href="#48" id="48">48</a>
<a href="#49" id="49">49</a>
<a href="#50" id="50">50</a>
<a href="#51" id="51">51</a>
<a href="#52" id="52">52</a>
<a href="#53" id="53">53</a>
<a href="#54" id="54">54</a>
<a href="#55" id="55">55</a>
<a href="#56" id="56">56</a>
<a href="#57" id="57">57</a>
<a href="#58" id="58">58</a>
<a href="#59" id="59">59</a>
<a href="#60" id="60">60</a>
<a href="#61" id="61">61</a>
<a href="#62" id="62">62</a>
<a href="#63" id="63">63</a>
<a href="#64" id="64">64</a>
<a href="#65" id="65">65</a>
<a href="#66" id="66">66</a>
<a href="#67" id="67">67</a>
<a href="#68" id="68">68</a>
<a href="#69" id="69">69</a>
<a href="#70" id="70">70</a>
<a href="#71" id="71">71</a>
<a href="#72" id="72">72</a>
<a href="#73" id="73">73</a>
<a href="#74" id="74">74</a>
<a href="#75" id="75">75</a>
<a href="#76" id="76">76</a>
<a href="#77" id="77">77</a>
<a href="#78" id="78">78</a>
<a href="#79" id="79">79</a>
<a href="#80" id="80">80</a>
<a href="#81" id="81">81</a>
<a href="#82" id="82">82</a>
<a href="#83" id="83">83</a>
<a href="#84" id="84">84</a>
<a href="#85" id="85">85</a>
<a href="#86" id="86">86</a>
<a href="#87" id="87">87</a>
<a href="#88" id="88">88</a>
<a href="#89" id="89">89</a>
<a href="#90" id="90">90</a>
<a href="#91" id="91">91</a>
<a href="#92" id="92">92</a>
<a href="#93" id="93">93</a>
<a href="#94" id="94">94</a>
<a href="#95" id="95">95</a>
<a href="#96" id="96">96</a>
<a href="#97" id="97">97</a>
<a href="#98" id="98">98</a>
<a href="#99" id="99">99</a>
<a href="#100" id="100">100</a>
<a href="#101" id="101">101</a>
<a href="#102" id="102">102</a>
<a href="#103" id="103">103</a>
<a href="#104" id="104">104</a>
<a href="#105" id="105">105</a>
<a href="#106" id="106">106</a>
<a href="#107" id="107">107</a>
<a href="#108" id="108">108</a>
<a href="#109" id="109">109</a>
<a href="#110" id="110">110</a>
<a href="#111" id="111">111</a>
<a href="#112" id="112">112</a>
<a href="#113" id="113">113</a>
<a href="#114" id="114">114</a>
<a href="#115" id="115">115</a>
<a href="#116" id="116">116</a>
<a href="#117" id="117">117</a>
<a href="#118" id="118">118</a>
<a href="#119" id="119">119</a>
</pre></div><pre class="rust"><code><span class="doccomment">//! `static` friendly data structures that don&#39;t require dynamic memory allocation
//!
//! The core principle behind `heapless` is that its data structures are backed by a *static* memory
//! allocation. For example, you can think of `heapless::Vec` as an alternative version of
//! `std::Vec` with fixed capacity and that can&#39;t be re-allocated on the fly (e.g. via `push`).
//!
//! All `heapless` data structures store their memory allocation *inline* and specify their capacity
//! via their type parameter `N`. This means that you can instantiate a `heapless` data structure on
//! the stack, in a `static` variable, or even in the heap.
//!
//! ```
//! use heapless::Vec; // fixed capacity `std::Vec`
//!
//! // on the stack
//! let mut xs: Vec&lt;u8, 8&gt; = Vec::new(); // can hold up to 8 elements
//! xs.push(42).unwrap();
//! assert_eq!(xs.pop(), Some(42));
//!
//! // in a `static` variable
//! static mut XS: Vec&lt;u8, 8&gt; = Vec::new();
//!
//! let xs = unsafe { &amp;mut XS };
//!
//! xs.push(42);
//! assert_eq!(xs.pop(), Some(42));
//!
//! // in the heap (though kind of pointless because no reallocation)
//! let mut ys: Box&lt;Vec&lt;u8, 8&gt;&gt; = Box::new(Vec::new());
//! ys.push(42).unwrap();
//! assert_eq!(ys.pop(), Some(42));
//! ```
//!
//! Because they have fixed capacity `heapless` data structures don&#39;t implicitly reallocate. This
//! means that operations like `heapless::Vec.push` are *truly* constant time rather than amortized
//! constant time with potentially unbounded (depends on the allocator) worst case execution time
//! (which is bad / unacceptable for hard real time applications).
//!
//! `heapless` data structures don&#39;t use a memory allocator which means no risk of an uncatchable
//! Out Of Memory (OOM) condition while performing operations on them. It&#39;s certainly possible to
//! run out of capacity while growing `heapless` data structures, but the API lets you handle this
//! possibility by returning a `Result` on operations that may exhaust the capacity of the data
//! structure.
//!
//! List of currently implemented data structures:
//!
//! - [`Arc`](pool/singleton/arc/struct.Arc.html) -- Thread-safe reference-counting pointer backed by a memory pool
//! - [`BinaryHeap`](binary_heap/struct.BinaryHeap.html) -- priority queue
//! - [`IndexMap`](struct.IndexMap.html) -- hash table
//! - [`IndexSet`](struct.IndexSet.html) -- hash set
//! - [`LinearMap`](struct.LinearMap.html)
//! - [`Pool`](pool/struct.Pool.html) -- lock-free memory pool
//! - [`String`](struct.String.html)
//! - [`Vec`](struct.Vec.html)
//! - [`mpmc::Q*`](mpmc/index.html) -- multiple producer multiple consumer lock-free queue
//! - [`spsc::Queue`](spsc/struct.Queue.html) -- single producer single consumer lock-free queue
//!
//! # Optional Features
//!
//! The `heapless` crate provides the following optional Cargo features:
//!
//! - `ufmt-impl`: Implement [`ufmt_write::uWrite`] for `String&lt;N&gt;` and `Vec&lt;u8, N&gt;`
//!
//! [`ufmt_write::uWrite`]: https://docs.rs/ufmt-write/
//!
//! # Minimum Supported Rust Version (MSRV)
//!
//! This crate is guaranteed to compile on stable Rust 1.51 and up with its default set of features.
//! It *might* compile on older versions but that may change in any new patch release.
</span><span class="attr">#![cfg_attr(not(test), no_std)]
#![deny(missing_docs)]
#![deny(rust_2018_compatibility)]
#![deny(rust_2018_idioms)]
#![deny(warnings)]
#![deny(const_err)]
</span><span class="kw">pub use </span>binary_heap::BinaryHeap;
<span class="kw">pub use </span>deque::Deque;
<span class="kw">pub use </span>histbuf::{HistoryBuffer, OldestOrdered};
<span class="kw">pub use </span>indexmap::{Bucket, Entry, FnvIndexMap, IndexMap, OccupiedEntry, Pos, VacantEntry};
<span class="kw">pub use </span>indexset::{FnvIndexSet, IndexSet};
<span class="kw">pub use </span>linear_map::LinearMap;
<span class="attr">#[cfg(all(has_cas, feature = <span class="string">&quot;cas&quot;</span>))]
</span><span class="kw">pub use </span>pool::singleton::arc::Arc;
<span class="kw">pub use </span>string::String;
<span class="kw">pub use </span>vec::Vec;
<span class="attr">#[macro_use]
#[cfg(test)]
</span><span class="kw">mod </span>test_helpers;
<span class="kw">mod </span>deque;
<span class="kw">mod </span>histbuf;
<span class="kw">mod </span>indexmap;
<span class="kw">mod </span>indexset;
<span class="kw">mod </span>linear_map;
<span class="kw">mod </span>string;
<span class="kw">mod </span>vec;
<span class="attr">#[cfg(feature = <span class="string">&quot;serde&quot;</span>)]
</span><span class="kw">mod </span>de;
<span class="attr">#[cfg(feature = <span class="string">&quot;serde&quot;</span>)]
</span><span class="kw">mod </span>ser;
<span class="kw">pub mod </span>binary_heap;
<span class="attr">#[cfg(feature = <span class="string">&quot;defmt-impl&quot;</span>)]
</span><span class="kw">mod </span>defmt;
<span class="attr">#[cfg(all(has_cas, feature = <span class="string">&quot;cas&quot;</span>))]
</span><span class="kw">pub mod </span>mpmc;
<span class="attr">#[cfg(all(has_cas, feature = <span class="string">&quot;cas&quot;</span>))]
</span><span class="kw">pub mod </span>pool;
<span class="kw">pub mod </span>sorted_linked_list;
<span class="attr">#[cfg(has_atomics)]
</span><span class="kw">pub mod </span>spsc;
<span class="attr">#[cfg(feature = <span class="string">&quot;ufmt-impl&quot;</span>)]
</span><span class="kw">mod </span>ufmt;
<span class="kw">mod </span>sealed;
</code></pre></div></section></main></body></html>

File diff suppressed because it is too large Load diff

View file

@ -1,117 +0,0 @@
<!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="Source of the Rust file `/home/zenn/.cargo/registry/src/index.crates.io-6f17d22bba15001f/heapless-0.7.16/src/sealed.rs`."><title>sealed.rs - source</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-47e7ab555ef2818a.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="heapless" data-themes="" data-resource-suffix="" data-rustdoc-version="1.74.0-nightly (d9c8274fb 2023-09-12)" data-channel="nightly" data-search-js="search-5d3eaacf19ebf04f.js" data-settings-js="settings-74424d7eec62a23e.js" data-settings-css="settings-8c76f75bfb6bd192.css" data-theme-light-css="light-f194925aa375ae96.css" data-theme-dark-css="dark-1dd4d1ce031e15de.css" data-theme-ayu-css="ayu-49e58d069f567085.css" ><script src="../../static.files/storage-db41da1a38ea3cb8.js"></script><script defer src="../../static.files/src-script-3280b574d94e47b4.js"></script><script defer src="../../src-files.js"></script><script defer src="../../static.files/main-8d035c8cea6edbc4.js"></script><noscript><link rel="stylesheet" media="(prefers-color-scheme:light)" href="../../static.files/light-f194925aa375ae96.css"><link rel="stylesheet" media="(prefers-color-scheme:dark)" href="../../static.files/dark-1dd4d1ce031e15de.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 src"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"></nav><main><nav class="sub"><a class="sub-logo-container" href="../../heapless/index.html"><img class="rust-logo" src="../../static.files/rust-logo-151179464ae7ed46.svg" alt="logo"></a><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="example-wrap"><div data-nosnippet><pre class="src-line-numbers"><a href="#1" id="1">1</a>
<a href="#2" id="2">2</a>
<a href="#3" id="3">3</a>
<a href="#4" id="4">4</a>
<a href="#5" id="5">5</a>
<a href="#6" id="6">6</a>
<a href="#7" id="7">7</a>
<a href="#8" id="8">8</a>
<a href="#9" id="9">9</a>
<a href="#10" id="10">10</a>
<a href="#11" id="11">11</a>
<a href="#12" id="12">12</a>
<a href="#13" id="13">13</a>
<a href="#14" id="14">14</a>
<a href="#15" id="15">15</a>
<a href="#16" id="16">16</a>
<a href="#17" id="17">17</a>
<a href="#18" id="18">18</a>
<a href="#19" id="19">19</a>
<a href="#20" id="20">20</a>
<a href="#21" id="21">21</a>
<a href="#22" id="22">22</a>
<a href="#23" id="23">23</a>
<a href="#24" id="24">24</a>
<a href="#25" id="25">25</a>
<a href="#26" id="26">26</a>
<a href="#27" id="27">27</a>
<a href="#28" id="28">28</a>
<a href="#29" id="29">29</a>
<a href="#30" id="30">30</a>
<a href="#31" id="31">31</a>
<a href="#32" id="32">32</a>
<a href="#33" id="33">33</a>
<a href="#34" id="34">34</a>
<a href="#35" id="35">35</a>
<a href="#36" id="36">36</a>
<a href="#37" id="37">37</a>
<a href="#38" id="38">38</a>
<a href="#39" id="39">39</a>
<a href="#40" id="40">40</a>
<a href="#41" id="41">41</a>
<a href="#42" id="42">42</a>
<a href="#43" id="43">43</a>
<a href="#44" id="44">44</a>
<a href="#45" id="45">45</a>
<a href="#46" id="46">46</a>
<a href="#47" id="47">47</a>
<a href="#48" id="48">48</a>
<a href="#49" id="49">49</a>
<a href="#50" id="50">50</a>
<a href="#51" id="51">51</a>
<a href="#52" id="52">52</a>
<a href="#53" id="53">53</a>
<a href="#54" id="54">54</a>
<a href="#55" id="55">55</a>
<a href="#56" id="56">56</a>
<a href="#57" id="57">57</a>
<a href="#58" id="58">58</a>
</pre></div><pre class="rust"><code><span class="attr">#[allow(dead_code)]
#[allow(path_statements)]
</span><span class="kw">pub</span>(<span class="kw">crate</span>) <span class="kw">const fn </span>smaller_than&lt;<span class="kw">const </span>N: usize, <span class="kw">const </span>MAX: usize&gt;() {
Assert::&lt;N, MAX&gt;::LESS;
}
<span class="attr">#[allow(dead_code)]
#[allow(path_statements)]
</span><span class="kw">pub</span>(<span class="kw">crate</span>) <span class="kw">const fn </span>greater_than_eq_0&lt;<span class="kw">const </span>N: usize&gt;() {
Assert::&lt;N, <span class="number">0</span>&gt;::GREATER_EQ;
}
<span class="attr">#[allow(dead_code)]
#[allow(path_statements)]
</span><span class="kw">pub</span>(<span class="kw">crate</span>) <span class="kw">const fn </span>greater_than_0&lt;<span class="kw">const </span>N: usize&gt;() {
Assert::&lt;N, <span class="number">0</span>&gt;::GREATER;
}
<span class="attr">#[allow(dead_code)]
#[allow(path_statements)]
</span><span class="kw">pub</span>(<span class="kw">crate</span>) <span class="kw">const fn </span>greater_than_1&lt;<span class="kw">const </span>N: usize&gt;() {
Assert::&lt;N, <span class="number">1</span>&gt;::GREATER;
}
<span class="attr">#[allow(dead_code)]
#[allow(path_statements)]
</span><span class="kw">pub</span>(<span class="kw">crate</span>) <span class="kw">const fn </span>power_of_two&lt;<span class="kw">const </span>N: usize&gt;() {
Assert::&lt;N, <span class="number">0</span>&gt;::GREATER;
Assert::&lt;N, <span class="number">0</span>&gt;::POWER_OF_TWO;
}
<span class="attr">#[allow(dead_code)]
</span><span class="doccomment">/// Const assert hack
</span><span class="kw">pub struct </span>Assert&lt;<span class="kw">const </span>L: usize, <span class="kw">const </span>R: usize&gt;;
<span class="attr">#[allow(dead_code)]
</span><span class="kw">impl</span>&lt;<span class="kw">const </span>L: usize, <span class="kw">const </span>R: usize&gt; Assert&lt;L, R&gt; {
<span class="doccomment">/// Const assert hack
</span><span class="kw">pub const </span>GREATER_EQ: usize = L - R;
<span class="doccomment">/// Const assert hack
</span><span class="kw">pub const </span>LESS_EQ: usize = R - L;
<span class="doccomment">/// Const assert hack
</span><span class="kw">pub const </span>NOT_EQ: isize = <span class="number">0 </span>/ (R <span class="kw">as </span>isize - L <span class="kw">as </span>isize);
<span class="doccomment">/// Const assert hack
</span><span class="kw">pub const </span>EQ: usize = (R - L) + (L - R);
<span class="doccomment">/// Const assert hack
</span><span class="kw">pub const </span>GREATER: usize = L - R - <span class="number">1</span>;
<span class="doccomment">/// Const assert hack
</span><span class="kw">pub const </span>LESS: usize = R - L - <span class="number">1</span>;
<span class="doccomment">/// Const assert hack
</span><span class="kw">pub const </span>POWER_OF_TWO: usize = <span class="number">0 </span>- (L &amp; (L - <span class="number">1</span>));
}
</code></pre></div></section></main></body></html>

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1,71 +0,0 @@
<!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="Source of the Rust file `/home/zenn/.cargo/registry/src/index.crates.io-6f17d22bba15001f/panic-halt-0.2.0/src/lib.rs`."><title>lib.rs - source</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-47e7ab555ef2818a.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="panic_halt" data-themes="" data-resource-suffix="" data-rustdoc-version="1.74.0-nightly (d9c8274fb 2023-09-12)" data-channel="nightly" data-search-js="search-5d3eaacf19ebf04f.js" data-settings-js="settings-74424d7eec62a23e.js" data-settings-css="settings-8c76f75bfb6bd192.css" data-theme-light-css="light-f194925aa375ae96.css" data-theme-dark-css="dark-1dd4d1ce031e15de.css" data-theme-ayu-css="ayu-49e58d069f567085.css" ><script src="../../static.files/storage-db41da1a38ea3cb8.js"></script><script defer src="../../static.files/src-script-3280b574d94e47b4.js"></script><script defer src="../../src-files.js"></script><script defer src="../../static.files/main-8d035c8cea6edbc4.js"></script><noscript><link rel="stylesheet" media="(prefers-color-scheme:light)" href="../../static.files/light-f194925aa375ae96.css"><link rel="stylesheet" media="(prefers-color-scheme:dark)" href="../../static.files/dark-1dd4d1ce031e15de.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 src"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"></nav><main><nav class="sub"><a class="sub-logo-container" href="../../panic_halt/index.html"><img class="rust-logo" src="../../static.files/rust-logo-151179464ae7ed46.svg" alt="logo"></a><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="example-wrap"><div data-nosnippet><pre class="src-line-numbers"><a href="#1" id="1">1</a>
<a href="#2" id="2">2</a>
<a href="#3" id="3">3</a>
<a href="#4" id="4">4</a>
<a href="#5" id="5">5</a>
<a href="#6" id="6">6</a>
<a href="#7" id="7">7</a>
<a href="#8" id="8">8</a>
<a href="#9" id="9">9</a>
<a href="#10" id="10">10</a>
<a href="#11" id="11">11</a>
<a href="#12" id="12">12</a>
<a href="#13" id="13">13</a>
<a href="#14" id="14">14</a>
<a href="#15" id="15">15</a>
<a href="#16" id="16">16</a>
<a href="#17" id="17">17</a>
<a href="#18" id="18">18</a>
<a href="#19" id="19">19</a>
<a href="#20" id="20">20</a>
<a href="#21" id="21">21</a>
<a href="#22" id="22">22</a>
<a href="#23" id="23">23</a>
<a href="#24" id="24">24</a>
<a href="#25" id="25">25</a>
<a href="#26" id="26">26</a>
<a href="#27" id="27">27</a>
<a href="#28" id="28">28</a>
<a href="#29" id="29">29</a>
<a href="#30" id="30">30</a>
<a href="#31" id="31">31</a>
<a href="#32" id="32">32</a>
<a href="#33" id="33">33</a>
<a href="#34" id="34">34</a>
<a href="#35" id="35">35</a>
</pre></div><pre class="rust"><code><span class="doccomment">//! Set the panicking behavior to halt
//!
//! This crate contains an implementation of `panic_fmt` that simply halt in an infinite loop.
//!
//! # Usage
//!
//! ``` ignore
//! #![no_std]
//!
//! extern crate panic_halt;
//!
//! fn main() {
//! panic!(&quot;argument is ignored&quot;);
//! }
//! ```
//!
//! # Breakable symbols
//!
//! With the panic handler being `#[inline(never)]` the symbol `rust_begin_unwind` will be
//! available to place a breakpoint on to halt when a panic is happening.
</span><span class="attr">#![deny(missing_docs)]
#![deny(warnings)]
#![no_std]
</span><span class="kw">use </span>core::panic::PanicInfo;
<span class="kw">use </span>core::sync::atomic::{<span class="self">self</span>, Ordering};
<span class="attr">#[inline(never)]
#[panic_handler]
</span><span class="kw">fn </span>panic(_info: <span class="kw-2">&amp;</span>PanicInfo) -&gt; ! {
<span class="kw">loop </span>{
atomic::compiler_fence(Ordering::SeqCst);
}
}
</code></pre></div></section></main></body></html>

View file

@ -1,379 +0,0 @@
<!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="Source of the Rust file `/home/zenn/.cargo/registry/src/index.crates.io-6f17d22bba15001f/stable_deref_trait-1.2.0/src/lib.rs`."><title>lib.rs - source</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-47e7ab555ef2818a.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="stable_deref_trait" data-themes="" data-resource-suffix="" data-rustdoc-version="1.74.0-nightly (d9c8274fb 2023-09-12)" data-channel="nightly" data-search-js="search-5d3eaacf19ebf04f.js" data-settings-js="settings-74424d7eec62a23e.js" data-settings-css="settings-8c76f75bfb6bd192.css" data-theme-light-css="light-f194925aa375ae96.css" data-theme-dark-css="dark-1dd4d1ce031e15de.css" data-theme-ayu-css="ayu-49e58d069f567085.css" ><script src="../../static.files/storage-db41da1a38ea3cb8.js"></script><script defer src="../../static.files/src-script-3280b574d94e47b4.js"></script><script defer src="../../src-files.js"></script><script defer src="../../static.files/main-8d035c8cea6edbc4.js"></script><noscript><link rel="stylesheet" media="(prefers-color-scheme:light)" href="../../static.files/light-f194925aa375ae96.css"><link rel="stylesheet" media="(prefers-color-scheme:dark)" href="../../static.files/dark-1dd4d1ce031e15de.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 src"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"></nav><main><nav class="sub"><a class="sub-logo-container" href="../../stable_deref_trait/index.html"><img class="rust-logo" src="../../static.files/rust-logo-151179464ae7ed46.svg" alt="logo"></a><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="example-wrap"><div data-nosnippet><pre class="src-line-numbers"><a href="#1" id="1">1</a>
<a href="#2" id="2">2</a>
<a href="#3" id="3">3</a>
<a href="#4" id="4">4</a>
<a href="#5" id="5">5</a>
<a href="#6" id="6">6</a>
<a href="#7" id="7">7</a>
<a href="#8" id="8">8</a>
<a href="#9" id="9">9</a>
<a href="#10" id="10">10</a>
<a href="#11" id="11">11</a>
<a href="#12" id="12">12</a>
<a href="#13" id="13">13</a>
<a href="#14" id="14">14</a>
<a href="#15" id="15">15</a>
<a href="#16" id="16">16</a>
<a href="#17" id="17">17</a>
<a href="#18" id="18">18</a>
<a href="#19" id="19">19</a>
<a href="#20" id="20">20</a>
<a href="#21" id="21">21</a>
<a href="#22" id="22">22</a>
<a href="#23" id="23">23</a>
<a href="#24" id="24">24</a>
<a href="#25" id="25">25</a>
<a href="#26" id="26">26</a>
<a href="#27" id="27">27</a>
<a href="#28" id="28">28</a>
<a href="#29" id="29">29</a>
<a href="#30" id="30">30</a>
<a href="#31" id="31">31</a>
<a href="#32" id="32">32</a>
<a href="#33" id="33">33</a>
<a href="#34" id="34">34</a>
<a href="#35" id="35">35</a>
<a href="#36" id="36">36</a>
<a href="#37" id="37">37</a>
<a href="#38" id="38">38</a>
<a href="#39" id="39">39</a>
<a href="#40" id="40">40</a>
<a href="#41" id="41">41</a>
<a href="#42" id="42">42</a>
<a href="#43" id="43">43</a>
<a href="#44" id="44">44</a>
<a href="#45" id="45">45</a>
<a href="#46" id="46">46</a>
<a href="#47" id="47">47</a>
<a href="#48" id="48">48</a>
<a href="#49" id="49">49</a>
<a href="#50" id="50">50</a>
<a href="#51" id="51">51</a>
<a href="#52" id="52">52</a>
<a href="#53" id="53">53</a>
<a href="#54" id="54">54</a>
<a href="#55" id="55">55</a>
<a href="#56" id="56">56</a>
<a href="#57" id="57">57</a>
<a href="#58" id="58">58</a>
<a href="#59" id="59">59</a>
<a href="#60" id="60">60</a>
<a href="#61" id="61">61</a>
<a href="#62" id="62">62</a>
<a href="#63" id="63">63</a>
<a href="#64" id="64">64</a>
<a href="#65" id="65">65</a>
<a href="#66" id="66">66</a>
<a href="#67" id="67">67</a>
<a href="#68" id="68">68</a>
<a href="#69" id="69">69</a>
<a href="#70" id="70">70</a>
<a href="#71" id="71">71</a>
<a href="#72" id="72">72</a>
<a href="#73" id="73">73</a>
<a href="#74" id="74">74</a>
<a href="#75" id="75">75</a>
<a href="#76" id="76">76</a>
<a href="#77" id="77">77</a>
<a href="#78" id="78">78</a>
<a href="#79" id="79">79</a>
<a href="#80" id="80">80</a>
<a href="#81" id="81">81</a>
<a href="#82" id="82">82</a>
<a href="#83" id="83">83</a>
<a href="#84" id="84">84</a>
<a href="#85" id="85">85</a>
<a href="#86" id="86">86</a>
<a href="#87" id="87">87</a>
<a href="#88" id="88">88</a>
<a href="#89" id="89">89</a>
<a href="#90" id="90">90</a>
<a href="#91" id="91">91</a>
<a href="#92" id="92">92</a>
<a href="#93" id="93">93</a>
<a href="#94" id="94">94</a>
<a href="#95" id="95">95</a>
<a href="#96" id="96">96</a>
<a href="#97" id="97">97</a>
<a href="#98" id="98">98</a>
<a href="#99" id="99">99</a>
<a href="#100" id="100">100</a>
<a href="#101" id="101">101</a>
<a href="#102" id="102">102</a>
<a href="#103" id="103">103</a>
<a href="#104" id="104">104</a>
<a href="#105" id="105">105</a>
<a href="#106" id="106">106</a>
<a href="#107" id="107">107</a>
<a href="#108" id="108">108</a>
<a href="#109" id="109">109</a>
<a href="#110" id="110">110</a>
<a href="#111" id="111">111</a>
<a href="#112" id="112">112</a>
<a href="#113" id="113">113</a>
<a href="#114" id="114">114</a>
<a href="#115" id="115">115</a>
<a href="#116" id="116">116</a>
<a href="#117" id="117">117</a>
<a href="#118" id="118">118</a>
<a href="#119" id="119">119</a>
<a href="#120" id="120">120</a>
<a href="#121" id="121">121</a>
<a href="#122" id="122">122</a>
<a href="#123" id="123">123</a>
<a href="#124" id="124">124</a>
<a href="#125" id="125">125</a>
<a href="#126" id="126">126</a>
<a href="#127" id="127">127</a>
<a href="#128" id="128">128</a>
<a href="#129" id="129">129</a>
<a href="#130" id="130">130</a>
<a href="#131" id="131">131</a>
<a href="#132" id="132">132</a>
<a href="#133" id="133">133</a>
<a href="#134" id="134">134</a>
<a href="#135" id="135">135</a>
<a href="#136" id="136">136</a>
<a href="#137" id="137">137</a>
<a href="#138" id="138">138</a>
<a href="#139" id="139">139</a>
<a href="#140" id="140">140</a>
<a href="#141" id="141">141</a>
<a href="#142" id="142">142</a>
<a href="#143" id="143">143</a>
<a href="#144" id="144">144</a>
<a href="#145" id="145">145</a>
<a href="#146" id="146">146</a>
<a href="#147" id="147">147</a>
<a href="#148" id="148">148</a>
<a href="#149" id="149">149</a>
<a href="#150" id="150">150</a>
<a href="#151" id="151">151</a>
<a href="#152" id="152">152</a>
<a href="#153" id="153">153</a>
<a href="#154" id="154">154</a>
<a href="#155" id="155">155</a>
<a href="#156" id="156">156</a>
<a href="#157" id="157">157</a>
<a href="#158" id="158">158</a>
<a href="#159" id="159">159</a>
<a href="#160" id="160">160</a>
<a href="#161" id="161">161</a>
<a href="#162" id="162">162</a>
<a href="#163" id="163">163</a>
<a href="#164" id="164">164</a>
<a href="#165" id="165">165</a>
<a href="#166" id="166">166</a>
<a href="#167" id="167">167</a>
<a href="#168" id="168">168</a>
<a href="#169" id="169">169</a>
<a href="#170" id="170">170</a>
<a href="#171" id="171">171</a>
<a href="#172" id="172">172</a>
<a href="#173" id="173">173</a>
<a href="#174" id="174">174</a>
<a href="#175" id="175">175</a>
<a href="#176" id="176">176</a>
<a href="#177" id="177">177</a>
<a href="#178" id="178">178</a>
<a href="#179" id="179">179</a>
<a href="#180" id="180">180</a>
<a href="#181" id="181">181</a>
<a href="#182" id="182">182</a>
<a href="#183" id="183">183</a>
<a href="#184" id="184">184</a>
<a href="#185" id="185">185</a>
<a href="#186" id="186">186</a>
<a href="#187" id="187">187</a>
<a href="#188" id="188">188</a>
<a href="#189" id="189">189</a>
</pre></div><pre class="rust"><code><span class="comment">// Copyright 2017 Robert Grosse
// Licensed under the Apache License, Version 2.0 &lt;LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0&gt; or the MIT license
// &lt;LICENSE-MIT or http://opensource.org/licenses/MIT&gt;, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
</span><span class="doccomment">/*!
This module defines an unsafe marker trait, StableDeref, for container types that deref to a fixed address which is valid even when the containing type is moved. For example, Box, Vec, Rc, Arc and String implement this trait. Additionally, it defines CloneStableDeref for types like Rc where clones deref to the same address.
It is intended to be used by crates such as [owning_ref](https://crates.io/crates/owning_ref) and [rental](https://crates.io/crates/rental), as well as library authors who wish to make their code interoperable with such crates. For example, if you write a custom Vec type, you can implement StableDeref, and then users will be able to use your custom type together with owning_ref and rental.
no_std support can be enabled by disabling default features (specifically &quot;std&quot;). In this case, the trait will not be implemented for the std types mentioned above, but you can still use it for your own types.
*/
</span><span class="attr">#![cfg_attr(not(feature = <span class="string">&quot;std&quot;</span>), no_std)]
#[cfg(feature = <span class="string">&quot;std&quot;</span>)]
</span><span class="kw">extern crate </span>core;
<span class="attr">#[cfg(feature = <span class="string">&quot;alloc&quot;</span>)]
</span><span class="kw">extern crate </span>alloc;
<span class="kw">use </span>core::ops::Deref;
<span class="doccomment">/**
An unsafe marker trait for types that deref to a stable address, even when moved. For example, this is implemented by Box, Vec, Rc, Arc and String, among others. Even when a Box is moved, the underlying storage remains at a fixed location.
More specifically, implementors must ensure that the result of calling deref() is valid for the lifetime of the object, not just the lifetime of the borrow, and that the deref is valid even if the object is moved. Also, it must be valid even after invoking arbitrary &amp;self methods or doing anything transitively accessible from &amp;Self. If Self also implements DerefMut, the same restrictions apply to deref_mut() and it must remain valid if anything transitively accessible from the result of deref_mut() is mutated/called. Additionally, multiple calls to deref, (and deref_mut if implemented) must return the same address. No requirements are placed on &amp;mut self methods other than deref_mut() and drop(), if applicable.
Basically, it must be valid to convert the result of deref() to a pointer, and later dereference that pointer, as long as the original object is still live, even if it has been moved or &amp;self methods have been called on it. If DerefMut is also implemented, it must be valid to get pointers from deref() and deref_mut() and dereference them while the object is live, as long as you don&#39;t simultaneously dereference both of them.
Additionally, Deref and DerefMut implementations must not panic, but users of the trait are not allowed to rely on this fact (so that this restriction can be removed later without breaking backwards compatibility, should the need arise).
Here are some examples to help illustrate the requirements for implementing this trait:
```
# use std::ops::Deref;
struct Foo(u8);
impl Deref for Foo {
type Target = u8;
fn deref(&amp;self) -&gt; &amp;Self::Target { &amp;self.0 }
}
```
Foo cannot implement StableDeref because the int will move when Foo is moved, invalidating the result of deref().
```
# use std::ops::Deref;
struct Foo(Box&lt;u8&gt;);
impl Deref for Foo {
type Target = u8;
fn deref(&amp;self) -&gt; &amp;Self::Target { &amp;*self.0 }
}
```
Foo can safely implement StableDeref, due to the use of Box.
```
# use std::ops::Deref;
# use std::ops::DerefMut;
# use std::rc::Rc;
#[derive(Clone)]
struct Foo(Rc&lt;u8&gt;);
impl Deref for Foo {
type Target = u8;
fn deref(&amp;self) -&gt; &amp;Self::Target { &amp;*self.0 }
}
impl DerefMut for Foo {
fn deref_mut(&amp;mut self) -&gt; &amp;mut Self::Target { Rc::make_mut(&amp;mut self.0) }
}
```
This is a simple implementation of copy-on-write: Foo&#39;s deref_mut will copy the underlying int if it is not uniquely owned, ensuring unique access at the point where deref_mut() returns. However, Foo cannot implement StableDeref because calling deref_mut(), followed by clone().deref() will result in mutable and immutable references to the same location. Note that if the DerefMut implementation were removed, Foo could safely implement StableDeref. Likewise, if the Clone implementation were removed, it would be safe to implement StableDeref, although Foo would not be very useful in that case, (without clones, the rc will always be uniquely owned).
```
# use std::ops::Deref;
struct Foo;
impl Deref for Foo {
type Target = str;
fn deref(&amp;self) -&gt; &amp;Self::Target { &amp;&quot;Hello&quot; }
}
```
Foo can safely implement StableDeref. It doesn&#39;t own the data being derefed, but the data is gaurenteed to live long enough, due to it being &#39;static.
```
# use std::ops::Deref;
# use std::cell::Cell;
struct Foo(Cell&lt;bool&gt;);
impl Deref for Foo {
type Target = str;
fn deref(&amp;self) -&gt; &amp;Self::Target {
let b = self.0.get();
self.0.set(!b);
if b { &amp;&quot;Hello&quot; } else { &amp;&quot;World&quot; }
}
}
```
Foo cannot safely implement StableDeref, even though every possible result of deref lives long enough. In order to safely implement StableAddress, multiple calls to deref must return the same result.
```
# use std::ops::Deref;
# use std::ops::DerefMut;
struct Foo(Box&lt;(u8, u8)&gt;);
impl Deref for Foo {
type Target = u8;
fn deref(&amp;self) -&gt; &amp;Self::Target { &amp;self.0.deref().0 }
}
impl DerefMut for Foo {
fn deref_mut(&amp;mut self) -&gt; &amp;mut Self::Target { &amp;mut self.0.deref_mut().1 }
}
```
Foo cannot implement StableDeref because deref and deref_mut return different addresses.
*/
</span><span class="kw">pub unsafe trait </span>StableDeref: Deref {}
<span class="doccomment">/**
An unsafe marker trait for types where clones deref to the same address. This has all the requirements of StableDeref, and additionally requires that after calling clone(), both the old and new value deref to the same address. For example, Rc and Arc implement CloneStableDeref, but Box and Vec do not.
Note that a single type should never implement both DerefMut and CloneStableDeref. If it did, this would let you get two mutable references to the same location, by cloning and then calling deref_mut() on both values.
*/
</span><span class="kw">pub unsafe trait </span>CloneStableDeref: StableDeref + Clone {}
<span class="comment">/////////////////////////////////////////////////////////////////////////////
// std types integration
/////////////////////////////////////////////////////////////////////////////
</span><span class="attr">#[cfg(feature = <span class="string">&quot;alloc&quot;</span>)]
</span><span class="kw">use </span>alloc::boxed::Box;
<span class="attr">#[cfg(feature = <span class="string">&quot;alloc&quot;</span>)]
</span><span class="kw">use </span>alloc::rc::Rc;
<span class="attr">#[cfg(feature = <span class="string">&quot;alloc&quot;</span>)]
</span><span class="kw">use </span>alloc::sync::Arc;
<span class="attr">#[cfg(feature = <span class="string">&quot;alloc&quot;</span>)]
</span><span class="kw">use </span>alloc::vec::Vec;
<span class="attr">#[cfg(feature = <span class="string">&quot;alloc&quot;</span>)]
</span><span class="kw">use </span>alloc::string::String;
<span class="attr">#[cfg(feature = <span class="string">&quot;std&quot;</span>)]
</span><span class="kw">use </span>std::ffi::{CString, OsString};
<span class="attr">#[cfg(feature = <span class="string">&quot;std&quot;</span>)]
</span><span class="kw">use </span>std::path::PathBuf;
<span class="attr">#[cfg(feature = <span class="string">&quot;std&quot;</span>)]
</span><span class="kw">use </span>std::sync::{MutexGuard, RwLockReadGuard, RwLockWriteGuard};
<span class="kw">use </span>core::cell::{Ref, RefMut};
<span class="attr">#[cfg(feature = <span class="string">&quot;alloc&quot;</span>)]
</span><span class="kw">unsafe impl</span>&lt;T: <span class="question-mark">?</span>Sized&gt; StableDeref <span class="kw">for </span>Box&lt;T&gt; {}
<span class="attr">#[cfg(feature = <span class="string">&quot;alloc&quot;</span>)]
</span><span class="kw">unsafe impl</span>&lt;T&gt; StableDeref <span class="kw">for </span>Vec&lt;T&gt; {}
<span class="attr">#[cfg(feature = <span class="string">&quot;alloc&quot;</span>)]
</span><span class="kw">unsafe impl </span>StableDeref <span class="kw">for </span>String {}
<span class="attr">#[cfg(feature = <span class="string">&quot;std&quot;</span>)]
</span><span class="kw">unsafe impl </span>StableDeref <span class="kw">for </span>CString {}
<span class="attr">#[cfg(feature = <span class="string">&quot;std&quot;</span>)]
</span><span class="kw">unsafe impl </span>StableDeref <span class="kw">for </span>OsString {}
<span class="attr">#[cfg(feature = <span class="string">&quot;std&quot;</span>)]
</span><span class="kw">unsafe impl </span>StableDeref <span class="kw">for </span>PathBuf {}
<span class="attr">#[cfg(feature = <span class="string">&quot;alloc&quot;</span>)]
</span><span class="kw">unsafe impl</span>&lt;T: <span class="question-mark">?</span>Sized&gt; StableDeref <span class="kw">for </span>Rc&lt;T&gt; {}
<span class="attr">#[cfg(feature = <span class="string">&quot;alloc&quot;</span>)]
</span><span class="kw">unsafe impl</span>&lt;T: <span class="question-mark">?</span>Sized&gt; CloneStableDeref <span class="kw">for </span>Rc&lt;T&gt; {}
<span class="attr">#[cfg(feature = <span class="string">&quot;alloc&quot;</span>)]
</span><span class="kw">unsafe impl</span>&lt;T: <span class="question-mark">?</span>Sized&gt; StableDeref <span class="kw">for </span>Arc&lt;T&gt; {}
<span class="attr">#[cfg(feature = <span class="string">&quot;alloc&quot;</span>)]
</span><span class="kw">unsafe impl</span>&lt;T: <span class="question-mark">?</span>Sized&gt; CloneStableDeref <span class="kw">for </span>Arc&lt;T&gt; {}
<span class="kw">unsafe impl</span>&lt;<span class="lifetime">&#39;a</span>, T: <span class="question-mark">?</span>Sized&gt; StableDeref <span class="kw">for </span>Ref&lt;<span class="lifetime">&#39;a</span>, T&gt; {}
<span class="kw">unsafe impl</span>&lt;<span class="lifetime">&#39;a</span>, T: <span class="question-mark">?</span>Sized&gt; StableDeref <span class="kw">for </span>RefMut&lt;<span class="lifetime">&#39;a</span>, T&gt; {}
<span class="attr">#[cfg(feature = <span class="string">&quot;std&quot;</span>)]
</span><span class="kw">unsafe impl</span>&lt;<span class="lifetime">&#39;a</span>, T: <span class="question-mark">?</span>Sized&gt; StableDeref <span class="kw">for </span>MutexGuard&lt;<span class="lifetime">&#39;a</span>, T&gt; {}
<span class="attr">#[cfg(feature = <span class="string">&quot;std&quot;</span>)]
</span><span class="kw">unsafe impl</span>&lt;<span class="lifetime">&#39;a</span>, T: <span class="question-mark">?</span>Sized&gt; StableDeref <span class="kw">for </span>RwLockReadGuard&lt;<span class="lifetime">&#39;a</span>, T&gt; {}
<span class="attr">#[cfg(feature = <span class="string">&quot;std&quot;</span>)]
</span><span class="kw">unsafe impl</span>&lt;<span class="lifetime">&#39;a</span>, T: <span class="question-mark">?</span>Sized&gt; StableDeref <span class="kw">for </span>RwLockWriteGuard&lt;<span class="lifetime">&#39;a</span>, T&gt; {}
<span class="kw">unsafe impl</span>&lt;<span class="lifetime">&#39;a</span>, T: <span class="question-mark">?</span>Sized&gt; StableDeref <span class="kw">for </span><span class="kw-2">&amp;</span><span class="lifetime">&#39;a </span>T {}
<span class="kw">unsafe impl</span>&lt;<span class="lifetime">&#39;a</span>, T: <span class="question-mark">?</span>Sized&gt; CloneStableDeref <span class="kw">for </span><span class="kw-2">&amp;</span><span class="lifetime">&#39;a </span>T {}
<span class="kw">unsafe impl</span>&lt;<span class="lifetime">&#39;a</span>, T: <span class="question-mark">?</span>Sized&gt; StableDeref <span class="kw">for </span><span class="kw-2">&amp;</span><span class="lifetime">&#39;a </span><span class="kw-2">mut </span>T {}
</code></pre></div></section></main></body></html>