mirror of
https://github.com/google/comprehensive-rust.git
synced 2025-05-29 05:37:37 +02:00
Move thread::spawn
to separate function (#1020)
This might make it clearer why the thread cannot borrow from the string.
This commit is contained in:
parent
dbb3217667
commit
2c820e7bf3
@ -5,13 +5,16 @@ Normal threads cannot borrow from their environment:
|
||||
```rust,editable,compile_fail
|
||||
use std::thread;
|
||||
|
||||
fn main() {
|
||||
fn foo() {
|
||||
let s = String::from("Hello");
|
||||
|
||||
thread::spawn(|| {
|
||||
println!("Length: {}", s.len());
|
||||
});
|
||||
}
|
||||
|
||||
fn main() {
|
||||
foo();
|
||||
}
|
||||
```
|
||||
|
||||
However, you can use a [scoped thread][1] for this:
|
||||
|
Loading…
x
Reference in New Issue
Block a user