分类 rust 中的文章

Rust by Example(chapter3)

Custom Types Rust中有两种自定义类型 struct enum struct 在结构体中,有三种struct的类型,分别为 元祖数据结构 类C struct unit struts 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 #[derive(Debug)] struct Person<'a> { // 'a 表示生命周期,当Person生命结束了,那么name也结束了。 name: &'a str, age: u8, } struct Nil; struct Pair(i32, f32);……

阅读全文

Rust by Example(chapter1)

Rust是一个现代的系统级编程语言,侧重于安全、速度和并发。 安装 1 curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh hello world 1 2 3 fn main() { println!("Hello World!"); } 其中,println!是一个宏,功能是将字符串打印到终端。 编译方式如下 1 2 rustc hello.rs ./hello 或者使用 1 cargo run cargo是一个rust生态管理工具,我们在接下来的各种实例中都采用这种方式来运行……

阅读全文

Rust by Example(chapter2)

Primitives(基本数据类型) Rust提供了几种数据类型 整数类型: i8, i16, i32, i64, i128 和isize(指针) 无符号整数类型: u8, u16, u32, u64, u128 和usize(指针) 浮点: f32, f64 char类型(4个比特) bool类型 元祖类型() 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 fn main() { // Variables can be type annotated. let logical: bool……

阅读全文