File tree 3 files changed +35
-0
lines changed
3 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -139,6 +139,13 @@ pub struct Weak<T> {
139
139
unsafe impl < T : Sync + Send > Send for Weak < T > { }
140
140
unsafe impl < T : Sync + Send > Sync for Weak < T > { }
141
141
142
+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
143
+ impl < T : fmt:: Debug > fmt:: Debug for Weak < T > {
144
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
145
+ write ! ( f, "(Weak)" )
146
+ }
147
+ }
148
+
142
149
struct ArcInner < T > {
143
150
strong : atomic:: AtomicUsize ,
144
151
weak : atomic:: AtomicUsize ,
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ use marker;
15
15
use ops:: { Deref , DerefMut } ;
16
16
use sync:: poison:: { self , TryLockError , TryLockResult , LockResult } ;
17
17
use sys_common:: mutex as sys;
18
+ use fmt;
18
19
19
20
/// A mutual exclusion primitive useful for protecting shared data
20
21
///
@@ -252,6 +253,19 @@ impl<T: Send + 'static> Drop for Mutex<T> {
252
253
}
253
254
}
254
255
256
+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
257
+ impl < T : fmt:: Debug + Send + ' static > fmt:: Debug for Mutex < T > {
258
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
259
+ match self . try_lock ( ) {
260
+ Ok ( guard) => write ! ( f, "Mutex {{ data: {:?} }}" , * guard) ,
261
+ Err ( TryLockError :: Poisoned ( err) ) => {
262
+ write ! ( f, "Mutex {{ data: Poisoned({:?}) }}" , * * err. get_ref( ) )
263
+ } ,
264
+ Err ( TryLockError :: WouldBlock ) => write ! ( f, "Mutex {{ <locked> }}" )
265
+ }
266
+ }
267
+ }
268
+
255
269
struct Dummy ( UnsafeCell < ( ) > ) ;
256
270
unsafe impl Sync for Dummy { }
257
271
static DUMMY : Dummy = Dummy ( UnsafeCell { value : ( ) } ) ;
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ use marker;
15
15
use ops:: { Deref , DerefMut } ;
16
16
use sync:: poison:: { self , LockResult , TryLockError , TryLockResult } ;
17
17
use sys_common:: rwlock as sys;
18
+ use fmt;
18
19
19
20
/// A reader-writer lock
20
21
///
@@ -258,6 +259,19 @@ impl<T> Drop for RwLock<T> {
258
259
}
259
260
}
260
261
262
+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
263
+ impl < T : fmt:: Debug + Send + Sync > fmt:: Debug for RwLock < T > {
264
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
265
+ match self . try_read ( ) {
266
+ Ok ( guard) => write ! ( f, "RwLock {{ data: {:?} }}" , * guard) ,
267
+ Err ( TryLockError :: Poisoned ( err) ) => {
268
+ write ! ( f, "RwLock {{ data: Poisoned({:?}) }}" , * * err. get_ref( ) )
269
+ } ,
270
+ Err ( TryLockError :: WouldBlock ) => write ! ( f, "RwLock {{ <locked> }}" )
271
+ }
272
+ }
273
+ }
274
+
261
275
struct Dummy ( UnsafeCell < ( ) > ) ;
262
276
unsafe impl Sync for Dummy { }
263
277
static DUMMY : Dummy = Dummy ( UnsafeCell { value : ( ) } ) ;
You can’t perform that action at this time.
0 commit comments