使用 Cargo

开始了解 Rust 后,你很快就会遇到 Cargo,这是 Rust 生态系统中用于构建和运行 Rust 应用的标准工具。在这里,我们想简要介绍一下什么是 Cargo、它如何融入更广泛的生态系统, 以及我们如何在本培训中合理利用 Cargo。

安装

请按照 https://rustup.rs/ 上的说明操作。

这将为你提供 Cargo 构建工具 (cargo)和 Rust 编译器 (rustc)。你还将获得 rustup,这是一个命令行实用程序,你可以用它来安装不同的编译器版本。

安装 Rust 之后,你应当配置你的编辑器或 IDE 以开始使用 Rust。大多数编辑器使用了 rust-analyzer。它为 VS CodeEmacsVim/Neovim 及其他许多编辑器提供了自动补全及定义跳转的功能。同样也可以使用 RustRover IDE。

  • On Debian/Ubuntu, you can install rustup via apt:

    sudo apt install rustup
    
  • On macOS, you can use Homebrew to install Rust, but this may provide an outdated version. Therefore, it is recommended to install Rust from the official site.