From c6bb6f898e8d07b53341e1b7b28486a1ffa2232c Mon Sep 17 00:00:00 2001 From: Korlo <88337245+Rqnsom@users.noreply.github.com> Date: Wed, 15 Jun 2022 17:25:39 +0200 Subject: [PATCH] Example improvements --- src/error/multiple_error_types/wrap_error.md | 2 +- src/std/arc.md | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/error/multiple_error_types/wrap_error.md b/src/error/multiple_error_types/wrap_error.md index 392b783aed..3da5984936 100644 --- a/src/error/multiple_error_types/wrap_error.md +++ b/src/error/multiple_error_types/wrap_error.md @@ -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; diff --git a/src/std/arc.md b/src/std/arc.md index 08d1ad31aa..f4c1ce80e7 100644 --- a/src/std/arc.md +++ b/src/std/arc.md @@ -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; @@ -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 || { @@ -21,6 +26,8 @@ fn main() { println!("{:?}", apple); }); } -} + // Make sure all Arc instances are printed from spawned threads. + thread::sleep(Duration::from_secs(1)); +} ```