2019-05-25 05:42:34 -05:00
|
|
|
|
|
|
|
<style>
|
2019-07-18 10:49:32 -05:00
|
|
|
body { margin: 0; }
|
|
|
|
pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padding: 0.4em; }
|
|
|
|
|
2020-02-28 09:49:46 -06:00
|
|
|
.lifetime { color: #DFAF8F; font-style: italic; }
|
2019-07-18 10:49:32 -05:00
|
|
|
.comment { color: #7F9F7F; }
|
2020-06-22 09:28:07 -05:00
|
|
|
.documentation { color: #629755; }
|
2020-06-18 09:30:40 -05:00
|
|
|
.injected { opacity: 0.65 ; }
|
2020-02-28 07:47:33 -06:00
|
|
|
.struct, .enum { color: #7CB8BB; }
|
|
|
|
.enum_variant { color: #BDE0F3; }
|
|
|
|
.string_literal { color: #CC9393; }
|
2019-12-20 07:10:31 -06:00
|
|
|
.field { color: #94BFF3; }
|
2019-07-18 10:49:32 -05:00
|
|
|
.function { color: #93E0E3; }
|
2020-06-08 08:23:03 -05:00
|
|
|
.function.unsafe { color: #BC8383; }
|
|
|
|
.operator.unsafe { color: #BC8383; }
|
2019-07-18 10:49:32 -05:00
|
|
|
.parameter { color: #94BFF3; }
|
|
|
|
.text { color: #DCDCCC; }
|
2019-12-07 13:05:08 -06:00
|
|
|
.type { color: #7CB8BB; }
|
2020-02-28 07:47:33 -06:00
|
|
|
.builtin_type { color: #8CD0D3; }
|
|
|
|
.type_param { color: #DFAF8F; }
|
2019-07-18 11:57:13 -05:00
|
|
|
.attribute { color: #94BFF3; }
|
2020-02-28 07:47:33 -06:00
|
|
|
.numeric_literal { color: #BFEBBF; }
|
2020-05-21 11:40:52 -05:00
|
|
|
.bool_literal { color: #BFE6EB; }
|
2019-07-18 11:57:13 -05:00
|
|
|
.macro { color: #94BFF3; }
|
2020-02-16 10:06:01 -06:00
|
|
|
.module { color: #AFD8AF; }
|
2020-07-11 07:50:00 -05:00
|
|
|
.value_param { color: #DCDCCC; }
|
2019-07-18 11:57:13 -05:00
|
|
|
.variable { color: #DCDCCC; }
|
2020-04-28 02:44:20 -05:00
|
|
|
.format_specifier { color: #CC696B; }
|
2020-02-28 07:47:33 -06:00
|
|
|
.mutable { text-decoration: underline; }
|
2020-06-17 08:27:13 -05:00
|
|
|
.escape_sequence { color: #94BFF3; }
|
2020-02-28 07:47:33 -06:00
|
|
|
.keyword { color: #F0DFAF; font-weight: bold; }
|
|
|
|
.keyword.unsafe { color: #BC8383; font-weight: bold; }
|
|
|
|
.control { font-style: italic; }
|
2020-07-11 07:50:00 -05:00
|
|
|
|
|
|
|
.unresolved_reference { color: #FC5555; text-decoration: wavy underline; }
|
2019-05-25 05:42:34 -05:00
|
|
|
</style>
|
2020-08-04 08:28:40 -05:00
|
|
|
<pre><code><span class="keyword">use</span> <span class="module">inner</span><span class="operator">::</span><span class="punctuation">{</span><span class="self_keyword">self</span> <span class="keyword">as</span> <span class="module declaration">inner_mod</span><span class="punctuation">}</span><span class="punctuation">;</span>
|
2020-08-04 08:23:23 -05:00
|
|
|
<span class="keyword">mod</span> <span class="module declaration">inner</span> <span class="punctuation">{</span><span class="punctuation">}</span>
|
|
|
|
|
|
|
|
<span class="attribute">#</span><span class="attribute">[</span><span class="function attribute">derive</span><span class="punctuation">(</span><span class="attribute">Clone</span><span class="punctuation">,</span><span class="attribute"> Debug</span><span class="punctuation">)</span><span class="attribute">]</span>
|
2020-07-15 09:34:11 -05:00
|
|
|
<span class="keyword">struct</span> <span class="struct declaration">Foo</span> <span class="punctuation">{</span>
|
|
|
|
<span class="keyword">pub</span> <span class="field declaration">x</span><span class="punctuation">:</span> <span class="builtin_type">i32</span><span class="punctuation">,</span>
|
|
|
|
<span class="keyword">pub</span> <span class="field declaration">y</span><span class="punctuation">:</span> <span class="builtin_type">i32</span><span class="punctuation">,</span>
|
|
|
|
<span class="punctuation">}</span>
|
|
|
|
|
|
|
|
<span class="keyword">trait</span> <span class="trait declaration">Bar</span> <span class="punctuation">{</span>
|
2020-07-20 09:21:40 -05:00
|
|
|
<span class="keyword">fn</span> <span class="function declaration">bar</span><span class="punctuation">(</span><span class="operator">&</span><span class="self_keyword">self</span><span class="punctuation">)</span> <span class="operator">-></span> <span class="builtin_type">i32</span><span class="punctuation">;</span>
|
2020-07-15 09:34:11 -05:00
|
|
|
<span class="punctuation">}</span>
|
|
|
|
|
|
|
|
<span class="keyword">impl</span> <span class="trait">Bar</span> <span class="keyword">for</span> <span class="struct">Foo</span> <span class="punctuation">{</span>
|
2020-07-20 09:21:40 -05:00
|
|
|
<span class="keyword">fn</span> <span class="function declaration">bar</span><span class="punctuation">(</span><span class="operator">&</span><span class="self_keyword">self</span><span class="punctuation">)</span> <span class="operator">-></span> <span class="builtin_type">i32</span> <span class="punctuation">{</span>
|
2020-07-15 09:34:11 -05:00
|
|
|
<span class="self_keyword">self</span><span class="punctuation">.</span><span class="field">x</span>
|
|
|
|
<span class="punctuation">}</span>
|
|
|
|
<span class="punctuation">}</span>
|
|
|
|
|
|
|
|
<span class="keyword">impl</span> <span class="struct">Foo</span> <span class="punctuation">{</span>
|
2020-07-20 09:21:40 -05:00
|
|
|
<span class="keyword">fn</span> <span class="function declaration">baz</span><span class="punctuation">(</span><span class="keyword">mut</span> <span class="self_keyword mutable">self</span><span class="punctuation">)</span> <span class="operator">-></span> <span class="builtin_type">i32</span> <span class="punctuation">{</span>
|
2020-07-15 09:34:11 -05:00
|
|
|
<span class="self_keyword">self</span><span class="punctuation">.</span><span class="field">x</span>
|
|
|
|
<span class="punctuation">}</span>
|
|
|
|
|
2020-07-20 09:21:40 -05:00
|
|
|
<span class="keyword">fn</span> <span class="function declaration">qux</span><span class="punctuation">(</span><span class="operator">&</span><span class="keyword">mut</span> <span class="self_keyword mutable">self</span><span class="punctuation">)</span> <span class="punctuation">{</span>
|
|
|
|
<span class="self_keyword mutable">self</span><span class="punctuation">.</span><span class="field">x</span> <span class="operator">=</span> <span class="numeric_literal">0</span><span class="punctuation">;</span>
|
2020-07-15 09:34:11 -05:00
|
|
|
<span class="punctuation">}</span>
|
|
|
|
<span class="punctuation">}</span>
|
|
|
|
|
2020-07-20 10:36:23 -05:00
|
|
|
<span class="keyword">static</span> <span class="keyword">mut</span> <span class="static declaration mutable">STATIC_MUT</span><span class="punctuation">:</span> <span class="builtin_type">i32</span> <span class="operator">=</span> <span class="numeric_literal">0</span><span class="punctuation">;</span>
|
2020-07-15 09:34:11 -05:00
|
|
|
|
2020-07-20 09:21:40 -05:00
|
|
|
<span class="keyword">fn</span> <span class="function declaration">foo</span><span class="punctuation"><</span><span class="lifetime declaration">'a</span><span class="punctuation">,</span> <span class="type_param declaration">T</span><span class="punctuation">></span><span class="punctuation">(</span><span class="punctuation">)</span> <span class="operator">-></span> <span class="type_param">T</span> <span class="punctuation">{</span>
|
|
|
|
<span class="function">foo</span><span class="operator">::</span><span class="punctuation"><</span><span class="lifetime">'a</span><span class="punctuation">,</span> <span class="builtin_type">i32</span><span class="punctuation">></span><span class="punctuation">(</span><span class="punctuation">)</span>
|
2020-07-15 09:34:11 -05:00
|
|
|
<span class="punctuation">}</span>
|
|
|
|
|
|
|
|
<span class="macro">macro_rules!</span> <span class="macro declaration">def_fn</span> <span class="punctuation">{</span>
|
2020-07-20 10:36:23 -05:00
|
|
|
<span class="punctuation">(</span><span class="punctuation">$</span><span class="punctuation">(</span><span class="punctuation">$</span>tt<span class="punctuation">:</span>tt<span class="punctuation">)</span><span class="punctuation">*</span><span class="punctuation">)</span> <span class="operator">=</span><span class="punctuation">></span> <span class="punctuation">{</span><span class="punctuation">$</span><span class="punctuation">(</span><span class="punctuation">$</span>tt<span class="punctuation">)</span><span class="punctuation">*</span><span class="punctuation">}</span>
|
2020-07-15 09:34:11 -05:00
|
|
|
<span class="punctuation">}</span>
|
|
|
|
|
|
|
|
<span class="macro">def_fn!</span> <span class="punctuation">{</span>
|
2020-07-20 09:21:40 -05:00
|
|
|
<span class="keyword">fn</span> <span class="function declaration">bar</span><span class="punctuation">(</span><span class="punctuation">)</span> <span class="operator">-</span><span class="operator">></span> <span class="builtin_type">u32</span> <span class="punctuation">{</span>
|
2020-02-28 07:47:33 -06:00
|
|
|
<span class="numeric_literal">100</span>
|
2020-07-15 09:34:11 -05:00
|
|
|
<span class="punctuation">}</span>
|
|
|
|
<span class="punctuation">}</span>
|
2020-01-20 10:06:47 -06:00
|
|
|
|
2020-07-15 09:34:11 -05:00
|
|
|
<span class="macro">macro_rules!</span> <span class="macro declaration">noop</span> <span class="punctuation">{</span>
|
2020-07-20 10:36:23 -05:00
|
|
|
<span class="punctuation">(</span><span class="punctuation">$</span>expr<span class="punctuation">:</span>expr<span class="punctuation">)</span> <span class="operator">=</span><span class="punctuation">></span> <span class="punctuation">{</span>
|
2020-07-15 09:34:11 -05:00
|
|
|
<span class="punctuation">$</span>expr
|
|
|
|
<span class="punctuation">}</span>
|
|
|
|
<span class="punctuation">}</span>
|
2020-06-14 08:40:06 -05:00
|
|
|
|
2019-05-25 05:42:34 -05:00
|
|
|
<span class="comment">// comment</span>
|
2020-07-15 09:34:11 -05:00
|
|
|
<span class="keyword">fn</span> <span class="function declaration">main</span><span class="punctuation">(</span><span class="punctuation">)</span> <span class="punctuation">{</span>
|
|
|
|
<span class="macro">println!</span><span class="punctuation">(</span><span class="string_literal">"Hello, {}!"</span><span class="punctuation">,</span> <span class="numeric_literal">92</span><span class="punctuation">)</span><span class="punctuation">;</span>
|
|
|
|
|
2020-07-20 10:36:23 -05:00
|
|
|
<span class="keyword">let</span> <span class="keyword">mut</span> <span class="variable declaration mutable">vec</span> <span class="operator">=</span> <span class="unresolved_reference">Vec</span><span class="operator">::</span><span class="unresolved_reference">new</span><span class="punctuation">(</span><span class="punctuation">)</span><span class="punctuation">;</span>
|
2020-07-15 09:34:11 -05:00
|
|
|
<span class="keyword control">if</span> <span class="bool_literal">true</span> <span class="punctuation">{</span>
|
2020-07-20 10:36:23 -05:00
|
|
|
<span class="keyword">let</span> <span class="variable declaration">x</span> <span class="operator">=</span> <span class="numeric_literal">92</span><span class="punctuation">;</span>
|
2020-07-15 09:34:11 -05:00
|
|
|
<span class="variable mutable">vec</span><span class="punctuation">.</span><span class="unresolved_reference">push</span><span class="punctuation">(</span><span class="struct">Foo</span> <span class="punctuation">{</span> <span class="field">x</span><span class="punctuation">,</span> <span class="field">y</span><span class="punctuation">:</span> <span class="numeric_literal">1</span> <span class="punctuation">}</span><span class="punctuation">)</span><span class="punctuation">;</span>
|
|
|
|
<span class="punctuation">}</span>
|
|
|
|
<span class="keyword unsafe">unsafe</span> <span class="punctuation">{</span>
|
|
|
|
<span class="variable mutable">vec</span><span class="punctuation">.</span><span class="unresolved_reference">set_len</span><span class="punctuation">(</span><span class="numeric_literal">0</span><span class="punctuation">)</span><span class="punctuation">;</span>
|
2020-07-20 09:21:40 -05:00
|
|
|
<span class="static mutable">STATIC_MUT</span> <span class="operator">=</span> <span class="numeric_literal">1</span><span class="punctuation">;</span>
|
2020-07-15 09:34:11 -05:00
|
|
|
<span class="punctuation">}</span>
|
|
|
|
|
|
|
|
<span class="keyword control">for</span> <span class="variable declaration">e</span> <span class="keyword control">in</span> <span class="variable mutable">vec</span> <span class="punctuation">{</span>
|
2020-05-10 13:08:32 -05:00
|
|
|
<span class="comment">// Do nothing</span>
|
2020-07-15 09:34:11 -05:00
|
|
|
<span class="punctuation">}</span>
|
2020-05-10 13:08:32 -05:00
|
|
|
|
2020-07-15 09:34:11 -05:00
|
|
|
<span class="macro">noop!</span><span class="punctuation">(</span><span class="macro">noop</span><span class="macro">!</span><span class="punctuation">(</span><span class="numeric_literal">1</span><span class="punctuation">)</span><span class="punctuation">)</span><span class="punctuation">;</span>
|
2020-06-14 08:40:06 -05:00
|
|
|
|
2020-07-20 10:36:23 -05:00
|
|
|
<span class="keyword">let</span> <span class="keyword">mut</span> <span class="variable declaration mutable">x</span> <span class="operator">=</span> <span class="numeric_literal">42</span><span class="punctuation">;</span>
|
|
|
|
<span class="keyword">let</span> <span class="variable declaration mutable">y</span> <span class="operator">=</span> <span class="operator">&</span><span class="keyword">mut</span> <span class="variable mutable">x</span><span class="punctuation">;</span>
|
|
|
|
<span class="keyword">let</span> <span class="variable declaration">z</span> <span class="operator">=</span> <span class="operator">&</span><span class="variable mutable">y</span><span class="punctuation">;</span>
|
2019-07-18 10:49:32 -05:00
|
|
|
|
2020-07-20 10:36:23 -05:00
|
|
|
<span class="keyword">let</span> <span class="struct">Foo</span> <span class="punctuation">{</span> <span class="field">x</span><span class="punctuation">:</span> <span class="variable declaration">z</span><span class="punctuation">,</span> <span class="field">y</span> <span class="punctuation">}</span> <span class="operator">=</span> <span class="struct">Foo</span> <span class="punctuation">{</span> <span class="field">x</span><span class="punctuation">:</span> <span class="variable">z</span><span class="punctuation">,</span> <span class="field">y</span> <span class="punctuation">}</span><span class="punctuation">;</span>
|
2020-06-10 05:34:23 -05:00
|
|
|
|
2020-07-15 09:34:11 -05:00
|
|
|
<span class="variable">y</span><span class="punctuation">;</span>
|
|
|
|
<span class="punctuation">}</span>
|
2019-12-07 13:05:08 -06:00
|
|
|
|
2020-07-15 09:34:11 -05:00
|
|
|
<span class="keyword">enum</span> <span class="enum declaration">Option</span><span class="punctuation"><</span><span class="type_param declaration">T</span><span class="punctuation">></span> <span class="punctuation">{</span>
|
|
|
|
<span class="enum_variant declaration">Some</span><span class="punctuation">(</span><span class="type_param">T</span><span class="punctuation">)</span><span class="punctuation">,</span>
|
|
|
|
<span class="enum_variant declaration">None</span><span class="punctuation">,</span>
|
|
|
|
<span class="punctuation">}</span>
|
2020-07-20 09:21:40 -05:00
|
|
|
<span class="keyword">use</span> <span class="enum">Option</span><span class="operator">::</span><span class="punctuation">*</span><span class="punctuation">;</span>
|
2019-12-07 13:05:08 -06:00
|
|
|
|
2020-07-15 09:34:11 -05:00
|
|
|
<span class="keyword">impl</span><span class="punctuation"><</span><span class="type_param declaration">T</span><span class="punctuation">></span> <span class="enum">Option</span><span class="punctuation"><</span><span class="type_param">T</span><span class="punctuation">></span> <span class="punctuation">{</span>
|
2020-07-20 09:21:40 -05:00
|
|
|
<span class="keyword">fn</span> <span class="function declaration">and</span><span class="punctuation"><</span><span class="type_param declaration">U</span><span class="punctuation">></span><span class="punctuation">(</span><span class="self_keyword">self</span><span class="punctuation">,</span> <span class="value_param declaration">other</span><span class="punctuation">:</span> <span class="enum">Option</span><span class="punctuation"><</span><span class="type_param">U</span><span class="punctuation">></span><span class="punctuation">)</span> <span class="operator">-></span> <span class="enum">Option</span><span class="punctuation"><</span><span class="punctuation">(</span><span class="type_param">T</span><span class="punctuation">,</span> <span class="type_param">U</span><span class="punctuation">)</span><span class="punctuation">></span> <span class="punctuation">{</span>
|
2020-07-15 09:34:11 -05:00
|
|
|
<span class="keyword control">match</span> <span class="value_param">other</span> <span class="punctuation">{</span>
|
2020-07-20 09:21:40 -05:00
|
|
|
<span class="enum_variant">None</span> <span class="operator">=></span> <span class="macro">unimplemented!</span><span class="punctuation">(</span><span class="punctuation">)</span><span class="punctuation">,</span>
|
|
|
|
<span class="variable declaration">Nope</span> <span class="operator">=></span> <span class="variable">Nope</span><span class="punctuation">,</span>
|
2020-07-15 09:34:11 -05:00
|
|
|
<span class="punctuation">}</span>
|
|
|
|
<span class="punctuation">}</span>
|
|
|
|
<span class="punctuation">}</span></code></pre>
|