1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-04-20 15:08:02 +02:00

Make scoped thread examples consistent (#2444)

This is a followup to #1020.
This commit is contained in:
Martin Geisler 2024-10-18 03:04:44 -04:00 committed by GitHub
parent 1a9941b39f
commit ad7ef2e50a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -26,15 +26,18 @@ However, you can use a [scoped thread][1] for this:
```rust,editable ```rust,editable
use std::thread; use std::thread;
fn main() { fn foo() {
let s = String::from("Hello"); let s = String::from("Hello");
thread::scope(|scope| { thread::scope(|scope| {
scope.spawn(|| { scope.spawn(|| {
println!("Length: {}", s.len()); println!("Length: {}", s.len());
}); });
}); });
} }
fn main() {
foo();
}
``` ```
[1]: https://doc.rust-lang.org/std/thread/fn.scope.html [1]: https://doc.rust-lang.org/std/thread/fn.scope.html