Rust---hello world


安装

curl https://sh.rustup.rs -sSf | sh
source $HOME/.cargo/env

检查安装

cargo --version

创建新项目

cargo new hello-rust

运行

cd hello-rust/
cargo run

结果
Hello, world!

添加依赖

vim Cargo.toml

[dependencies]
ferris-says = "0.1"

安装依赖

cargo build

编辑 src/main.rs

use ferris_says::say; // from the previous step
use std::io::{stdout, BufWriter};

fn main() {
    let stdout = stdout();
    let out = b"Hello fellow Rustaceans!";
    let width = 24;

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

运行

cargo run

结果

----------------------------
| Hello fellow Rustaceans! |
----------------------------
              \
               \
                  _~^~^~_
              \) /  o o  \ (/
                '_   -   _'
                / '-----' \

参考
https://www.rust-lang.org/zh-CN/learn/get-started

你可能感兴趣的:(Rust)