Rust Learning

Rust Learning

References

Web

GUI

  • conrod An easy-to-use, 2D GUI library written entirely in Rust.
  • druid Data-oriented Rust UI design toolkit.
  • libui-rs Rust bindings to the minimalist, native, cross-platform UI toolkit libui
  • Are we GUI Yet?

Other

Learn web

Key points

  • 理解所有权:What is Ownership
    • Copy
    • Move
    • Clone
  • 理解引用和借用:References and Borrowing
    • & 引用
    • (&) 借用
      • We call having references as function parameters borrowing

      • 我们称“将引用作为函数参数”为“借用”
      • 解引用

数据竞争

对于所有的类型T和任意的生命周期参数‘a,都能衍生出两种类型:&’a T 和 &mut ‘a T。

&’a T 相当于T的读取器,持有T的读锁, &mut ‘a T 相当于T的写入器,持有T的写锁。

编译器里有一个工具borrowck,在编译时会自动检查这两种类型的使用情况,如果有非法的使用,就报错,不让你编译通过。同样地,当你手中还持有着对一个值的引用时,编译器不允许将其移动或者销毁。这样,就杜绝了野指针现象和数据竞争问题。

1
2
let rb0 = &b;
let rb1 = &mut b;

值传递

Rust 的默认的值的传递是:转移。不管是赋值还是函数调用时的参数和返回值,都是这样。

分类体系(taxonomy)

开放的分类,使用泛型;封闭的分类,使用枚举(ADT)。

开放的全分类:Type + Trait

赞赏留名,相识相惜 ~