Julio Biason
2 years ago
4 changed files with 40 additions and 0 deletions
@ -0,0 +1,7 @@ |
|||||||
|
# This file is automatically @generated by Cargo. |
||||||
|
# It is not intended for manual editing. |
||||||
|
version = 3 |
||||||
|
|
||||||
|
[[package]] |
||||||
|
name = "movereftest" |
||||||
|
version = "0.1.0" |
@ -0,0 +1,8 @@ |
|||||||
|
[package] |
||||||
|
name = "movereftest" |
||||||
|
version = "0.1.0" |
||||||
|
edition = "2021" |
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html |
||||||
|
|
||||||
|
[dependencies] |
@ -0,0 +1,3 @@ |
|||||||
|
# MoveRefTest |
||||||
|
|
||||||
|
Testing if one can move the reference withtout moving the real data. |
@ -0,0 +1,22 @@ |
|||||||
|
use std::thread; |
||||||
|
|
||||||
|
fn main() { |
||||||
|
let concrete = String::from("Hello!"); |
||||||
|
|
||||||
|
let ref1 = &concrete; |
||||||
|
let t1 = thread::spawn(move || { |
||||||
|
for i in 0..5 { |
||||||
|
println!("Thread1: {} - {}", i, ref1); |
||||||
|
} |
||||||
|
}); |
||||||
|
|
||||||
|
let ref2 = &concrete; |
||||||
|
let t2 = thread::spawn(move || { |
||||||
|
for i in 5..10 { |
||||||
|
println!("Thread2: {} - {}", i, ref2); |
||||||
|
} |
||||||
|
}); |
||||||
|
|
||||||
|
t1.join(); |
||||||
|
t2.join(); |
||||||
|
} |
Loading…
Reference in new issue