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; }
|
|
|
|
|
|
|
|
.comment { color: #7F9F7F; }
|
|
|
|
.string { color: #CC9393; }
|
2019-12-20 07:10:31 -06:00
|
|
|
.field { color: #94BFF3; }
|
2019-07-18 10:49:32 -05:00
|
|
|
.function { color: #93E0E3; }
|
|
|
|
.parameter { color: #94BFF3; }
|
|
|
|
.text { color: #DCDCCC; }
|
2019-12-07 13:05:08 -06:00
|
|
|
.type { color: #7CB8BB; }
|
2019-12-17 07:43:37 -06:00
|
|
|
.type\.builtin { color: #8CD0D3; }
|
2019-12-14 05:29:42 -06:00
|
|
|
.type\.param { color: #20999D; }
|
2019-07-18 11:57:13 -05:00
|
|
|
.attribute { color: #94BFF3; }
|
|
|
|
.literal { color: #BFEBBF; }
|
2019-12-14 05:29:42 -06:00
|
|
|
.literal\.numeric { color: #6A8759; }
|
2019-07-18 11:57:13 -05:00
|
|
|
.macro { color: #94BFF3; }
|
|
|
|
.variable { color: #DCDCCC; }
|
|
|
|
.variable\.mut { color: #DCDCCC; text-decoration: underline; }
|
2019-07-18 10:49:32 -05:00
|
|
|
|
|
|
|
.keyword { color: #F0DFAF; }
|
2019-07-18 11:57:13 -05:00
|
|
|
.keyword\.unsafe { color: #DFAF8F; }
|
|
|
|
.keyword\.control { color: #F0DFAF; font-weight: bold; }
|
2019-05-25 05:42:34 -05:00
|
|
|
</style>
|
2019-10-08 06:52:03 -05:00
|
|
|
<pre><code><span class="attribute">#</span><span class="attribute">[</span><span class="attribute">derive</span><span class="attribute">(</span><span class="attribute">Clone</span><span class="attribute">,</span><span class="attribute"> </span><span class="attribute">Debug</span><span class="attribute">)</span><span class="attribute">]</span>
|
2019-05-28 13:27:54 -05:00
|
|
|
<span class="keyword">struct</span> <span class="type">Foo</span> {
|
2019-12-14 05:29:42 -06:00
|
|
|
<span class="keyword">pub</span> <span class="field">x</span>: <span class="type.builtin">i32</span>,
|
|
|
|
<span class="keyword">pub</span> <span class="field">y</span>: <span class="type.builtin">i32</span>,
|
2019-05-25 05:42:34 -05:00
|
|
|
}
|
|
|
|
|
2019-12-14 05:29:42 -06:00
|
|
|
<span class="keyword">fn</span> <span class="function">foo</span><<span class="type.param">T</span>>() -> <span class="type.param">T</span> {
|
2019-05-25 05:42:34 -05:00
|
|
|
<span class="macro">unimplemented</span><span class="macro">!</span>();
|
2019-12-14 05:29:42 -06:00
|
|
|
<span class="function">foo</span>::<<span class="type.builtin">i32</span>>();
|
2019-05-25 05:42:34 -05:00
|
|
|
}
|
|
|
|
|
2020-01-20 10:06:47 -06:00
|
|
|
<span class="macro">macro_rules</span><span class="macro">!</span> def_fn {
|
|
|
|
($($tt:tt)*) => {$($tt)*}
|
|
|
|
}
|
|
|
|
|
|
|
|
<span class="macro">def_fn</span><span class="macro">!</span>{
|
|
|
|
<span class="keyword">fn</span> <span class="function">bar</span>() -> <span class="type.builtin">u32</span> {
|
|
|
|
<span class="literal.numeric">100</span>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-25 05:42:34 -05:00
|
|
|
<span class="comment">// comment</span>
|
|
|
|
<span class="keyword">fn</span> <span class="function">main</span>() {
|
2019-12-14 05:29:42 -06:00
|
|
|
<span class="macro">println</span><span class="macro">!</span>(<span class="string">"Hello, {}!"</span>, <span class="literal.numeric">92</span>);
|
2019-05-25 05:42:34 -05:00
|
|
|
|
2019-12-31 04:06:50 -06:00
|
|
|
<span class="keyword">let</span> <span class="keyword">mut</span> <span class="variable.mut">vec</span> = Vec::new();
|
2019-05-25 05:42:34 -05:00
|
|
|
<span class="keyword.control">if</span> <span class="keyword">true</span> {
|
2019-12-20 07:10:31 -06:00
|
|
|
<span class="keyword">let</span> <span class="variable">x</span> = <span class="literal.numeric">92</span>;
|
2019-12-31 04:06:50 -06:00
|
|
|
<span class="variable.mut">vec</span>.push(<span class="type">Foo</span> { <span class="field">x</span>, <span class="field">y</span>: <span class="literal.numeric">1</span> });
|
2019-05-25 05:42:34 -05:00
|
|
|
}
|
2019-12-31 04:06:50 -06:00
|
|
|
<span class="keyword.unsafe">unsafe</span> { <span class="variable.mut">vec</span>.set_len(<span class="literal.numeric">0</span>); }
|
2019-07-18 10:49:32 -05:00
|
|
|
|
2019-12-14 05:29:42 -06:00
|
|
|
<span class="keyword">let</span> <span class="keyword">mut</span> <span class="variable.mut">x</span> = <span class="literal.numeric">42</span>;
|
2019-07-18 10:49:32 -05:00
|
|
|
<span class="keyword">let</span> <span class="variable.mut">y</span> = &<span class="keyword">mut</span> <span class="variable.mut">x</span>;
|
|
|
|
<span class="keyword">let</span> <span class="variable">z</span> = &<span class="variable.mut">y</span>;
|
|
|
|
|
|
|
|
<span class="variable.mut">y</span>;
|
2019-12-07 13:05:08 -06:00
|
|
|
}
|
|
|
|
|
2019-12-14 05:29:42 -06:00
|
|
|
<span class="keyword">enum</span> <span class="type">E</span><<span class="type.param">X</span>> {
|
|
|
|
<span class="constant">V</span>(<span class="type.param">X</span>)
|
2019-12-07 13:05:08 -06:00
|
|
|
}
|
|
|
|
|
2019-12-14 05:29:42 -06:00
|
|
|
<span class="keyword">impl</span><<span class="type.param">X</span>> <span class="type">E</span><<span class="type.param">X</span>> {
|
|
|
|
<span class="keyword">fn</span> <span class="function">new</span><<span class="type.param">T</span>>() -> <span class="type">E</span><<span class="type.param">T</span>> {}
|
2019-05-25 09:23:58 -05:00
|
|
|
}</code></pre>
|