鍍金池/ 教程/ Java/ Rust 版本管理工具: rustup
標準輸入與輸出
消息傳遞
循環(huán)
注釋
Rust for Mac OS
幾種智能指針
Cell, RefCell
trait對象 (trait object)
rust web 開發(fā)
Unsafe、原始指針
Macro
迭代器
函數(shù)
Borrow, BorrowMut, ToOwned
快速上手
二叉樹
編輯器
測試與評測
Deref
安裝Rust
哈希表 HashMap
原生類型
17.錯誤處理
VS Code 安裝配置
動態(tài)數(shù)組Vec
模式匹配
操作符和格式化字符串
Rust for Linux
函數(shù)參數(shù)
Visual Studio
vim/GVim安裝配置
閉包作為參數(shù)和返回值
安全(Safety)
Cow
生命周期( Lifetime )
閉包的實現(xiàn)
所有權(quán)(Ownership)
Atom
將Rust編譯成庫
類型、運算符和字符串
類型系統(tǒng)中的幾個常見 trait
特性
屬性和編譯器參數(shù)
Spacemacs
集合類型
Rust json處理
Heap & Stack
并行
標準庫示例
基本程序結(jié)構(gòu)
鏈表
trait 和 trait對象
前期準備
代碼風格
編譯器參數(shù)
基于語義化版本的項目版本聲明與管理
Rust 版本管理工具: rustup
引用&借用(References&Borrowing)
注釋與文檔
10.1 trait關(guān)鍵字
模式
調(diào)用ffi函數(shù)
unsafe
并發(fā),并行,多線程編程
AsRef 和 AsMut
Rust旅程
Rust for Windows
結(jié)構(gòu)體與枚舉
條件分支
附錄I-術(shù)語表
變量綁定與原生類型
Mutex 與 RwLock
泛型
裸指針
常用數(shù)據(jù)結(jié)構(gòu)實現(xiàn)
系統(tǒng)命令:調(diào)用grep
Into/From 及其在 String 和 &str 互轉(zhuǎn)上的應用
共享內(nèi)存
Sublime
網(wǎng)絡模塊:W貓的回音
函數(shù)返回值
包和模塊
高階函數(shù)
函數(shù)與方法
match關(guān)鍵字
隊列
目錄操作:簡單grep
語句和表達式
并發(fā)編程
閉包
測試
閉包的語法
同步
迭代器
String
Send 和 Sync
Rc 和 Arc
屬性
Emacs
優(yōu)先隊列
Prelude
cargo簡介
控制流(control flow)
數(shù)組、動態(tài)數(shù)組和字符串
FFI
模塊和包系統(tǒng)、Prelude
實戰(zhàn)篇
Rust 是一門系統(tǒng)級編程語言,被設計為保證內(nèi)存和線程安全,并防止段錯誤。作為系統(tǒng)級編程語言,它的基本理念是 “零開銷抽象”。理
運算符重載
Any和反射
rust數(shù)據(jù)庫操作
輸入輸出流
復合類型
性能測試

Rust 版本管理工具: rustup

rustup 是rust官方的版本管理工具。應當作為安裝 Rust 的首選。

項目主頁是: https://github.com/rust-lang-nursery/rustup.rs

Features

  • 管理安裝多個官方版本的 Rust 二進制程序。
  • 配置基于目錄的 Rust 工具鏈。
  • 安裝和更新來自 Rust 的發(fā)布通道: nightly, beta 和 stable。
  • 接收來自發(fā)布通道更新的通知。
  • 從官方安裝歷史版本的 nightly 工具鏈。
  • 通過指定 stable 版本來安裝。
  • 安裝額外的 std 用于交叉編譯。
  • 安裝自定義的工具鏈。
  • 獨立每個安裝的 Cargo metadata。
  • 校驗下載的 hash 值。
  • 校驗簽名 (如果 GPG 存在)。
  • 斷點續(xù)傳。
  • 只依賴 bash, curl 和常見 unix 工具。
  • 支持 Linux, OS X, Windows(via MSYS2)。

安裝

Windows

rustup的主頁下載并運行rustup-init.exe,并按照提示選擇選項。

Welcome to Rust!

This will download and install the official compiler for the Rust programming
language, and its package manager, Cargo.

It will add the cargo, rustc, rustup and other commands to Cargo's bin
directory, located at:

  C:\Users\Liqueur Librazy\.cargo\bin

This path will then be added to your PATH environment variable by modifying the
HKEY_CURRENT_USER/Environment/PATH registry key.

You can uninstall at any time with rustup self uninstall and these changes will
be reverted.

Current installation options:

   default host triple: x86_64-pc-windows-msvc
     default toolchain: stable
  modify PATH variable: yes

1) Proceed with installation (default)
2) Customize installation
3) Cancel installation

三個選項分別是

1) 開始安裝(默認選項) 2) 自定義安裝 3) 取消

其中自定義安裝可以更改默認架構(gòu)與工具鏈、是否添加 PATH。例如想要選擇 nightly 工具鏈可以進行以下自定義

I'm going to ask you the value of each these installation options.
You may simply press the Enter key to leave unchanged.

Default host triple?

Default toolchain? (stable/beta/nightly)
nightly

Modify PATH variable? (y/n)

設置完畢后,選擇 1 以開始安裝。

Linux & macOS

運行以下命令

curl https://sh.rustup.rs -sSf | sh

這個命令將會編譯和安裝 rustup, 安裝過程中可能會提示你輸入 sudo 的密碼。 然后, 他會下載和安裝 stable 版本的工具鏈, 當執(zhí)行 rustc, rustdoc 和 cargo 時, 將會配置他為默認工具鏈。

Unix 上安裝后工具鏈會被安裝到 $HOME/.cargo/bin 目錄。

.cargo/bin 目錄會被添加到系統(tǒng)的 $PATH 環(huán)境變量,重新登錄后即可使用 rustc,cargo 等命令。

卸載

rustup self uninstall

用法

安裝后會得到一個 rustup 命令, 多使用命令自帶的幫助提示, 可以快速定位你需要功能。

幫助

運行 rustup -h 你將會得到如下提示:

? rustup -h
rustup 1.5.0 (92d0d1e9e 2017-06-24)
The Rust toolchain installer

USAGE:
    rustup.exe [FLAGS] [SUBCOMMAND]

FLAGS:
    -v, --verbose    Enable verbose output
    -h, --help       Prints help information
    -V, --version    Prints version information

SUBCOMMANDS:
    show           Show the active and installed toolchains
    update         Update Rust toolchains and rustup
    default        Set the default toolchain
    toolchain      Modify or query the installed toolchains
    target         Modify a toolchain's supported targets
    component      Modify a toolchain's installed components
    override       Modify directory toolchain overrides
    run            Run a command with an environment configured for a given toolchain
    which          Display which binary will be run for a given command
    doc            Open the documentation for the current toolchain
    self           Modify the rustup installation
    set            Alter rustup settings
    completions    Generate completion scripts for your shell
    help           Prints this message or the help of the given subcommand(s)

DISCUSSION:
    rustup installs The Rust Programming Language from the official
    release channels, enabling you to easily switch between stable,
    beta, and nightly compilers and keep them updated. It makes
    cross-compiling simpler with binary builds of the standard library
    for common platforms.

    If you are new to Rust consider running `rustup doc --book` to
    learn Rust.

根據(jù)提示, 使用 rust help <command> 來查看子命令的幫助。

rustup doc --book 會打開英文版的 The Rust Programming Language。

常用命令

rustup default <toolchain> 配置默認工具鏈。

rustup show 顯示當前安裝的工具鏈信息。

rustup update 檢查安裝更新。

rustup toolchain [SUBCOMMAND] 配置工具鏈

  • rustup toolchain install <toolchain> 安裝工具鏈。
  • rustup toolchain uninstall <toolchain> 卸載工具鏈。
  • rustup toolchain link <toolchain-name> "<toolchain-path>" 設置自定義工具鏈。

其中標準的 <toolchain>具有如下的形式

`<channel>[-<date>][-<host>]`
<channel>       = stable|beta|nightly|<version>
<date>          = YYYY-MM-DD
<host>          = <target-triple>

stable-x86_64-pc-windows-msvc nightly-2017-7-25 1.18.0 等都是合法的toolchain名稱。

rustup override [SUBCOMMAND] 配置一個目錄以及其子目錄的默認工具鏈

使用 --path <path> 指定目錄或在某個目錄下運行以下命令

  • rustup override set <toolchain> 設置該目錄以及其子目錄的默認工具鏈。
  • rustup override unset 取消目錄以及其子目錄的默認工具鏈。

使用 rustup override list 查看已設置的默認工具鏈。

rustup target [SUBCOMMAND] 配置工具鏈的可用目標

  • rustup target add <target> 安裝目標。
  • rustup target remove <target> 卸載目標。
  • rustup target add --toolchain <toolchain> <target> 為特定工具鏈安裝目標。

rustup component 配置 rustup 安裝的組件

  • rustup component add <component> 安裝組件
  • rustup component remove <component> 卸載組件
  • rustup component list 列出可用組件

常用組件:

  • Rust 源代碼 rustup component add rust-src
  • Rust Langular Server (RLS) rustup component add rls
上一篇:Mutex 與 RwLock下一篇:Spacemacs