24 days from node.js to Rust
December 1, 2021
A guide to Rust from a node.js developer’s perspective.
Welcome to our 24-post series on getting started with Rust! Each day until Christmas (December 25th 2021) you’ll find another post taking something you know how to do in node.js and translating it to Rust. Today kicks off with you setting up Rust via a tool similar to
rustup. Next up we’ll tackle
- → Day 1: From nvm to rustup
- Day 2: From npm to cargo
- Day 3: Setting up VS Code
- Day 4: Hello World (and your first two WTFs)
- Day 5: Borrowing & Ownership
- Day 6: Strings, part 1
- Day 7: Syntax and Language, part 1
- Day 8: Language Part 2: From objects and classes to HashMaps and structs
- Day 9: Language Part 3: Class Methods for Rust Structs (+ enums!)
- Day 10: From Mixins to Traits
- Day 11: The Module System
- Day 12: Strings, Part 2
- Day 13: Results & Options
- Day 14: Managing Errors
- Day 15: Closures
- Day 16: Lifetimes, references, and
- Day 17: Arrays, Loops, and Iterators
- Day 18: Async
- Day 19: Starting a large project
- Day 20: CLI Arguments & Logging
- Day 21: Building and Running WebAssembly
- Day 22: Using JSON
- Day 23: Cheating The Borrow Checker
- Day 24: Crates & Tools
Day 1: Installing rust with
The equivalent in Rust’s world is rustup.
Rustup manages your Rust installation as well as additonal targets (like WebAssembly) and core tools like
rustup, run it without any subcommands and explore what it has to offer.
$ rustup rustup 1.24.3 (ce5817a94 2021-05-31) The Rust toolchain installer USAGE: rustup [FLAGS] [+toolchain] <SUBCOMMAND> FLAGS: -v, --verbose Enable verbose output -q, --quiet Disable progress output -h, --help Prints help information -V, --version Prints version information ARGS: <+toolchain> release channel (e.g. +stable) or custom toolchain to set override SUBCOMMANDS: show Show the active and installed toolchains or profiles update Update Rust toolchains and rustup check Check for updates to Rust toolchains and rustup default Set the default toolchain toolchain Modify or query the installed toolchains target Modify a toolchain's supported targets component Modify a toolchain's installed components override Modify directory toolchain overrides run Run a command with an environment configured for a given toolchain which Display which binary will be run for a given command doc Open the documentation for the current toolchain man View the man page for a given command self Modify the rustup installation set Alter rustup settings completions Generate tab-completion scripts for your shell help Prints this message or the help of the given subcommand(s) DISCUSSION: Rustup installs The Rust Programming Language from the official release channels, enabling you to easily switch between stable, beta, and nightly compilers and keep them updated. It makes cross-compiling simpler with binary builds of the standard library for common platforms. If you are new to Rust consider running `rustup doc --book` to learn Rust.
rustup show will show you what is currently installed.
rustup completions will help you enable CLI autocompletion for tools like
rustup component lets you add additonal components.
rustup update will update you to the latest version.
rustup install stable|nightly|1.57 will install a specific version or the latest stable/nightly versions.
By default, rustup will install the latest version of
cargo and you should be ready to go right away. Give it a shot with.
$ rustc --version rustc 1.57.0 (59eed8a2a 2021-11-01) $ cargo --version cargo 1.56.0 (4ed5d137b 2021-10-04)
If it doesn’t work, you may need to restart your shell to update your PATH.
Specifying your toolchain with rustup is easy enough. As you get deeper, you may get into configurations where different projects require different toolchains or Rust versions. That’s where
rust-toolchain.toml comes into play. Specify your project’s required toolchain, targets, and supporting tools here so that
rustup can work automagically, e.g.
[toolchain] channel = "1.56.0" components = [ "rustfmt", "clippy" ]
Next up we’ll take a look at
npm and the additional tools that will help reach parity with common workflows: Day 2: From npm to cargo.