Rust学习一
一 安装
-
命令行安装 curl --proto ‘=https’ --tlsv1.2 https://sh.rustup.rs -sSf | sh
-
查看版本 rustc —version
-
更新 rustup update
-
卸载 rustup self uninstall
二 Hello World
-
xxx.rs rs文件是rust的文件格式, linux/macos 下 可执行文件是 xxx , windows是xxx.exe
-
fn main() {}
程序入口函数 -
println!(“Hello world”);
println! 是rust的宏命令 ; 表示此代码结束 -
编译
rustc xxx.rs
三 Cargo
cargo是rust编译和包管理工具, 安装rust时已安装cargo
-
查看 cargo版本: cargo —version
-
cargo 新建项目: cargo new 项目名
-
cargo新建项目时,初始化里一个新的git仓库包含.git和.gitignore文件。 如果不需要git 使用 cargo new —vcs=none xxx
-
cargo.toml文件是项