@@ -6,81 +6,13 @@ pub use inner::*;
66mod inner {
77 #![ allow( clippy:: disallowed_types) ]
88
9- use std:: ops:: Deref ;
10- use std:: ops:: DerefMut ;
119 pub use std:: sync:: Arc as MaybeArc ;
1210
13- pub struct MaybeArcMutexGuard < ' lock , T > ( std:: sync:: MutexGuard < ' lock , T > ) ;
14-
15- impl < ' lock , T > Deref for MaybeArcMutexGuard < ' lock , T > {
16- type Target = std:: sync:: MutexGuard < ' lock , T > ;
17- fn deref ( & self ) -> & std:: sync:: MutexGuard < ' lock , T > {
18- & self . 0
19- }
20- }
21-
22- impl < ' lock , T > DerefMut for MaybeArcMutexGuard < ' lock , T > {
23- fn deref_mut ( & mut self ) -> & mut std:: sync:: MutexGuard < ' lock , T > {
24- & mut self . 0
25- }
26- }
27-
28- #[ derive( Debug ) ]
29- pub struct MaybeArcMutex < T > ( std:: sync:: Arc < std:: sync:: Mutex < T > > ) ;
30- impl < T > MaybeArcMutex < T > {
31- pub fn new ( val : T ) -> Self {
32- Self ( std:: sync:: Arc :: new ( std:: sync:: Mutex :: new ( val) ) )
33- }
34- }
35-
36- impl < ' lock , T > MaybeArcMutex < T > {
37- pub fn lock ( & ' lock self ) -> MaybeArcMutexGuard < ' lock , T > {
38- MaybeArcMutexGuard ( self . 0 . lock ( ) . unwrap ( ) )
39- }
40- }
41-
4211 pub use core:: marker:: Send as MaybeSend ;
4312 pub use core:: marker:: Sync as MaybeSync ;
4413}
4514
4615#[ cfg( not( feature = "sync" ) ) ]
4716mod inner {
48- use std:: ops:: Deref ;
49- use std:: ops:: DerefMut ;
50-
5117 pub use std:: rc:: Rc as MaybeArc ;
52-
53- pub struct MaybeArcMutexGuard < ' lock , T > ( std:: cell:: RefMut < ' lock , T > ) ;
54-
55- impl < ' lock , T > Deref for MaybeArcMutexGuard < ' lock , T > {
56- type Target = std:: cell:: RefMut < ' lock , T > ;
57- fn deref ( & self ) -> & std:: cell:: RefMut < ' lock , T > {
58- & self . 0
59- }
60- }
61-
62- impl < ' lock , T > DerefMut for MaybeArcMutexGuard < ' lock , T > {
63- fn deref_mut ( & mut self ) -> & mut std:: cell:: RefMut < ' lock , T > {
64- & mut self . 0
65- }
66- }
67-
68- #[ derive( Debug ) ]
69- pub struct MaybeArcMutex < T > ( std:: rc:: Rc < std:: cell:: RefCell < T > > ) ;
70- impl < T > MaybeArcMutex < T > {
71- pub fn new ( val : T ) -> Self {
72- Self ( std:: rc:: Rc :: new ( std:: cell:: RefCell :: new ( val) ) )
73- }
74- }
75-
76- impl < ' lock , T > MaybeArcMutex < T > {
77- pub fn lock ( & ' lock self ) -> MaybeArcMutexGuard < ' lock , T > {
78- MaybeArcMutexGuard ( self . 0 . borrow_mut ( ) )
79- }
80- }
81-
82- pub trait MaybeSync { }
83- impl < T > MaybeSync for T where T : ?Sized { }
84- pub trait MaybeSend { }
85- impl < T > MaybeSend for T where T : ?Sized { }
8618}
0 commit comments