Day148 — Rust
Dec 4, 2021
Good presentation from Carol introducing Rust.
- high performance
- Memory safety
- great backward compatibility
Memory safety
memory safety is guard by the concept of ownership and borrowing.
Ownership
x is the owner. When the owner goes out of scope, allocated memory is cleaned up automatically. memory clean up code is inserted at the compile time. No garbage collection is done in runtime.
If the ownership of the value is moved from x to y. x cannot be used afterwards.
Borrowing
y borrows the value of x as a immutable borrow. allows to read the value x owns, but x is responsible to clean up the value at the end.
Below code does not compile because the value x owns is cleaned up after the scope.
All of the above error occurs in compile time.