文章目录
1. linux&macos安装rust
安装
curl https://sh.rustup.rs -sSf | sh
这将会安装rustc, rustup, rustfmt, cargo 等等程序
环境变量
手动将 Rust 加入系统 PATH 变量中:
source $HOME/.cargo/env
或者可以在 ~/.bash_profile 文件中增加如下行:
export PATH="$HOME/.cargo/bin:$PATH"
测试
> rustc --version
rustc 1.39.0 (4560ea788 2019-11-04)
2. hello world
fn main() {
println!("Hello, world!");
}
编译&运行
> rustc main.rs
> ./main
Hello, world!
3. 初步分析hello world代码
1,宏:println! 调用了一个 Rust 宏(macro)。如果是调用函数,则应输入 println(没有!)
2,函数用fn定义
3&