| 1 | |
| 2 |
|
| 3 | |
| 4 | |
| 5 | |
| 6 |
|
| 7 | pub use core::fmt::{
|
| 8 | Arguments,
|
| 9 | Debug,
|
| 10 | Error,
|
| 11 | Formatter,
|
| 12 | Result,
|
| 13 | Write, |
| 14 | };
|
| 15 |
|
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | #[doc(hidden)]
|
| 22 | pub struct Adapter<T>(pub T);
|
| 23 |
|
| 24 | macro_rules! impl_fmt_adapter_forward {
|
| 25 | ($($trait:ident),* $(,)?) => {
|
| 26 | $(
|
| 27 | impl<T: $trait> $trait for Adapter<T> {
|
| 28 | fn fmt(&self, f: &mut Formatter<'_>) -> Result {
|
| 29 | let Self(t) = self;
|
| 30 | $trait::fmt(t, f)
|
| 31 | }
|
| 32 | }
|
| 33 | )*
|
| 34 | };
|
| 35 | }
|
| 36 |
|
| 37 | use core::fmt::{
|
| 38 | Binary,
|
| 39 | LowerExp,
|
| 40 | LowerHex,
|
| 41 | Octal,
|
| 42 | Pointer,
|
| 43 | UpperExp,
|
| 44 | UpperHex, //
|
| 45 | };
|
| 46 | impl_fmt_adapter_forward!(Debug, LowerHex, UpperHex, Octal, Binary, Pointer, LowerExp, UpperExp);
|
| 47 |
|
| 48 | /// A copy of [`core::fmt::Display`] that allows us to implement it for foreign types.
|
| 49 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | |
| 54 | |
| 55 | pub trait Display {
|
| 56 | |
| 57 | fn fmt(&self, f: &mut Formatter<'_>) -> Result;
|
| 58 | }
|
| 59 |
|
| 60 | impl<T: ?Sized + Display> Display for &T {
|
| 61 | fn fmt(&self, f: &mut Formatter<'_>) -> Result {
|
| 62 | Display::fmt(*self, f)
|
| 63 | }
|
| 64 | }
|
| 65 |
|
| 66 | impl<T: ?Sized + Display> core::fmt::Display for Adapter<&T> {
|
| 67 | fn fmt(&self, f: &mut Formatter<'_>) -> Result {
|
| 68 | let Self(t) = self;
|
| 69 | Display::fmt(t, f)
|
| 70 | }
|
| 71 | }
|
| 72 |
|
| 73 | macro_rules! impl_display_forward {
|
| 74 | ($(
|
| 75 | $( { $($generics:tt)* } )? $ty:ty $( { where $($where:tt)* } )?
|
| 76 | ),* $(,)?) => {
|
| 77 | $(
|
| 78 | impl$($($generics)*)? Display for $ty $(where $($where)*)? {
|
| 79 | fn fmt(&self, f: &mut Formatter<'_>) -> Result {
|
| 80 | core::fmt::Display::fmt(self, f)
|
| 81 | }
|
| 82 | }
|
| 83 | )*
|
| 84 | };
|
| 85 | }
|
| 86 |
|
| 87 | impl_display_forward!(
|
| 88 | bool,
|
| 89 | char,
|
| 90 | core::panic::PanicInfo<'_>,
|
| 91 | Arguments<'_>,
|
| 92 | i128,
|
| 93 | i16,
|
| 94 | i32,
|
| 95 | i64,
|
| 96 | i8,
|
| 97 | isize,
|
| 98 | str,
|
| 99 | u128,
|
| 100 | u16,
|
| 101 | u32,
|
| 102 | u64,
|
| 103 | u8,
|
| 104 | usize,
|
| 105 | {<T: ?Sized>} crate::sync::Arc<T> {where crate::sync::Arc<T>: core::fmt::Display},
|
| 106 | {<T: ?Sized>} crate::sync::UniqueArc<T> {where crate::sync::UniqueArc<T>: core::fmt::Display},
|
| 107 | );
|