-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnotes
More file actions
85 lines (54 loc) · 1.83 KB
/
Copy pathnotes
File metadata and controls
85 lines (54 loc) · 1.83 KB
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
Books
https://doc.rust-lang.org/book/
https://doc.rust-lang.org/rust-by-example/index.html
https://doc.rust-lang.org/nightly/nomicon/intro.html
OpenGL
http://nercury.github.io/rust/opengl/tutorial/2018/02/08/opengl-in-rust-from-scratch-00-setup.html
Vim Plugins
https://github.com/rust-lang/rust.vim
Install Rust:
$ sudo snap install --classic rustup
$ rustup toolchain install stable
$ rustup update
$ rustc --version
rustc 1.47.0 (18bf6b4f0 2020-10-07)
Start a project:
$ cargo new projectname
Compile a project:
$ cargo build
Run the code
$ cargo run
Any 0.* version of a dependency, in Cargo.toml:
[dependencies]
depname = "^0"
Show package dependencies:
$ cargo tree
Rust Language Server
https://github.com/dense-analysis/ale/blob/master/doc/ale-rust.txt
$ rustup component add rls rustfmt rust-analysis rust-src
### Cargo-edit
$ cargo install cargo-edit
$ cargo add base64
### Printing
format!
print!
println!
"{}" invokes Display trait
"{:?}" invokes Debug trait
"{:#}" alternate format, usually multi-line
### Logging
API provided by `log` crate.
Implementation provided by `env_logger` crate.
dbg! can show local variables easily
### Crates and Modules
`extern crate` is no longer needed as of Rust 2018, just do `use` instead.
### String encoding and decoding
### Async
Can't use std::thread::sleep, which is blocking. Instead use async_std::task::sleep.
Futures require their result to be a Pin. This causes problems unless you can also create an Unpin implementation for the result.
Unpin auto-trait is not created for tuples, because they do not have a fixed memory layout. Use a real struct instead.
### Scratch
See auto trait implementations via cargo doc:
$ cargo doc --document-private-items --open
The macro todo!() panics, but can be used as a placeholder for functions that need to return a result of a
particular type.