2019-05-25 10:42:34 +00:00
|
|
|
|
|
|
|
<style>
|
2019-07-18 15:49:32 +00:00
|
|
|
body { margin: 0; }
|
|
|
|
pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padding: 0.4em; }
|
|
|
|
|
2020-02-28 13:47:33 +00:00
|
|
|
|
2019-07-18 15:49:32 +00:00
|
|
|
.comment { color: #7F9F7F; }
|
2020-02-28 13:47:33 +00:00
|
|
|
.struct, .enum { color: #7CB8BB; }
|
|
|
|
.enum_variant { color: #BDE0F3; }
|
|
|
|
.string_literal { color: #CC9393; }
|
2019-12-20 13:10:31 +00:00
|
|
|
.field { color: #94BFF3; }
|
2019-07-18 15:49:32 +00:00
|
|
|
.function { color: #93E0E3; }
|
|
|
|
.parameter { color: #94BFF3; }
|
|
|
|
.text { color: #DCDCCC; }
|
2019-12-07 19:05:08 +00:00
|
|
|
.type { color: #7CB8BB; }
|
2020-02-28 13:47:33 +00:00
|
|
|
.builtin_type { color: #8CD0D3; }
|
|
|
|
.type_param { color: #DFAF8F; }
|
2019-07-18 16:57:13 +00:00
|
|
|
.attribute { color: #94BFF3; }
|
2020-02-28 13:47:33 +00:00
|
|
|
.numeric_literal { color: #BFEBBF; }
|
2019-07-18 16:57:13 +00:00
|
|
|
.macro { color: #94BFF3; }
|
2020-02-16 16:06:01 +00:00
|
|
|
.module { color: #AFD8AF; }
|
2019-07-18 16:57:13 +00:00
|
|
|
.variable { color: #DCDCCC; }
|
2020-02-28 13:47:33 +00:00
|
|
|
.mutable { text-decoration: underline; }
|
2019-07-18 15:49:32 +00:00
|
|
|
|
2020-02-28 13:47:33 +00:00
|
|
|
.keyword { color: #F0DFAF; font-weight: bold; }
|
|
|
|
.keyword.unsafe { color: #BC8383; font-weight: bold; }
|
|
|
|
.control { font-style: italic; }
|
2019-05-25 10:42:34 +00:00
|
|
|
</style>
|
2019-10-08 11:52:03 +00: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>
|
2020-02-28 13:47:33 +00:00
|
|
|
<span class="keyword">struct</span> <span class="struct">Foo</span> {
|
|
|
|
<span class="keyword">pub</span> <span class="field">x</span>: <span class="builtin_type">i32</span>,
|
|
|
|
<span class="keyword">pub</span> <span class="field">y</span>: <span class="builtin_type">i32</span>,
|
2019-05-25 10:42:34 +00:00
|
|
|
}
|
|
|
|
|
2020-02-28 13:47:33 +00: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 10:42:34 +00:00
|
|
|
<span class="macro">unimplemented</span><span class="macro">!</span>();
|
2020-02-28 13:47:33 +00:00
|
|
|
<span class="function">foo</span>::<<span class="builtin_type">i32</span>>();
|
2019-05-25 10:42:34 +00:00
|
|
|
}
|
|
|
|
|
2020-01-20 16:06:47 +00:00
|
|
|
<span class="macro">macro_rules</span><span class="macro">!</span> def_fn {
|
|
|
|
($($tt:tt)*) => {$($tt)*}
|
|
|
|
}
|
|
|
|
|
2020-02-28 13:47:33 +00:00
|
|
|
<span class="macro">def_fn</span><span class="macro">!</span> {
|
|
|
|
<span class="keyword">fn</span> <span class="function">bar</span>() -> <span class="builtin_type">u32</span> {
|
|
|
|
<span class="numeric_literal">100</span>
|
2020-01-20 16:06:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-25 10:42:34 +00:00
|
|
|
<span class="comment">// comment</span>
|
|
|
|
<span class="keyword">fn</span> <span class="function">main</span>() {
|
2020-02-28 13:47:33 +00:00
|
|
|
<span class="macro">println</span><span class="macro">!</span>(<span class="string_literal">"Hello, {}!"</span>, <span class="numeric_literal">92</span>);
|
2019-05-25 10:42:34 +00:00
|
|
|
|
2020-02-26 22:09:55 +00:00
|
|
|
<span class="keyword">let</span> <span class="keyword">mut</span> <span class="variable mutable">vec</span> = Vec::new();
|
|
|
|
<span class="keyword control">if</span> <span class="keyword">true</span> {
|
2020-02-28 13:47:33 +00:00
|
|
|
<span class="keyword">let</span> <span class="variable">x</span> = <span class="numeric_literal">92</span>;
|
|
|
|
<span class="variable mutable">vec</span>.push(<span class="struct">Foo</span> { <span class="field">x</span>, <span class="field">y</span>: <span class="numeric_literal">1</span> });
|
2019-05-25 10:42:34 +00:00
|
|
|
}
|
2020-02-28 13:47:33 +00:00
|
|
|
<span class="keyword unsafe">unsafe</span> { <span class="variable mutable">vec</span>.set_len(<span class="numeric_literal">0</span>); }
|
2019-07-18 15:49:32 +00:00
|
|
|
|
2020-02-28 13:47:33 +00:00
|
|
|
<span class="keyword">let</span> <span class="keyword">mut</span> <span class="variable mutable">x</span> = <span class="numeric_literal">42</span>;
|
2020-02-26 22:09:55 +00:00
|
|
|
<span class="keyword">let</span> <span class="variable mutable">y</span> = &<span class="keyword">mut</span> <span class="variable mutable">x</span>;
|
|
|
|
<span class="keyword">let</span> <span class="variable">z</span> = &<span class="variable mutable">y</span>;
|
2019-07-18 15:49:32 +00:00
|
|
|
|
2020-02-26 22:09:55 +00:00
|
|
|
<span class="variable mutable">y</span>;
|
2019-12-07 19:05:08 +00:00
|
|
|
}
|
|
|
|
|
2020-02-28 13:47:33 +00:00
|
|
|
<span class="keyword">enum</span> <span class="enum">E</span><<span class="type_param">X</span>> {
|
|
|
|
<span class="enum_variant">V</span>(<span class="type_param">X</span>)
|
2019-12-07 19:05:08 +00:00
|
|
|
}
|
|
|
|
|
2020-02-28 13:47:33 +00:00
|
|
|
<span class="keyword">impl</span><<span class="type_param">X</span>> <span class="enum">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="enum">E</span><<span class="type_param">T</span>> {}
|
2019-05-25 14:23:58 +00:00
|
|
|
}</code></pre>
|