Rust入門-mac下安裝及idea開發環境搭建

一、安裝

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參數因爲我們的目標是直接創建一個可執行程序,而不是一個庫。
  • Rust入門-mac下安裝及idea開發環境搭建|百賺網
  • 導入到IDE,這裏選的是IntelliJ,先安裝rust插件,雙擊shift鍵,輸入plugin
  • 選中之後搜索安裝就好了,重啓IDE,用IDE打開Project,找到main.rs,直接右鍵運行,如果看到missing xcrun at:XXXXX說明你的mac缺少命令行工具,可以選擇安裝命令行工具或者xcode,下載地址,登陸後下載
  • 卸載命令:rustup self uninstall,在安裝時有提示該命令

三、環境測試

1.idea打開新建項目hello_word

Rust入門-mac下安裝及idea開發環境搭建|百賺網

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

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章