一、安裝
rust安裝部署相對簡單,我們可以直接參考官網安裝
curl https://sh.rustup.rs -sSf | sh
source $HOME/.cargo/env
rustc --version
如果顯示版本號、提交的 hash 值和提交時間,恭喜你!則 Rust 已成功安裝!cargo --version
如果你看到了版本號,一切 OK!
二、idea開發環境搭建
- 創建項目
cargo new hello_world --bin
這個命令傳遞了--bin參數因爲我們的目標是直接創建一個可執行程序,而不是一個庫。 - 導入到IDE,這裏選的是IntelliJ,先安裝rust插件,雙擊
shift
鍵,輸入plugin
- 選中之後搜索安裝就好了,重啓IDE,用IDE打開Project,找到main.rs,直接右鍵運行,如果看到
missing xcrun at:XXXXX
說明你的mac缺少命令行工具,可以選擇安裝命令行工具或者xcode,下載地址,登陸後下載 - 卸載命令:
rustup self uninstall
,在安裝時有提示該命令
三、環境測試
1.idea打開新建項目hello_word
2.打印相關輸出
/Users/zhangpeng/.cargo/bin/cargo run --color=always --package hello_world --bin hello_world
Compiling hello_world v0.1.0 (/data/project/hello_world)
Finished dev [unoptimized + debuginfo] target(s) in 0.33s
Running `/data/project/hello_world/target/debug/hello_world`
Hello, Arvin, http://www.chinad.top 歡迎你 !
Hello, world!
Process finished with exit code 0