--j
id: KrmgjrqydqC65v4Za1t6c
title: Rust
desc: ""
updated: 1659872186436
created: 1622307866939
The main thing why i and other people want rust ... is that it does not have programming.undefined-behavior in the safe subset.
– LVC21F-317 Rust for Linux
Features
- Shared & exclusive references
- MOdules & visibliity
- Generics
- Lifetimes
- Stricter type systems
- Pattern matching
- Safe/unsafe split
- RAII
- Sum typesPowerful hygienic and procedural macros
- standalone standard library
- Vocabulary types like
Result
and Options
- Pinning
- Formating
- Checked, saturating & wrapping integer arithmetic primitives
- Iterators
- tool
- documentation generator
- unit & integration tests
- static analyzer
- c<->rust bindings generators
- linter
- formatter
- IDE tooling
- macro debugging
- UBSAN-like interpreter
- plust the usual friends: gdb, 11db, perf, valgrind
Nuggets
- functions use the
fn
keyword. This is just like function
in javascript.
- Macros are called just like functions but with the additional
!
before the parenthesis.
- Strings in rust use double quotes
"
. You cannot use '
or ```.
- Unlike JavaScript, semicolons in Rust are not optional. Every statement in Rust must end with a semicolon.
- Every Rust program needs to have a
main
function.
- all variables created using
let
are immutable by default. (You just can't assign them more than once.)
- The
mut
keyword allows the variable to be mutable.
const
are compile time known constants, Rust will not infer their type for you and you will need to provide a type
- Since most of us are using 64-bit machines these days, stick to
u64
, i64
and f64
unless you have a good reason.
- The
::
in Rust is much like the dot operator in JavaScript when it comes to types and namespaces.
- all elements in an Array must be of the same type.
cargo
will by default look for src/main.rs
and use the package.name
field as the binary name
- Packages can have lang.rust.t.target#library, lang.rust.t.target#binary, lang.rust.t.target#example, lang.rust.t.target#test, and lang.rust.t.target#benchmark targets.
What can I do with Rust?. A small, incomplete list.
- Serverless functions
- Serverful services
- Embedded programming for microcontrollers, Arduinos, or Raspberry Pis
- CLI tools
- Enhance the performance of JS/Ruby/Elixir/etc by calling out to Rust
- Compile to Wasm and deploy to the edge, browser, and more
- Game development
- Operating systems and shells
bundler
Links