Using Cargo

Rustを学び始めると、まもなくRustエコシステムで広く使われているビルドシステム兼パッケージマネージャであるCargoという標準ツールに出会います。ここでは、Cargoの概要や使用方法、そして本講座における重要性について簡単に説明します。

インストール

Please follow the instructions on https://rustup.rs/.

This will give you the Cargo build tool (cargo) and the Rust compiler (rustc). You will also get rustup, a command line utility that you can use to install to different compiler versions.

After installing Rust, you should configure your editor or IDE to work with Rust. Most editors do this by talking to rust-analyzer, which provides auto-completion and jump-to-definition functionality for VS Code, Emacs, Vim/Neovim, and many others. There is also a different IDE available called RustRover.

  • On Debian/Ubuntu, you can also install Cargo, the Rust source and the Rust formatter via apt. However, this gets you an outdated rust version and may lead to unexpected behavior. The command would be:

    sudo apt install cargo rust-src rustfmt