mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 10:40:15 +02:00 
			
		
		
		
	rust: sync: impl {Debug,Display} for {Unique,}Arc
This allows printing the inner data of `Arc` and its friends if the inner data implements `Display` or `Debug`. It's useful for logging and debugging purpose. Signed-off-by: Boqun Feng <boqun.feng@gmail.com> Reviewed-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com> Reviewed-by: Gary Guo <gary@garyguo.net> Reviewed-by: Andreas Hindborg <a.hindborg@samsung.com> Reviewed-by: Björn Roy Baron <bjorn3_gh@protonmail.com> Link: https://lore.kernel.org/r/20230207185216.1314638-2-boqun.feng@gmail.com Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
This commit is contained in:
		
							parent
							
								
									09a9639e56
								
							
						
					
					
						commit
						00140a8308
					
				
					 1 changed files with 25 additions and 0 deletions
				
			
		| 
						 | 
				
			
			@ -22,6 +22,7 @@
 | 
			
		|||
};
 | 
			
		||||
use alloc::boxed::Box;
 | 
			
		||||
use core::{
 | 
			
		||||
    fmt,
 | 
			
		||||
    marker::{PhantomData, Unsize},
 | 
			
		||||
    mem::{ManuallyDrop, MaybeUninit},
 | 
			
		||||
    ops::{Deref, DerefMut},
 | 
			
		||||
| 
						 | 
				
			
			@ -522,3 +523,27 @@ fn deref_mut(&mut self) -> &mut Self::Target {
 | 
			
		|||
        unsafe { &mut self.inner.ptr.as_mut().data }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T: fmt::Display + ?Sized> fmt::Display for UniqueArc<T> {
 | 
			
		||||
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
 | 
			
		||||
        fmt::Display::fmt(self.deref(), f)
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T: fmt::Display + ?Sized> fmt::Display for Arc<T> {
 | 
			
		||||
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
 | 
			
		||||
        fmt::Display::fmt(self.deref(), f)
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T: fmt::Debug + ?Sized> fmt::Debug for UniqueArc<T> {
 | 
			
		||||
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
 | 
			
		||||
        fmt::Debug::fmt(self.deref(), f)
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T: fmt::Debug + ?Sized> fmt::Debug for Arc<T> {
 | 
			
		||||
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
 | 
			
		||||
        fmt::Debug::fmt(self.deref(), f)
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue