锈蚀

快速、安全、支持并发编程的语言,具备强类型和内存安全特性。

访问

凭证:

  • 用户: ferris
  • 密码:(存储在 /root/.cloudzy-creds)

以root身份通过SSH登录服务器,然后切换到Rust用户:

su - ferris

重要目录

  • /home/ferris/.cargo/ → 货物二进制文件 (cargo(已安装的木箱)
  • /home/费里斯/.rustup/ → Rust 工具链与组件
  • /home/费里斯/ → 您的工作区(项目存放于此)

常用命令

验证安装:

cargo --version
rustc --version

更新Rust:

rustup update

添加/更新额外工具(例如代码检查工具):

rustup component add clippy

卸载Rust:

rustup self uninstall

构建您的项目:

cargo build

运行您的项目:

cargo run

运行测试:

cargo test

为您的项目创建文档:

cargo doc --open

将库发布到 crates.io:

cargo publish

一个小型Rust应用程序

创建新项目:

cargo new hello-rust
cd hello-rust

运行默认程序:

cargo run

通过命令行界面添加依赖项:

cargo add ferris-says

然后构建(Cargo将为我们安装依赖项):

cargo build

这也将产生 Cargo.lock (依赖版本锁定文件)

编辑 src/main.rs:

use ferris_says::say;
use std::io::{stdout, BufWriter};


fn main() {
    let stdout = stdout();
    let message = String::from("Hello fellow Rustaceans!");
    let width = message.chars().count();


    let mut writer = BufWriter::new(stdout.lock());
    say(&message, width, &mut writer).unwrap();
}

运行它:

cargo run

申请详情