-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlearning_rust.html
executable file
·294 lines (246 loc) · 8.43 KB
/
learning_rust.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Learning Rust</title>
<link rel="icon" href="crow.ico?" type="image/x-icon">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta property="og:type" content="article"/>
<meta property="og:title" content="Learning Rust"/>
<link rel="feed" type="application/rss+xml" title="Mineral Existence RSS Feed" href="https://mineralexistence.com/feed.xml">
<!-- the below sections enables syntax highlighting when js is enabled, and reverts to the default when it isn't -->
<noscript>
<style>
pre {
font-size:calc(0.5rem + 0.25vw);
line-height:2.3ex;
overflow-x:auto;
padding:2%;
color:var(--bg);
background-color:var(--text);
}
</style>
</noscript>
<script src="./assets/prism.js" defer></script>
<script>
var link = document.createElement("link");
link.rel="stylesheet";
link.href="./assets/prism.css";
link.type="text/css";
document.getElementsByTagName("head")[0].appendChild(link);
</script>
<style>
/* @import url('reset.css'); */
*, *::before, *::after {box-sizing: border-box;}
* {margin: 0;}
body {line-height: 1.5;-webkit-font-smoothing: antialiased;}
img, picture, video, canvas, svg {display: block;max-width: 100%;}
input, button, textarea, select {font: inherit;}
p, h1, h2, h3, h4, h5, h6 {overflow-wrap: break-word;}
#root, #__next {isolation: isolate;}
:root {
/* --text:#3A3738; */
/* --text:#472d30; */
--text:#654735;
/* --bg:#FBF0F0; */
/* --bg:#ffe1a8; */
--bg:#fbf1c7;
--bg-hl:#fcd297;
/* --hl:#80dec5; */
/* --hl:#c9cba3; */
--hl:#45707a;
--hl-orange:#c35e0a;
/* https://utopia.fyi/type/calculator?c=320,18,1.2,1240,20,1.333,3,0,&s=0.75|0.5|0.25,1.5|2|3|4|6,s-l&g=s,l,xl,12 */
--step-0: clamp(1.13rem, calc(1.08rem + 0.22vw), 1.25rem);
--step-1: clamp(1.35rem, calc(1.24rem + 0.55vw), 1.67rem);
--step-2: clamp(1.62rem, calc(1.41rem + 1.05vw), 2.22rem);
--step-3: clamp(1.94rem, calc(1.59rem + 1.77vw), 2.96rem);
/* @link https://utopia.fyi/space/calculator?c=320,18,1.2,1240,32,1.25,5,2,&s=,1.5|2,s-l&g=s,l,xl,12 */
--space-s: clamp(1.13rem, calc(0.82rem + 1.52vw), 2.00rem);
--space-m: clamp(1.69rem, calc(1.23rem + 2.28vw), 3.00rem);
--space-l: clamp(2.25rem, calc(1.64rem + 3.04vw), 4.00rem);
/* One-up pairs */
--space-s-m: clamp(1.13rem, calc(0.47rem + 3.26vw), 3.00rem);
--space-m-l: clamp(1.69rem, calc(0.88rem + 4.02vw), 4.00rem);
/* Custom pairs */
--space-s-l: clamp(1.13rem, calc(0.13rem + 5.00vw), 4.00rem);
}
body {
font-size:var(--step-0);
font-family:sans-serif;
max-width:72ch;
margin: var(--space-m-l);
/* padding: 0 1rem; */
line-height:1.6;
color:var(--text);
background-color:var(--bg);
}
/* * {border: 1px solid black;} */
main > *+* {margin-top: var(--space-s);}
h1,
h2,
h3,
h4,
h5,
h6 {
font-family: serif;
}
h1 { font-size: var(--step-3); }
h2 { font-size: var(--step-2); }
h3 { font-size: var(--step-1); }
/* header>h1 {display:inline-block;padding-right:.3em;} */
header {margin: 0 0 var(--space-l) 0;clear:both;}
mark {background-color:var(--hl);color:var(--bg);}
hr {height:1px;border-width:0;color:var(--text);background-color:var(--text)}
a {color:var(--hl);}
a:visited {color:var(--hl-orange);}
pre {
font-size:calc(var(--step-0) + 0.15rem);
line-height:2.3ex;
overflow-x:auto;
padding:2%;
color:var(--bg);
background-color:var(--text);
}
code {
font-family: monospace;
color:var(--bg);
background-color:var(--text);
font-size:calc(var(--step-0) + 0.15rem);
padding-left: 0.2em;
padding-right: 0.2em;
}
button {
border-radius: 8px;
border: 1px solid var(--text);
background: none;
padding: 0px 10px;
font-weight: bold;
font-family: sans;
color: var(--text);
font-size: 20px;
}
button:hover {color: var(--bg);background: var(--text);}
dd {margin-left:var(--space-s);}
details {padding-bottom:0ex;}
fieldset {border:1px solid;}
::selection {color: var(--bg);background-color: var(--text);}
footer {margin:var(--space-l) 0 0 0;clear:both}
footer>* {display:inline-block;}
footer img {margin:0 0 -10px 0;width:30px;}
/* .half {width: 50%; height: auto;} */
/* .left {margin-top: 0em;float: left;margin-right: 2em;clear: both;} */
/* .block {margin-top: 1em;margin-left: 0px;clear: both;} */
.third {width: 31%; height: auto;}
.container {padding: var(--space-s); border: solid 1px var(--text);border-radius: 5px;}
.row {display: flex;}
.column {flex: 50%;}
.listing > span {float: right;}
.box {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(256px, 1fr));
gap: 0.5em;
grid-auto-flow: dense;
}
ul[role=list] {
list-style: none;
margin: 0;
padding: 0;
}
.nav-main ul {
flex-flow: wrap;
justify-content: flex-start;
align-items: center;
gap: 5px 20px;
display: flex
}
.nav--main a {
text-decoration: none
}
.inline-img {
height: 33px;
display: inline-block;
border: 1px solid var(--text);
position: relative;
left: 0.25em;
top: 0.25ex;
}
*:not(footer)>a[href*=':']::before{content:"↗"}
</style>
</head>
<body>
<header>
<nav class="nav-main" role="navigation">
<ul role="list">
<li><h1><a href="home.html">Home</a></h1> </li>
<li><h1><a href="now.html">now</a></h1></li>
<li><h1><a href="wiki.html">wiki</a></h1></li>
<li><h1><a href="about.html">about</a></h1></li>
</ul>
</nav>
</header>
<main>
<h2>Learning Rust</h2>
<p>First of all, this is going to primarily be a place to store notes for myself as I learn Rust, so take everything I say with a grain of salt! (and feedback is always appreciated, so feel free to say hi)</p>
<p>Good resources:</p>
<ul>
<li><a href="https://doc.rust-lang.org/book">The Rust Programming Language</a></li>
<li><a href="https://www.vandenoever.info/blog/2017/02/17/a-simple-rust-gui-with-qml.html">Simple Rust GUI with QML</a></li>
<li><a href="https://www.youtube.com/playlist?list=PLVvjrrRCBy2JSHf9tGxGKJ-bYAN_uDCUL">Rust Programming Tutorial</a></li>
</ul>
<p>Things to remember:</p>
<ul>
<li>variable(y) things<ul>
<li>variables need the "mut" tag to be changeable</li>
<li>it's statically typed! (but has inference)</li>
<li>tuples can hold different types, arrays cannot<ul>
<li>values in tuples can be accessed through "tuple.index"</li>
</ul></li>
<li>vectors are like arrays, but they can change size</li>
<li>arrays can be defined as "let arr = [3; 4];", which would expand to "[3, 3, 3, 3]"</li>
<li>"&" means a reference to an object</li>
<li>enums have a fixed set of variables, called the variants</li>
<li>can reassign variables, overwriting previous type and value (good for converting between types), called shadowing</li>
<li>always have to annotate type for constants</li>
</ul></li>
<li>style things<ul>
<li>most names should be in "snake_case"</li>
<li>types, enums, and traits should be in "CamelCase"</li>
<li>anything static/constant should be in "SCREAMING_SNAKE_CASE"</li>
<li>use underscores in big numbers to break them up ("10_000_000")</li>
</ul></li>
<li>various functions/expression things<ul>
<li>".expect()" is used to handle possible errors, but panics if there is an error</li>
<li>the "match" expression<ul>
<li>is made of arms</li>
<li>each arm has a pattern and some code to run</li>
<li>connect the code to the pattern with "=>"</li>
<li>separate the arms with commas, not semicolons</li>
<li>can also use "match" instead of a ".expect()" to handle errors (match output to "Ok" and "Err")</li>
</ul></li>
</ul></li>
<li>miscellaneous things<ul>
<li>if it looks like a function but has a "!" at the end, it's a macro (?? what's a macro ??)</li>
<li>"::" refers to an associated function of a "type" (static method)</li>
<li>the "Result" enum has two variants, "Ok" and "Err"</li>
<li>"gen_range()" is inclusive on the lower bound and exclusive on the upper</li>
<li>can use "cargo doc --open" to view the documentation of the packages in your project</li>
</ul></li>
</ul>
<p>Things I'm not sure about</p>
<ul>
<li>macros</li>
<li>traits</li>
</ul>
<p><b>Incoming:</b> <a href=".html"></a> <a href=".html"></a> </p>
</main>
<footer>
<img loading="lazy" style="width:88px;height:31px;margin-left:0.5ex;" title="my homemade site banner!" alt="site banner" src="images/icon.gif"/>
<a href="mailto:[email protected]">email</a>
<a href="https://merveilles.town/@flbr">fedi</a>
<a href="https://webring.xxiivv.com/#icons">webring</a>
<span style="float: right;"><em>Last updated: 041923</em></span>
</footer>
</body>
</html>