基础能力系列 - Rust - HelloWorld

安装环境

# 从国内镜像下载(下载速度快)
export RUSTUP_DIST_SERVER=https://mirrors.ustc.edu.cn/rust-static
export RUSTUP_UPDATE_ROOT=https://mirrors.ustc.edu.cn/rust-static/rustup

# 安装 rustup 和 stable 版本
curl https://sh.rustup.rs -sSf | sh
source $HOME/.cargo/env

# 安装 nightly 版本 (vscode需要配置nightly版本使用)
rustup install nightly 
# 设置默认的工具链版本 stable | nightly
rustup default stable
# or
rustup default nightly
# 查看版本
rustc --version

rustup会在Cargo目录下安装rustc、cargo、rustup,以及其他一些标准工具。类UNIX平台默认安装于$HOME/.cargo/bin,Windows平台默认安装于%USERPROFILE%.cargo\bin

hello world

#使用 Cargo 创建项目
cargo new hello_cargo

cd hello_cargo

check
cargo check

#编译并生成可执行文件
cargo build

cargo build --release

#编译, 生成可执行文件 并运行
cargo run


#新建库项目
cargo new add-one --lib

#更新库
cargo update

#构建所有本地依赖提供的文档,并在浏览器中打开
cargo doc --open

#测试 (也会进行文档注释的测试)
cargo test

#从 Crates.io 安装二进制文件
cargo install ripgrep


往期精彩回顾:
区块链知识系列
密码学系列
零知识证明系列
共识系列
公链调研系列
比特币系列
以太坊系列
EOS系列
Filecoin系列
联盟链系列
Fabric系列
智能合约系列

猜你喜欢

转载自blog.csdn.net/wcc19840827/article/details/127607070