# study_rust **Repository Path**: haifengat/study_rust ## Basic Information - **Project Name**: study_rust - **Description**: rust 学习笔记及代码示例 - **Primary Language**: Rust - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2022-11-22 - **Last Updated**: 2023-03-18 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # study_rust ## 介绍 ## 安装教程 ### rustup ```sh # 镜像加速,使用的是中科大的源,速度很快 # ~/.bashrc export RUSTUP_DIST_SERVER=https://mirrors.ustc.edu.cn/rust-static export RUSTUP_UPDATE_ROOT=https://mirrors.ustc.edu.cn/rust-static/rustup # 也可用以下配置 export RUSTUP_DIST_SERVER="https://rsproxy.cn" export RUSTUP_UPDATE_ROOT="https://rsproxy.cn/rustup" # 安装 curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh ``` ### crate - 源加速 `~/.cargo/config` ```toml [source.crates-io] registry = "https://github.com/rust-lang/crates.io-index" # 指定镜像 replace-with = 'rsproxy' [source.rsproxy] registry = "https://rsproxy.cn/crates.io-index" [registries.rsproxy] index = "https://rsproxy.cn/crates.io-index" [http] check-revoke = false [net] git-fetch-with-cli = true ``` ### rust-analyzer - 安装 ```sh git clone https://github.com/rust-lang/rust-analyzer.git && cd rust-analyzer cargo xtask install --server ``` - 配置 settings.json 目录结构 ```sh project ┕━ .vscode ┕━settings.json ┕━ src ┕━ main.ts Cargo.toml ``` ```json { # 下面这行,必须加在 .vscode/settings.json 路径可用 whereis rust-analyzer 查看 "rust-analyzer.server.path": "/root/.cargo/bin/rust-analyzer", # 以下配置可放在用户的 settings.json "rust-analyzer.trace.extension": true, "rust-analyzer.checkOnSave.target": "x86_64-unknown-linux-gnu", "editor.formatOnSave": true, } ``` ### vscode 插件 - rust-analyzer - Rust Syntax - crates - Creates Completer - Rust Test Lens - Tabnine AI Autocomplete - Better TOML ## 使用说明 ### cargo - 创建项目 `cargo new 项目名(目录)` - 检查 `cargo check` - 编译 `cargo build` - 运行 `cargo run` 编译并运行 - 发布 `cargo build --release`