public:it:rust

差别

这里会显示出您选择的修订版和当前版本之间的差别。

到此差别页面的链接

两侧同时换到之前的修订记录 前一修订版
后一修订版
前一修订版
public:it:rust [2015/06/18 15:36] oakfirepublic:it:rust [2021/07/07 15:17] (当前版本) – [Manual] oakfire
行 4: 行 4:
   * [[https://github.com/PistonDevelopers/piston|piston game engine]]   * [[https://github.com/PistonDevelopers/piston|piston game engine]]
   * [[https://github.com/Geal/nom|nom]]   * [[https://github.com/Geal/nom|nom]]
 +  * [[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''
行 15: 行 16:
   * 了解输入输入出流,文件流操作:   * 了解输入输入出流,文件流操作:
       * 标准输出: 使用宏 ''println!("世界,你好");'', 或 ''std::io''       * 标准输出: 使用宏 ''println!("世界,你好");'', 或 ''std::io''
-      * 标准输入: ''io::stdin().read_line()'' 等 +      * 标准输入: ''std::io::stdin().read_line()'' 等 
-      * 文件 FIXME+      * 文件: ''std::fs''
   * 了解程序代码和可执行代码的组织机制,运行时模块加载、符号查找机制:   * 了解程序代码和可执行代码的组织机制,运行时模块加载、符号查找机制:
-      * 可使用官方提供的 Cargo 工具来方便工程依赖 +      * 机制:[[http://doc.rust-lang.org/reference.html#crates-and-source-files|crate]],[[http://doc.rust-lang.org/reference.html#items-and-attributes|items,attributes]] 
-      * 代码包含FIXME +      * A **crate** contains a tree of nested module scopes... 
-      * 标准库依赖: rust 默认加载少量库, 用到的标准库如果没有默认加载需要使用 use, 比如''use std::io;'' +      * 一个源文件对应一个或多个modules.文件本身就是一个module. 
-      * 外部库依赖: "extern crate"  之后, 再 ''use''.+      * 代码包含:A module without a body is loaded from an external file, by default with the same name as the module, plus the .rs extension.<code> 
 +mod vec;// Load the `vec` module from `vec.rs` 
 +mod thread { 
 +    // Load the `local_data` module from `thread/local_data.rs` 
 +    // or `thread/local_data/mod.rs`. 
 +    mod local_data; 
 +
 +</code> 
 +      *  items 默认都是私有(除了一点:pub enum里的项默认也是pub),公开需要显式声明''pub''.[[http://doc.rust-lang.org/reference.html#visibility-and-privacy|visibility and privacy]] 
 +      * 标准库依赖: rust 默认加载std标准库, 详见文档. 
 +      * 外部库: 编译为''.rlib''格式, 用 ''extern crate'' 导入. rustc编译时库路径指定与gcc类似 
 +      * ''use ''可以绑定模块接口名一个新名字,方便使用,比如''use std::sync::Mutex'',之后就可以直接用''Mutex''这个短名字. 
 +      * ''use'',''mod''都受作用域影响. 
 +      * 可使用官方提供的 Cargo 工具来方便工程依赖.
   * 了解该语言的基本数据类型,基本语法和主要语言构造,主要数学运算符和输入输出函数的使用   * 了解该语言的基本数据类型,基本语法和主要语言构造,主要数学运算符和输入输出函数的使用
       * 变量绑定(variable bindings): ''let a = b; let mut somevalue = String::new();'' 默认为常量(they’re [[https://doc.rust-lang.org/stable/book/mutability.html|immutable]] by default), 变量需标明''mut''       * 变量绑定(variable bindings): ''let a = b; let mut somevalue = String::new();'' 默认为常量(they’re [[https://doc.rust-lang.org/stable/book/mutability.html|immutable]] by default), 变量需标明''mut''
       * 变量绑定支持模板(patten)匹配, 类似erlang;       * 变量绑定支持模板(patten)匹配, 类似erlang;
       * 基本数据类型:  [[https://doc.rust-lang.org/stable/book/primitive-types.html|primitive-types]]       * 基本数据类型:  [[https://doc.rust-lang.org/stable/book/primitive-types.html|primitive-types]]
-      * 条件: ''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. 
 +      * **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]]
行 44: 行 78:
       * 函数作为一种类型, 仍需指定参数与返回值, 类似C++函数指针:''let mut myfun:fn(i32,i32)->i32'';       * 函数作为一种类型, 仍需指定参数与返回值, 类似C++函数指针:''let mut myfun:fn(i32,i32)->i32'';
       * 支持泛型(Generics):包括 函数与struct. 语法类似c++       * 支持泛型(Generics):包括 函数与struct. 语法类似c++
-      * 支持接口 ''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()''等方法来方便进行错误处理. 
行 54: 行 90:
       * 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 '';
   * 了解该语言的编译/解释机制   * 了解该语言的编译/解释机制
  • public/it/rust.1434612990.txt.gz
  • 最后更改: 2015/06/18 15:36
  • oakfire