Rust: Difference between revisions

From Wiki :-)
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
rust is a programming language.
== Cargo ==
== Cargo ==
{| class="wikitable"
{| class="wikitable"
Line 15: Line 17:


== Advanced concepts ==
== Advanced concepts ==
Aliasing means one memory space is referenced by multiple references.
As aliasing a mutation together is the problem, rust prevent that to happen at the same time.


=== Ownership ===
=== Ownership ===
In Rust, unlike C++, by default, on a function call, the ownership of parameters is transferred; the copy should be explicit (.clone()).
In Rust, unlike C++, by default, on a function call, the ownership of parameters is transferred; the copy should be explicit (.clone()). Therefore, parameters cannot be reused after the function call.


=== Borrowing ===
=== Borrowing ===
Line 36: Line 41:
* trait Send { }: Safe to send between thread: String, u32, Arc<String>
* trait Send { }: Safe to send between thread: String, u32, Arc<String>
* trait Copy { }: Safe to memcpy: u32, f32,
* trait Copy { }: Safe to memcpy: u32, f32,
== References ==
{| class="wikitable"
!
!
|-
|The Rust Programming Language
|https://doc.rust-lang.org/book/ch00-00-introduction.html
|-
|C++Now 2017: Niko Matsakis "Rust: Hack Without Fear!"
|https://www.youtube.com/watch?v=lO1z-7cuRYI
|}

Revision as of 07:16, 23 December 2018

rust is a programming language.

Cargo

Comments
cargo new <project-name> --bin
cargo build
cargo run

Advanced concepts

Aliasing means one memory space is referenced by multiple references.

As aliasing a mutation together is the problem, rust prevent that to happen at the same time.

Ownership

In Rust, unlike C++, by default, on a function call, the ownership of parameters is transferred; the copy should be explicit (.clone()). Therefore, parameters cannot be reused after the function call.

Borrowing

Shared borrow

Cannot mutate while shared.

Mutable borrow

Cannot access while borrowed.

Can access the mutable borrowed variable.

Lifetime reference

Traits

Marker traits

  • trait Send { }: Safe to send between thread: String, u32, Arc<String>
  • trait Copy { }: Safe to memcpy: u32, f32,

References

The Rust Programming Language https://doc.rust-lang.org/book/ch00-00-introduction.html
C++Now 2017: Niko Matsakis "Rust: Hack Without Fear!" https://www.youtube.com/watch?v=lO1z-7cuRYI