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
///
@@ -250,6 +251,19 @@ impl<T: Send> Drop for Mutex<T> {
250
251
}
251
252
}
252
253
254
+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
255
+ impl < T : fmt:: Debug + Send + ' static > fmt:: Debug for Mutex < T > {
256
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
257
+ match self . try_lock ( ) {
258
+ Ok ( guard) => write ! ( f, "Mutex {{ data: {:?} }}" , * guard) ,
259
+ Err ( TryLockError :: Poisoned ( err) ) => {
260
+ write ! ( f, "Mutex {{ data: Poisoned({:?}) }}" , * * err. get_ref( ) )
261
+ } ,
262
+ Err ( TryLockError :: WouldBlock ) => write ! ( f, "Mutex {{ <locked> }}" )
263
+ }
264
+ }
265
+ }
266
+
253
267
struct Dummy ( UnsafeCell < ( ) > ) ;
254
268
unsafe impl Sync for Dummy { }
255
269
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
///
@@ -255,6 +256,19 @@ impl<T> Drop for RwLock<T> {
255
256
}
256
257
}
257
258
259
+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
260
+ impl < T : fmt:: Debug + Send + Sync > fmt:: Debug for RwLock < T > {
261
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
262
+ match self . try_read ( ) {
263
+ Ok ( guard) => write ! ( f, "RwLock {{ data: {:?} }}" , * guard) ,
264
+ Err ( TryLockError :: Poisoned ( err) ) => {
265
+ write ! ( f, "RwLock {{ data: Poisoned({:?}) }}" , * * err. get_ref( ) )
266
+ } ,
267
+ Err ( TryLockError :: WouldBlock ) => write ! ( f, "RwLock {{ <locked> }}" )
268
+ }
269
+ }
270
+ }
271
+
258
272
struct Dummy ( UnsafeCell < ( ) > ) ;
259
273
unsafe impl Sync for Dummy { }
260
274
static DUMMY : Dummy = Dummy ( UnsafeCell { value : ( ) } ) ;
You can’t perform that action at this time.
0 commit comments