为什么学习Rust?
https://www.rust-lang.org/learn/get-started
管理工具:Cargo
Cargo: the Rust build tool and package manager
简单教程和一些说明:
https://polarisxu.studygolang.com/posts/rust/rust-tutorial-02/
https://polarisxu.studygolang.com/posts/rust/rust-tutorial-03/
https://polarisxu.studygolang.com/posts/rust/rust-tutorial-04/
https://polarisxu.studygolang.com/posts/rust/rust-tutorial-05/
https://polarisxu.studygolang.com/posts/rust/rust-tutorial-06/
https://polarisxu.studygolang.com/posts/rust/rust-tutorial-07/
https://polarisxu.studygolang.com/posts/rust/rust-tutorial-08/
https://polarisxu.studygolang.com/posts/rust/rust-tutorial-09/
**Rust 程序设计语言 中文翻译**
https://kaisery.github.io/trpl-zh-cn/ch03-00-common-programming-concepts.html
https://kaisery.github.io/trpl-zh-cn/ch04-01-what-is-ownership.html
https://kaisery.github.io/trpl-zh-cn/ch05-00-structs.html
let 关键字创建变量并绑定一个值。
Rust函数和变量名使用snake case 规范:小写字母,下户线分割单词
参数:函数签名的一部分parameters形参 必须声明参数类型;具体值argument由定义中或调用函数时传入。
语句statements 是指令,无返回值;表达式expressions计算并产生返回值。表达式可以作为函数返回值(不用写return),表达式不需要结尾加分号。
控制流 control flow 结构(if和循环)
if
是一个表达式,根据条件选择是否运行代码
fn main() {
let condition = true;
let number = if condition { 5 } else { 6 };
println!("The value of number is: {number}");
}
fn main() {
let number = 6;
if number % 4 == 0 {
println!("number is divisible by 4");
} else if number % 3 == 0 {
println!("number is divisible by 3");
} else if number % 2 == 0 {
println!("number is divisible by 2");
} else {
println!("number is not divisible by 4, 3, or 2");
}
}
loop
关键字
continue
,break
表达式break
表达式允许返回值break
continue
作用循环while true {}
for element in a {}
所有权系统管理内存,编译器在编译时检查内存(运行时不损耗)。
Rust无需垃圾回收garbage collector 即可保障内存安全。