ESSAY / NOTE

编写第一个RUST程序

我们已经完成了RUST安装接下来在命令行运行
cargo new hello-rust 创建新项目
在Cargo.toml 添加依赖库
[dependencies]
ferris-says = "0.2"
运行cargo build 会自动安装完成后会在Cargo.lock中显示这个包 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.as_bytes(),width,&mut writer).unwrap();
}
cargo run 运行 Cargo命令
cargo build 构建项目
cargo run 运行项目
cargo test 测试项目
cargo doc 为项目构建文档
cargo publish 可以将库发布到crates.io
cargo --version 检查是否安装了Rust和Cargo