leak_playground_std/sync/
arc.rs1use core::fmt;
4use std::sync::Arc as StdArc;
5
6use crate::marker::Forget;
7
8#[derive(Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
9pub struct Arc<T> {
10 inner: StdArc<T>,
11}
12
13impl<T> Arc<T> {
14 pub fn new(x: T) -> Self
16 where
17 T: Forget,
18 {
19 Arc {
20 inner: StdArc::new(x),
21 }
22 }
23
24 pub unsafe fn new_unchecked(x: T) -> Self {
30 Arc {
31 inner: StdArc::new(x),
32 }
33 }
34}
35
36impl<T> Clone for Arc<T> {
37 fn clone(&self) -> Self {
38 Arc {
39 inner: StdArc::clone(&self.inner),
40 }
41 }
42}
43
44impl<T> AsRef<T> for Arc<T> {
45 fn as_ref(&self) -> &T {
46 StdArc::as_ref(&self.inner)
47 }
48}
49
50impl<T> core::borrow::Borrow<T> for Arc<T> {
51 fn borrow(&self) -> &T {
52 &self.inner
53 }
54}
55
56impl<T> std::ops::Deref for Arc<T> {
57 type Target = T;
58
59 fn deref(&self) -> &Self::Target {
60 &self.inner
61 }
62}
63
64impl<T> fmt::Display for Arc<T>
65where
66 T: fmt::Display,
67{
68 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
69 fmt::Display::fmt(&self.inner, f)
70 }
71}
72
73impl<T> fmt::Debug for Arc<T>
74where
75 T: fmt::Debug,
76{
77 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
78 fmt::Debug::fmt(&self.inner, f)
79 }
80}
81
82impl<T> fmt::Pointer for Arc<T> {
83 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
84 fmt::Pointer::fmt(&self.inner, f)
85 }
86}