Rust: Difference between revisions

From Wiki :-)
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
== Cargo ==
{| class="wikitable"
!
!Comments
|-
|cargo new <project-name> --bin
|
|-
|cargo build
|
|-
|cargo run
|
|}
== Advanced concepts ==
=== 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()).

Revision as of 05:42, 24 August 2018

Cargo

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

Advanced concepts

Ownership

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

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,