Rust: Difference between revisions
Jump to navigation
Jump to search
Created page with "In Rust, unlike C++, by default, on a function call, the ownership of parameters is transferred; the copy should be explicit (.clone())." |
No edit summary |
||
| Line 1: | Line 1: | ||
=== 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()). | ||
=== 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, | |||
Revision as of 18:37, 5 November 2017
Ownership
In Rust, unlike C++, by default, on a function call, the ownership of parameters is transferred; the copy should be explicit (.clone()).
Borrowing
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,