内容简介:不建议使用第三方包管理器安装Rust。建议使用官方的脚本一键安装安装脚本:
不建议使用第三方包管理器安装Rust。
建议使用官方的脚本一键安装 Rustup
(Rust版本管理器)到$HOME目录。不需要Root权限,也便于以后切换版本
安装脚本: curl https://sh.rustup.rs -sSf | sh
安装完成后,需要将 Cargo
的 bin
目录添加到 PATH
环境变量
这个 bin
目录大概有这些文件:
cargo cargo-fmt rust-gdb rustc rustfmt cargo-clippy rls rust-lldb rustdoc rustup
永久添加: 编辑 ~/.bashrc
或 ~/.zshrc
,添加一行
export PATH=$HOME/.cargo/bin:$PATH
一次性添加: source ~/.cargo/env
Rust之HelloWorld
cargo new hello-rust cd hello-rust cargo run
目录结构
├── Cargo.toml └── src └── main.rs
Cargo.toml
[package] name = "hello-rust" version = "0.1.0" authors = ["BaiJiFeiLong <baijifeilong@gmail.com>"] edition = "2018" [dependencies]
src/main.rs
fn main() { println!("Hello, world!"); }
控制台输出
Hello, world!
Rust引入第三方库
1. 编辑Cargo.toml,添加依赖项
[package] name = "untitled" version = "0.1.0" authors = ["BaiJiFeiLong <baijifeilong@gmail.com>"] edition = "2018" [dependencies] ferris-says = "0.1"
2. 安装依赖
cargo build
或者
cargo run
3. 使用依赖
src/main.rs
fn main() { use ferris_says::*; use std::io::{stdout, BufWriter}; let stdout = stdout(); let out = b"Hello World"; let width = 24; let mut writer = BufWriter::new(stdout.lock()); say(out, width, &mut writer).unwrap(); }
控制台输出
---------------------------- | Hello World | ---------------------------- \ \ _~^~^~_ \) / o o \ (/ '_ - _' / '-----' \
以上所述就是小编给大家介绍的《Rust大杂烩》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!
猜你喜欢:本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Introduction to Linear Optimization
Dimitris Bertsimas、John N. Tsitsiklis / Athena Scientific / 1997-02-01 / USD 89.00
"The true merit of this book, however, lies in its pedagogical qualities which are so impressive..." "Throughout the book, the authors make serious efforts to give geometric and intuitive explanations......一起来看看 《Introduction to Linear Optimization》 这本书的介绍吧!