Skip to content

Commit feb8f91

Browse files
authored
Merge pull request #1552 from Rqnsom/fixes
Example improvements
2 parents dccf9d7 + c6bb6f8 commit feb8f91

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

src/error/multiple_error_types/wrap_error.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ An alternative to boxing errors is to wrap them in your own error type.
44

55
```rust,editable
66
use std::error;
7-
use std::error::Error as _;
7+
use std::error::Error;
88
use std::num::ParseIntError;
99
use std::fmt;
1010

src/std/arc.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
# Arc
22

3-
When shared ownership between threads is needed, `Arc`(Atomic Reference Counted) can be used. This struct, via the `Clone` implementation can create a reference pointer for the location of a value in the memory heap while increasing the reference counter. As it shares ownership between threads, when the last reference pointer to a value is out of scope, the variable is dropped.
3+
When shared ownership between threads is needed, `Arc`(Atomically Reference
4+
Counted) can be used. This struct, via the `Clone` implementation can create
5+
a reference pointer for the location of a value in the memory heap while
6+
increasing the reference counter. As it shares ownership between threads, when
7+
the last reference pointer to a value is out of scope, the variable is dropped.
48

59
```rust,editable
10+
use std::time::Duration;
611
use std::sync::Arc;
712
use std::thread;
813
@@ -11,8 +16,8 @@ fn main() {
1116
let apple = Arc::new("the same apple");
1217
1318
for _ in 0..10 {
14-
// Here there is no value specification as it is a pointer to a reference
15-
// in the memory heap.
19+
// Here there is no value specification as it is a pointer to a
20+
// reference in the memory heap.
1621
let apple = Arc::clone(&apple);
1722
1823
thread::spawn(move || {
@@ -21,6 +26,8 @@ fn main() {
2126
println!("{:?}", apple);
2227
});
2328
}
24-
}
2529
30+
// Make sure all Arc instances are printed from spawned threads.
31+
thread::sleep(Duration::from_secs(1));
32+
}
2633
```

0 commit comments

Comments
 (0)