USEGEAR

导航

2021年7月5日 #

study Rust-8【使用结构体的方法】

摘要: 1、方法 与函数类似:它们使用 fn 关键字和名称声明,可以拥有参数和返回值,同时包含在某处调用该方法时会执行的代码。2、不过方法与函数是不同的,因为它们在结构体的上下文中被定义(或者是枚举或 trait 对象的上下文),并且它们第一个参数总是 self,它代表调用该方法的结构体实例。 #[deri 阅读全文

posted @ 2021-07-05 14:49 USEGEAR 阅读(73) 评论(0) 推荐(0) 编辑

study Rust-7【使用结构体的demo】

摘要: fn main() { let width1 = 30; let height1 = 50; println!( "The area of the rectangle is {} square pixels.", area(width1, height1) ); } fn area(width: u 阅读全文

posted @ 2021-07-05 14:28 USEGEAR 阅读(43) 评论(0) 推荐(0) 编辑

study Rust-6【使用结构体组织相关联的数据】

摘要: struc(structure) 定义并且实例化结构体: struct User { username: String, email: String, sign_in_count: u64, active: bool, } User的结构定义。这种形式,写过程序的很熟悉。 看一下程序中如何定义: l 阅读全文

posted @ 2021-07-05 11:49 USEGEAR 阅读(51) 评论(0) 推荐(0) 编辑

study Rust-5【Slice】

摘要: 另一个没有所有权的数据类型是 slice。slice 允许你引用集合中一段连续的元素序列,而不用引用整个集合。 【字符串Slice熟悉掌握的很勉强,通过动手来进步加深认识】 字符串slice let s = String::from("hello world"); let hello = &s[0. 阅读全文

posted @ 2021-07-05 11:10 USEGEAR 阅读(27) 评论(0) 推荐(0) 编辑