Skip to content

Commit

Permalink
Merge pull request #1552 from Rqnsom/fixes
Browse files Browse the repository at this point in the history
Example improvements
  • Loading branch information
marioidival authored Jun 17, 2022
2 parents dccf9d7 + c6bb6f8 commit feb8f91
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/error/multiple_error_types/wrap_error.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ An alternative to boxing errors is to wrap them in your own error type.

```rust,editable
use std::error;
use std::error::Error as _;
use std::error::Error;
use std::num::ParseIntError;
use std::fmt;
Expand Down
15 changes: 11 additions & 4 deletions src/std/arc.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
# Arc

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.
When shared ownership between threads is needed, `Arc`(Atomically 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.

```rust,editable
use std::time::Duration;
use std::sync::Arc;
use std::thread;
Expand All @@ -11,8 +16,8 @@ fn main() {
let apple = Arc::new("the same apple");
for _ in 0..10 {
// Here there is no value specification as it is a pointer to a reference
// in the memory heap.
// Here there is no value specification as it is a pointer to a
// reference in the memory heap.
let apple = Arc::clone(&apple);
thread::spawn(move || {
Expand All @@ -21,6 +26,8 @@ fn main() {
println!("{:?}", apple);
});
}
}
// Make sure all Arc instances are printed from spawned threads.
thread::sleep(Duration::from_secs(1));
}
```

0 comments on commit feb8f91

Please sign in to comment.