@@ -10,6 +10,7 @@ We'll first need a way to construct an `Arc<T>`.
1010This is pretty simple, as we just need to box the ` ArcInner<T> ` and get a
1111` NonNull<T> ` pointer to it.
1212
13+ <!-- ignore: simplified code -->
1314``` rust,ignore
1415impl<T> Arc<T> {
1516 pub fn new(data: T) -> Arc<T> {
@@ -41,6 +42,7 @@ This is okay because:
4142 if it is the only ` Arc ` referencing that data (which only happens in ` Drop ` )
4243* We use atomics for the shared mutable reference counting
4344
45+ <!-- ignore: simplified code -->
4446``` rust,ignore
4547unsafe impl<T: Sync + Send> Send for Arc<T> {}
4648unsafe impl<T: Sync + Send> Sync for Arc<T> {}
@@ -61,6 +63,8 @@ as `Rc` is not thread-safe.
6163To dereference the ` NonNull<T> ` pointer into a ` &T ` , we can call
6264` NonNull::as_ref ` . This is unsafe, unlike the typical ` as_ref ` function, so we
6365must call it like this:
66+
67+ <!-- ignore: simplified code -->
6468``` rust,ignore
6569unsafe { self.ptr.as_ref() }
6670```
@@ -79,11 +83,15 @@ to the data inside?
7983What we need now is an implementation of ` Deref ` .
8084
8185We'll need to import the trait:
86+
87+ <!-- ignore: simplified code -->
8288``` rust,ignore
8389use std::ops::Deref;
8490```
8591
8692And here's the implementation:
93+
94+ <!-- ignore: simplified code -->
8795``` rust,ignore
8896impl<T> Deref for Arc<T> {
8997 type Target = T;
@@ -101,6 +109,8 @@ Pretty simple, eh? This simply dereferences the `NonNull` pointer to the
101109## Code
102110
103111Here's all the code from this section:
112+
113+ <!-- ignore: simplified code -->
104114``` rust,ignore
105115use std::ops::Deref;
106116
0 commit comments