deploy: de38ae62916547ad097c066f94a32e9ba7790eeb

This commit is contained in:
NotAShelf 2025-02-05 00:10:33 +00:00
commit 9a86359447
28502 changed files with 1261284 additions and 0 deletions

1
overload/all.html Normal file
View file

@ -0,0 +1 @@
<!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="List of all items in this crate"><title>List of all items in this crate</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="overload" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.1 (e71f9a9a9 2025-01-27)" data-channel="1.84.1" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../static.files/storage-59e33391.js"></script><script defer src="../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../static.files/favicon-044be391.svg"></head><body class="rustdoc mod sys"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../overload/index.html">overload</a><span class="version">0.1.1</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h3><a href="#macros">Crate Items</a></h3><ul class="block"><li><a href="#macros" title="Macros">Macros</a></li></ul></section><div id="rustdoc-modnav"></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><h1>List of all items</h1><h3 id="macros">Macros</h3><ul class="all-items"><li><a href="macro.overload.html">overload</a></li></ul></section></div></main></body></html>

128
overload/index.html Normal file
View file

@ -0,0 +1,128 @@
<!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="Provides a macro to simplify operator overloading."><title>overload - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="overload" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.1 (e71f9a9a9 2025-01-27)" data-channel="1.84.1" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../static.files/storage-59e33391.js"></script><script defer src="../crates.js"></script><script defer src="../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../static.files/favicon-044be391.svg"></head><body class="rustdoc mod crate"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../overload/index.html">overload</a><span class="version">0.1.1</span></h2></div><div class="sidebar-elems"><ul class="block"><li><a id="all-types" href="all.html">All Items</a></li></ul><section id="rustdoc-toc"><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#introduction" title="Introduction">Introduction</a></li><li><a href="#owned-and-borrowed-types" title="Owned and borrowed types">Owned and borrowed types</a></li><li><a href="#binary-operators" title="Binary operators">Binary operators</a></li><li><a href="#assignment-operators" title="Assignment operators">Assignment operators</a></li><li><a href="#unary-operators" title="Unary operators">Unary operators</a></li><li><a href="#notes" title="Notes">Notes</a></li></ul><h3><a href="#macros">Crate Items</a></h3><ul class="block"><li><a href="#macros" title="Macros">Macros</a></li></ul></section><div id="rustdoc-modnav"></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><h1>Crate <span>overload</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../src/overload/lib.rs.html#1-257">Source</a> </span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Provides a macro to simplify operator overloading.</p>
<p>To use, include the following:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">extern crate </span>overload;
<span class="kw">use </span>overload::overload;
<span class="kw">use </span>std::ops; <span class="comment">// &lt;- don't forget this or you'll get nasty errors</span></code></pre></div>
<h2 id="introduction"><a class="doc-anchor" href="#introduction">§</a>Introduction</h2>
<p>Suppose we have the following <code>struct</code> definition:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attr">#[derive(PartialEq, Debug)]
</span><span class="kw">struct </span>Val {
v: i32
}</code></pre></div>
<p>We can overload the addition of <code>Val</code>s like so:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="macro">overload!</span>((a: Val) + (b: Val) -&gt; Val { Val { v: a.v + b.v } });</code></pre></div>
<p>The macro call above generates the following code:</p>
<div class="example-wrap ignore"><a href="#" class="tooltip" title="This example is not tested"></a><pre class="rust rust-example-rendered"><code><span class="kw">impl </span>ops::Add&lt;Val&gt; <span class="kw">for </span>Val {
<span class="kw">type </span>Output = Val;
<span class="kw">fn </span>add(<span class="self">self</span>, b: Val) -&gt; <span class="self">Self</span>::Output {
<span class="kw">let </span>a = <span class="self">self</span>;
Val { v: a.v + b.v }
}
}</code></pre></div>
<p>We are now able to add <code>Val</code>s:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="macro">assert_eq!</span>(Val{v:<span class="number">3</span>} + Val{v:<span class="number">5</span>}, Val{v:<span class="number">8</span>});</code></pre></div>
<h2 id="owned-and-borrowed-types"><a class="doc-anchor" href="#owned-and-borrowed-types">§</a>Owned and borrowed types</h2>
<p>If we also wanted to overload addition for the borrowed type <code>&amp;Val</code> we could write:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="macro">overload!</span>((a: <span class="kw-2">&amp;</span>Val) + (b: <span class="kw-2">&amp;</span>Val) -&gt; Val { Val { v: a.v + b.v } });</code></pre></div>
<p>We might also want to overload addition between the owned and borrowed types:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="macro">overload!</span>((a: Val) + (b: <span class="kw-2">&amp;</span>Val) -&gt; Val { Val { v: a.v + b.v } });
<span class="macro">overload!</span>((a: <span class="kw-2">&amp;</span>Val) + (b: Val) -&gt; Val { Val { v: a.v + b.v } });</code></pre></div>
<p>Lets see how we can write these combinations more concisely.</p>
<p>We can include a <code>?</code> in front of a type to indicate that it should stand in for both the owned and borrowed type.</p>
<p>To overload addition for all four combinations between <code>Val</code> and <code>&amp;Val</code> we can therefore simply include a <code>?</code> in front of both types:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="macro">overload!</span>((a: <span class="question-mark">?</span>Val) + (b: <span class="question-mark">?</span>Val) -&gt; Val { Val { v: a.v + b.v } });</code></pre></div>
<p>The macro call above generates the following code:</p>
<div class="example-wrap ignore"><a href="#" class="tooltip" title="This example is not tested"></a><pre class="rust rust-example-rendered"><code><span class="kw">impl </span>ops::Add&lt;Val&gt; <span class="kw">for </span>Val {
<span class="kw">type </span>Output = Val;
<span class="kw">fn </span>add(<span class="self">self</span>, b: Val) -&gt; <span class="self">Self</span>::Output {
<span class="kw">let </span>a = <span class="self">self</span>;
Val { v: a.v + b.v }
}
}
<span class="kw">impl </span>ops::Add&lt;<span class="kw-2">&amp;</span>Val&gt; <span class="kw">for </span>Val {
<span class="kw">type </span>Output = Val;
<span class="kw">fn </span>add(<span class="self">self</span>, b: <span class="kw-2">&amp;</span>Val) -&gt; <span class="self">Self</span>::Output {
<span class="kw">let </span>a = <span class="self">self</span>;
Val { v: a.v + b.v }
}
}
<span class="kw">impl </span>ops::Add&lt;Val&gt; <span class="kw">for </span><span class="kw-2">&amp;</span>Val {
<span class="kw">type </span>Output = Val;
<span class="kw">fn </span>add(<span class="self">self</span>, b: Val) -&gt; <span class="self">Self</span>::Output {
<span class="kw">let </span>a = <span class="self">self</span>;
Val { v: a.v + b.v }
}
}
<span class="kw">impl </span>ops::Add&lt;<span class="kw-2">&amp;</span>Val&gt; <span class="kw">for </span><span class="kw-2">&amp;</span>Val {
<span class="kw">type </span>Output = Val;
<span class="kw">fn </span>add(<span class="self">self</span>, b: <span class="kw-2">&amp;</span>Val) -&gt; <span class="self">Self</span>::Output {
<span class="kw">let </span>a = <span class="self">self</span>;
Val { v: a.v + b.v }
}
}</code></pre></div>
<p>We are now able to add <code>Val</code>s and <code>&amp;Val</code>s in any combination:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="macro">assert_eq!</span>(Val{v:<span class="number">3</span>} + Val{v:<span class="number">5</span>}, Val{v:<span class="number">8</span>});
<span class="macro">assert_eq!</span>(Val{v:<span class="number">3</span>} + <span class="kw-2">&amp;</span>Val{v:<span class="number">5</span>}, Val{v:<span class="number">8</span>});
<span class="macro">assert_eq!</span>(<span class="kw-2">&amp;</span>Val{v:<span class="number">3</span>} + Val{v:<span class="number">5</span>}, Val{v:<span class="number">8</span>});
<span class="macro">assert_eq!</span>(<span class="kw-2">&amp;</span>Val{v:<span class="number">3</span>} + <span class="kw-2">&amp;</span>Val{v:<span class="number">5</span>}, Val{v:<span class="number">8</span>});</code></pre></div>
<h2 id="binary-operators"><a class="doc-anchor" href="#binary-operators">§</a>Binary operators</h2>
<p>The general syntax to overload a binary operator between types <code>&lt;a_type&gt;</code> and <code>&lt;b_type&gt;</code> is:</p>
<div class="example-wrap ignore"><a href="#" class="tooltip" title="This example is not tested"></a><pre class="rust rust-example-rendered"><code><span class="macro">overload!</span>((&lt;a_ident&gt;: &lt;a_type&gt;) &lt;op&gt; (&lt;b_ident&gt;: &lt;b_type&gt;) -&gt; &lt;out_type&gt; { <span class="comment">/*body*/ </span>});</code></pre></div>
<p>Inside the body you can use <code>&lt;a_ident&gt;</code> and <code>&lt;b_ident&gt;</code> freely to perform any computation.</p>
<p>The last line of the body needs to be an expression (i.e. no <code>;</code> at the end of the line) of type <code>&lt;out_type&gt;</code>.</p>
<div><table><thead><tr><th>Operator</th><th>Example</th><th>Trait</th></tr></thead><tbody>
<tr><td>+</td><td><code>overload!((a: A) + (b: B) -&gt; C { /*...*/ );</code></td><td>Add</td></tr>
<tr><td>-</td><td><code>overload!((a: A) - (b: B) -&gt; C { /*...*/ );</code></td><td>Sub</td></tr>
<tr><td>*</td><td><code>overload!((a: A) * (b: B) -&gt; C { /*...*/ );</code></td><td>Mul</td></tr>
<tr><td>/</td><td><code>overload!((a: A) / (b: B) -&gt; C { /*...*/ );</code></td><td>Div</td></tr>
<tr><td>%</td><td><code>overload!((a: A) % (b: B) -&gt; C { /*...*/ );</code></td><td>Rem</td></tr>
<tr><td>&amp;</td><td><code>overload!((a: A) &amp; (b: B) -&gt; C { /*...*/ );</code></td><td>BitAnd</td></tr>
<tr><td>|</td><td><code>overload!((a: A) | (b: B) -&gt; C { /*…*/ );</code></td><td>BitOr</td></tr>
<tr><td>^</td><td><code>overload!((a: A) ^ (b: B) -&gt; C { /*...*/ );</code></td><td>BitXor</td></tr>
<tr><td>&lt;&lt;</td><td><code>overload!((a: A) &lt;&lt; (b: B) -&gt; C { /*...*/ );</code></td><td>Shl</td></tr>
<tr><td>&gt;&gt;</td><td><code>overload!((a: A) &gt;&gt; (b: B) -&gt; C { /*...*/ );</code></td><td>Shr</td></tr>
</tbody></table>
</div><h2 id="assignment-operators"><a class="doc-anchor" href="#assignment-operators">§</a>Assignment operators</h2>
<p>The general syntax to overload an assignment operator between types <code>&lt;a_type&gt;</code> and <code>&lt;b_type&gt;</code> is:</p>
<div class="example-wrap ignore"><a href="#" class="tooltip" title="This example is not tested"></a><pre class="rust rust-example-rendered"><code><span class="macro">overload!</span>((&lt;a_ident&gt;: <span class="kw-2">&amp;mut </span>&lt;a_type&gt;) &lt;op&gt; (&lt;b_ident&gt;: &lt;b_type&gt;) { <span class="comment">/*body*/ </span>});</code></pre></div>
<p>Inside the body you can use <code>&lt;a_ident&gt;</code> and <code>&lt;b_ident&gt;</code> freely to perform any computation and mutate <code>&lt;a_ident&gt;</code> as desired.</p>
<div><table><thead><tr><th>Operator</th><th>Example</th><th>Trait</th></tr></thead><tbody>
<tr><td>+=</td><td><code>overload!((a: &amp;mut A) += (b: B) { /*...*/ );</code></td><td>AddAssign</td></tr>
<tr><td>-=</td><td><code>overload!((a: &amp;mut A) -= (b: B) { /*...*/ );</code></td><td>SubAssign</td></tr>
<tr><td>*=</td><td><code>overload!((a: &amp;mut A) *= (b: B) { /*...*/ );</code></td><td>MulAssign</td></tr>
<tr><td>/=</td><td><code>overload!((a: &amp;mut A) /= (b: B) { /*...*/ );</code></td><td>DivAssign</td></tr>
<tr><td>%=</td><td><code>overload!((a: &amp;mut A) %= (b: B) { /*...*/ );</code></td><td>RemAssign</td></tr>
<tr><td>&amp;=</td><td><code>overload!((a: &amp;mut A) &amp;= (b: B) { /*...*/ );</code></td><td>BitAndAssign</td></tr>
<tr><td>|=</td><td><code>overload!((a: &amp;mut A) |= (b: B) { /*…*/ );</code></td><td>BitOrAssign</td></tr>
<tr><td>^=</td><td><code>overload!((a: &amp;mut A) ^= (b: B) { /*...*/ );</code></td><td>BitXorAssign</td></tr>
<tr><td>&lt;&lt;=</td><td><code>overload!((a: &amp;mut A) &lt;&lt;= (b: B) { /*...*/ );</code></td><td>ShlAssign</td></tr>
<tr><td>&gt;&gt;=</td><td><code>overload!((a: &amp;mut A) &gt;&gt;= (b: B) { /*...*/ );</code></td><td>ShrAssign</td></tr>
</tbody></table>
</div><h2 id="unary-operators"><a class="doc-anchor" href="#unary-operators">§</a>Unary operators</h2>
<p>The general syntax to overload a unary operator for type <code>&lt;a_type&gt;</code> is:</p>
<div class="example-wrap ignore"><a href="#" class="tooltip" title="This example is not tested"></a><pre class="rust rust-example-rendered"><code><span class="macro">overload!</span>(&lt;op&gt; (&lt;a_ident&gt;: &lt;a_type&gt;) -&gt; &lt;out_type&gt; { <span class="comment">/*body*/ </span>});</code></pre></div>
<p>Inside the body you can use <code>&lt;a_ident&gt;</code> freely to perform any computation.</p>
<p>The last line of the body needs to be an expression (i.e. no <code>;</code> at the end of the line) of type <code>&lt;out_type&gt;</code>.</p>
<div><table><thead><tr><th>Operator</th><th>Example</th><th>Trait</th></tr></thead><tbody>
<tr><td>-</td><td><code>overload!(- (a: A) -&gt; B { /*...*/ );</code></td><td>Neg</td></tr>
<tr><td>!</td><td><code>overload!(! (a: A) -&gt; B { /*...*/ );</code></td><td>Not</td></tr>
</tbody></table>
</div><h2 id="notes"><a class="doc-anchor" href="#notes">§</a>Notes</h2>
<p>Remember that you can only overload operators between one or more types if at least one of the types is defined in the current crate.</p>
</div></details><h2 id="macros" class="section-header">Macros<a href="#macros" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="macro" href="macro.overload.html" title="macro overload::overload">overload</a></div><div class="desc docblock-short">Overloads an operator. See the <a href="index.html">module level documentation</a> for more information.</div></li></ul></section></div></main></body></html>

View file

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="refresh" content="0;URL=macro.overload.html">
<title>Redirection</title>
</head>
<body>
<p>Redirecting to <a href="macro.overload.html">macro.overload.html</a>...</p>
<script>location.replace("macro.overload.html" + location.search + location.hash);</script>
</body>
</html>

View file

@ -0,0 +1,11 @@
<!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="Overloads an operator. See the module level documentation for more information."><title>overload in overload - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="overload" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.1 (e71f9a9a9 2025-01-27)" data-channel="1.84.1" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../static.files/storage-59e33391.js"></script><script defer src="sidebar-items.js"></script><script defer src="../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../static.files/favicon-044be391.svg"></head><body class="rustdoc macro"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../overload/index.html">overload</a><span class="version">0.1.1</span></h2></div><div class="sidebar-elems"><div id="rustdoc-modnav"></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="index.html">overload</a></span><h1>Macro <span class="macro">overload</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../src/overload/lib.rs.html#217-257">Source</a> </span></div><pre class="rust item-decl"><code>macro_rules! overload {
($op:tt ($i:ident : ? $t:ty) -&gt; $out:ty $body:block) =&gt; { ... };
($op:tt ($i:ident : $t:ty) -&gt; $out:ty $body:block) =&gt; { ... };
(($li:ident : &amp;mut $lt:ty) $op:tt ($ri:ident : ? $rt:ty) $body:block) =&gt; { ... };
(($li:ident : &amp;mut $lt:ty) $op:tt ($ri:ident : $rt:ty) $body:block) =&gt; { ... };
(($li:ident : ? $lt:ty) $op:tt ($ri:ident : ? $rt:ty) -&gt; $out:ty $body:block) =&gt; { ... };
(($li:ident : ? $lt:ty) $op:tt ($ri:ident : $rt:ty) -&gt; $out:ty $body:block) =&gt; { ... };
(($li:ident : $lt:ty) $op:tt ($ri:ident : ? $rt:ty) -&gt; $out:ty $body:block) =&gt; { ... };
(($li:ident : $lt:ty) $op:tt ($ri:ident : $rt:ty) -&gt; $out:ty $body:block) =&gt; { ... };
}</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Overloads an operator. See the <a href="index.html">module level documentation</a> for more information.</p>
</div></details></section></div></main></body></html>

View file

@ -0,0 +1 @@
window.SIDEBAR_ITEMS = {"macro":["overload"]};