https://www.recurse.com/manual
Rust is a statically and strongly typed modern systems programming language focusing on safety, speed, and concurrency. It accomplishes these goals by being memory safe without using garbage collection.
all types are known at compile-time
types are designed to make it harder to write incorrect programs
generating the best possible machine code with full control of memory use
e.g. OS, device drivers
traffic mesh
netlify-toml-rs
traffic controller
netlify-headers-rs
...
Package Manager | npm | crates |
Version Manager | nvm | rustup |
Registry | npmjs.com | crates.io |
Config | package.json | cargo.toml |
Task Runner | npm scripts/gulp | make / cargo run |
Linter | eslint/tslint | clippy |
Formatter | prettier | rustfmt |
JavaScript | Rust |
---|
$ curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | sh
[[ Install Rustup ]]
https://www.rust-lang.org/tools/install
windows
mac
├── babys_first_rust/ ├── main.rs └── main
executable
your code
fn main() { println!("Hello, world!"); }
fn main() { println!("Hello, world!"); }
4 spaces
end of expression
first code that runs in every executable Rust program
console log macro
println!("Hello {}", SOME_VAR);
println!("Hello {:?}", "world");
rustc main.rs
./main
├── babys_first_rust/
├── src
├── main.rs └── cargo.toml
your config
your code
[package] name = "hello_cargo" version = "0.1.0" authors = ["Your Name <you@example.com>"] edition = "2018" [dependencies]
cargo build
./target/debug/hello_cargo
OR
cargo run
Type | Example Values |
---|---|
bool | true/false |
char | ❤️, a, 東京 |
i8, i16, i32, i64, isize | -5, 42, |
u8, u16, u32, u64, usize | 5, 42 |
f32, f64 | 3.14, 4,5 |
array | let array: [i32; 5] = [0, 1, 2, 3, 4]; |
slice | let slice = &array[0..3]; |
str | "Hello World" |
tuple | let tuple = ("hello", 42, "world", [3,6,9]); |
The rules of raindrops are that if a given number:
pub fn raindrops(n: u32) -> String {
let mut sound = String::new();
...
}