# Rust rust 语言 可以开发命令行,web,嵌入式。文件 *.rs* 结尾 ``` fn main() { println!("Hello World!"); } ``` 编译运行: ``` rustc hello.rs ./hello # 或者 cargo 编译 cargo build cargo run ``` ## Develop rust,vs, vscode, 安装vs主要是安装C++编译工具(**MSVC** )。 https://static.rust-lang.org/rustup/dist/i686-pc-windows-gnu/rustup-init.exe 安装: ``` curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y export PATH="$HOME/.cargo/bin:$PATH" ``` docker方式安装: ``` docker run --rm -it -w /app -v $(pwd)/docs:/app rust:latest ``` 设置国内镜像: ``` vim ~/.cargo/config [source.crates-io] replace-with = 'aliyun' # 指定使用下面哪个源,修改为source.后面的内容即可 #阿里云 [source.aliyun] registry = "sparse+https://mirrors.aliyun.com/crates.io-index/" # 中国科学技术大学 [source.ustc] registry = "https://mirrors.ustc.edu.cn/crates.io-index" # 上海交通大学 [source.sjtu] registry = "https://mirrors.sjtug.sjtu.edu.cn/git/crates.io-index/" # 清华大学 [source.tuna] registry = "https://mirrors.tuna.tsinghua.edu.cn/git/crates.io-index.git" # rustcc社区 [source.rustcc] registry = "https://code.aliyun.com/rustcc/crates.io-index.git" ``` 命令: ``` cargo install create-tauri-app --locked cargo create-tauri-app cargo new demo1 cargo build cargo build --release cargo run cargo test cargo check # 增加依赖 cargo add xx cargo update cargo metadata # 格式化代码 cargo fmt # 生成文档 cargo doc # 包发布到 creates.io cargo publish ``` 构建文档,采用 mdbook,类似gitbook主题,先安装rust: ``` # 安装 mdbook cargo install --git https://github.com/rust-lang/mdBook.git mdbook mdbook init mybook # 数学公式 cargo install mdbook-katex # 代码块 cargo install mdbook-admonish mdbook-admonish install # 导出pdf,会安装 chromium cargo install mdbook-pdf cargo install mdbook-pdf --features fetch pip install mdbook-pdf-outline mdbook serve --open mdbook build ``` ## Reference * [rust 文档](https://wiki.yoqi.me/rust-note/) * [rust 网站](https://play.rust-lang.org/) * https://github.com/photino/rust-notes * https://github.com/xuesongbj/Rust-Notes * https://github.dev/brson/my-rust-lists * https://github.com/wx-chevalier/CS-Notes * https://github.com/rust-lang/cargo * https://github.com/rust-lang/rust