Assorted Rust tutes
- RustRover or others with IntelliJ Rust plugin
- Use
rustup
to install Rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source $HOME/.cargo/env
which cargo
which rustc
which rustup
cargo --version
rustc --version
rustup update
mkdir hello_world
cd hello_world
vi main.rs
rustc main.rs
./main
rustc main.rs -o main.exe
./main.exe
- Cargo get-started
cargo new --help
cargo new --vcs none hello-rust
cd hello-rust
cargo run
./target/debug/hello-rust
tree .
(add 'ferris-says = "0.2"' to dependencies section in Cargo.toml and correspondent code in main.rs)
cargo clean
cargo check
cargo build
cargo run
tree -L 2 target
cargo build --release
tree -L 2 target
./target/release/hello-rust
- The program entrypoint is a function named
main()
, typically inmain.rs
rustup
-- the Rust installer and version management toolcargo
-- the Rust build tool and package managerCargo.toml
-- Cargo config that use toml formatCargo.lock
-- git ignored for libraries, git tracked for binaries- Cargo prescribe a convention for project layout -- much resemble to Maven
- https://crates.io -- the Rust package registry
cargo doc --open
-- generate documentation including dependencies- Also note about Rust underscore vs hyphen -- similar to Python import hyphen -- a Rust module import/include valid identifier is underscore i.e.
use foo_module::bar_func
Just like others, such as yarn global add <foo>
or npm -g install <bar>
for some tool written in NodeJS eco-system; or pip install <foo>
or pipx install <bar>
for Python; or go get github.com/some/xtool
for Go; etc... we can use Cargo install for some tool that is written in Rust.
cargo install --help
cargo help install
# e.g. WebSocket cli client
cargo search websocat
cargo install websocat
which websocat
websocat --help
- modsys -- code organization and module system
- primer -- language basic
- testing -- code testing
- cross-build -- building for different platforms
- guessing_game -- example app