Rust is a system programming language that focuses on:
memory safety
This means that Rust prevents common programming errors related to memory management, such as null pointer dereferencing and buffer overflows, without needing a garbage collector.
type safety
Rust has a Hindley-Milner type system that can catch many errors at compile time, reducing runtime errors. This is similar to functional languages like Haskell, OCaml, and ML.
把类型想象成一种“防呆设计”的接口:不同类型的插头形状不同,如果弄错了插头,是插不进去的。这给程序员提供了额外的安全保障owo
low-level control & speed
It is popular for performance-critical applications and systems programming.
This type system supports features like:
Algebraic data types (enums and structs)
Pattern matching
Type inference
Type variables (called generics in Rust)
(Which enables parametric polymorphism)
Optionally : type classes (called traits in Rust)
(Which enables ad-hoc polymorphism)
Install Rust:
visit Rustup and run the following command in your terminal (depending on your OS):
curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | shInstall rustup-init.exe
Install Visual-Studio
Check ‘C++ Desktop’
Run rustup-init.exe
If installation is successful, you can verify it by checking the version:
rustc --versionCreate a new Rust project:
cargo new hello_rust
cd hello_rustInstall rust-analyzer:
VSCode: Install the “rust-analyzer” extension from the marketplace.
For vim there are 6 options, I personally use coc with coc-rust-analyzer.
We shall explore:
Hello world
File read/write
Enigma machine
喵喵给你留下了一段密文
ENCLU UKWQG BRDFA UZLGK JXNTK OTWEL AEQFT IMFAW OTBCS
Homework : 解密喵喵的密文,已知 position = AAA, rings = BBB (or AAA)
rotorL = rotorI of Enigma I , notch at 'Q' (16)
rotorM = rotorII of Enigma I , notch at 'E' (4)
rotorR = rotorIII of Enigma I , notch at 'V' (21)
I EKMFLGDQVZNTOWYHXUSPAIBRCJ Q 1930 Enigma I
II AJDKSIRUXBLHWTMCQGZNPYFVOE E 1930 Enigma I
III BDFHJLCPRTXVZNYEIWGAKMUSQO V 1930 Enigma I
Reflector B YRUHQSLDPXNGOKMIEBFZCWVJAT
decode this:
`ENCLU UKWQG BRDFA UZLGK JXNTK OTWEL AEQFT IMFAW OTBCS`