1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2024-11-21 13:25:53 +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
use std::thread;
fn main() {
fn foo() {
let s = String::from("Hello");
thread::scope(|scope| {
scope.spawn(|| {
println!("Length: {}", s.len());
});
});
}
fn main() {
foo();
}
```
[1]: https://doc.rust-lang.org/std/thread/fn.scope.html