两侧同时换到之前的修订记录 前一修订版 后一修订版 | 前一修订版 |
public:it:rust [2015/06/24 13:33] – oakfire | public:it:rust [2021/07/07 15:17] (当前版本) – [Manual] oakfire |
---|
* [[https://github.com/carllerche/mio|mio]] | * [[https://github.com/carllerche/mio|mio]] |
===== Manual ===== | ===== Manual ===== |
* Book:[[https://doc.rust-lang.org/stable/book/README.html|The Rust Programming Language]] | * Book:[[https://doc.rust-lang.org/stable/book/|The Rust Programming Language]]; [[https://github.com/KaiserY/trpl-zh-cn|中文版]] |
* [[http://rustbyexample.com]] | * [[http://rustbyexample.com]] |
* 编译型语言, ''rustc''类似gcc/clang, 具体''man rustc'' 或 ''rustc -h'' | * 编译型语言, ''rustc''类似gcc/clang, 具体''man rustc'' 或 ''rustc -h'' |
* 条件: ''match statement'', ''if a==b { } else { }''. ''if''也是表达式, 可被变量绑定''let a= if b==c {b} else {c};'' | * 条件: ''match statement'', ''if a==b { } else { }''. ''if''也是表达式, 可被变量绑定''let a= if b==c {b} else {c};'' |
* 循环: ''loop{}'', ''for x in y{}'', ''for( ; ;){}'', ''while'', ''continue'', ''break''. | * 循环: ''loop{}'', ''for x in y{}'', ''for( ; ;){}'', ''while'', ''continue'', ''break''. |
* [[https://doc.rust-lang.org/stable/book/functions.html#expressions-vs.-statements|expression-based language]] | * [[https://doc.rust-lang.org/stable/book/functions.html#expressions-vs.-statements|expression-based language]], 主表达式语言, 表达式始终返回一个值, rust 函数也属于表达式; 但是 let 语句不是表达式(属于声明); |
* enum 比较强大,感觉更类似tuple. | * enum 比较强大,感觉更类似tuple. |
| * **char** 类型为32位无符号Unicode,UCS-4/UTF-32编码 |
| * **str** 类型为8位无符号array, UTF-8编码 |
| * 支持 **type** 自定义类型 |
* 了解数组和其他集合类的使用: | * 了解数组和其他集合类的使用: |
* Array FIXME | * Array: [[https://doc.rust-lang.org/stable/std/vec/|Vec<T>]]; ''vec!'' macro. |
* Slice FIXME | * Slice FIXME |
* Tuple FIXME | * Tuple FIXME |
* 了解字符串的处理 | * 了解字符串的处理 |
* String(默认utf8编码);FIXME | * 不同于老的语言,rust 基础字符串相关类型**char**,**str**默认就支持unicode. |
| * String(默认utf8编码); 与str的转换 ''to_string()''. |
| * 由于是utf8编码,所以str支持两种下标:按字节与按文字:<code rust> |
| let hachiko = "忠犬ハチ公"; |
| for b in hachiko.as_bytes() { |
| print!("{}, ", b); |
| } |
| println!(""); |
| for c in hachiko.chars() { |
| print!("{}, ", c); |
| } |
| println!(""); |
| |
| // This prints: |
| // 229, 191, 160, 231, 138, 172, 227, 131, 143, 227, 131, 129, 229, 133, 172, |
| // 忠, 犬, ハ, チ, 公, |
| </code> |
| * 由于是utf8编码,所以rust的str不需要null结尾,字符串本身也可包含null. |
* 了解该语言在面向对象,函数式编程,泛型,元编程等编程范式的特性 | * 了解该语言在面向对象,函数式编程,泛型,元编程等编程范式的特性 |
* 并发:[[https://doc.rust-lang.org/stable/book/concurrency.html|concurrency]] | * 并发:[[https://doc.rust-lang.org/stable/book/concurrency.html|concurrency]] |
* 支持接口 ''trait ''编程, 扩展了OO与泛型: 参数可声明为''fn myfun<T:SomeMethod> (a:T){}'' 其中''T:SomeMethod''表示拥有接口''SomeMethod''的任意T. | * 支持接口 ''trait ''编程, 扩展了OO与泛型: 参数可声明为''fn myfun<T:SomeMethod> (a:T){}'' 其中''T:SomeMethod''表示拥有接口''SomeMethod''的任意T. |
* 了解特有的语法糖 | * 了解特有的语法糖 |
| * [[http://doc.rust-lang.org/reference.html#if-let-expressions|if let]] |
* 了解该语言错误处理,调试方式以及对测试的支持 | * 了解该语言错误处理,调试方式以及对测试的支持 |
| * 没有 exception. [[https://doc.rust-lang.org/stable/book/error-handling.html|error hadling]] |
* 方法调用可返回 [[https://doc.rust-lang.org/stable/std/result/enum.Result.html|Result]], 如果未对 Result 进行处理, 编译器会警告; | * 方法调用可返回 [[https://doc.rust-lang.org/stable/std/result/enum.Result.html|Result]], 如果未对 Result 进行处理, 编译器会警告; |
* Result 可有''ok()''等方法来方便进行错误处理. | * Result 可有''ok()''等方法来方便进行错误处理. |
* 8-)不需要手动释放内存, 没有运行时GC,但可在编译期来保证内存安全! | * 8-)不需要手动释放内存, 没有运行时GC,但可在编译期来保证内存安全! |
* [[https://doc.rust-lang.org/stable/book/ownership.html|Ownership]]: 所有权唯一; | * [[https://doc.rust-lang.org/stable/book/ownership.html|Ownership]]: 所有权唯一; |
* 引用(reference, borrow),可多个引用借用所有权,但同一时间只能有一个可变的引用;引用生存期必须比所有者短; | * 引用(reference, borrow),可以有多个不变引用,或一个可变引用,但不能有两种引用同时存在;引用生存期不能比所有者长; |
* 生存期(lifetimes), 可显式声明 '' 'a '', '' 'static ''; | * 生存期(lifetimes), 可显式声明 '' 'a '', '' 'static ''; |
* 了解该语言的编译/解释机制 | * 了解该语言的编译/解释机制 |