ufmt/impls/
core.rs
1use crate::{uDebug, uDisplay, uWrite, Formatter};
2
3impl uDebug for bool {
4 fn fmt<W>(&self, f: &mut Formatter<'_, W>) -> Result<(), W::Error>
5 where
6 W: uWrite + ?Sized,
7 {
8 if *self {
9 f.write_str("true")
10 } else {
11 f.write_str("false")
12 }
13 }
14}
15
16impl uDisplay for bool {
17 #[inline(always)]
18 fn fmt<W>(&self, f: &mut Formatter<'_, W>) -> Result<(), W::Error>
19 where
20 W: uWrite + ?Sized,
21 {
22 <bool as uDebug>::fmt(self, f)
23 }
24}
25
26impl uDisplay for char {
41 #[inline(always)]
42 fn fmt<W>(&self, f: &mut Formatter<'_, W>) -> Result<(), W::Error>
43 where
44 W: uWrite + ?Sized,
45 {
46 f.write_char(*self)
47 }
48}
49
50impl<T> uDebug for [T]
51where
52 T: uDebug,
53{
54 fn fmt<W>(&self, f: &mut Formatter<'_, W>) -> Result<(), W::Error>
55 where
56 W: uWrite + ?Sized,
57 {
58 f.debug_list()?.entries(self)?.finish()
59 }
60}
61
62impl uDisplay for str {
96 #[inline(always)]
97 fn fmt<W>(&self, f: &mut Formatter<'_, W>) -> Result<(), W::Error>
98 where
99 W: uWrite + ?Sized,
100 {
101 f.write_str(self)
102 }
103}
104
105impl<T> uDebug for &'_ T
106where
107 T: uDebug + ?Sized,
108{
109 #[inline(always)]
110 fn fmt<W>(&self, f: &mut Formatter<'_, W>) -> Result<(), W::Error>
111 where
112 W: uWrite + ?Sized,
113 {
114 <T as uDebug>::fmt(self, f)
115 }
116}
117
118impl<T> uDisplay for &'_ T
119where
120 T: uDisplay + ?Sized,
121{
122 #[inline(always)]
123 fn fmt<W>(&self, f: &mut Formatter<'_, W>) -> Result<(), W::Error>
124 where
125 W: uWrite + ?Sized,
126 {
127 <T as uDisplay>::fmt(self, f)
128 }
129}
130
131impl<T> uDebug for &'_ mut T
132where
133 T: uDebug + ?Sized,
134{
135 #[inline(always)]
136 fn fmt<W>(&self, f: &mut Formatter<'_, W>) -> Result<(), W::Error>
137 where
138 W: uWrite + ?Sized,
139 {
140 <T as uDebug>::fmt(self, f)
141 }
142}
143
144impl<T> uDisplay for &'_ mut T
145where
146 T: uDisplay + ?Sized,
147{
148 #[inline(always)]
149 fn fmt<W>(&self, f: &mut Formatter<'_, W>) -> Result<(), W::Error>
150 where
151 W: uWrite + ?Sized,
152 {
153 <T as uDisplay>::fmt(self, f)
154 }
155}
156
157impl<T> uDebug for Option<T>
158where
159 T: uDebug,
160{
161 fn fmt<W>(&self, f: &mut Formatter<'_, W>) -> Result<(), W::Error>
162 where
163 W: uWrite + ?Sized,
164 {
165 match self {
166 None => f.write_str("None"),
167 Some(x) => f.debug_tuple("Some")?.field(x)?.finish(),
168 }
169 }
170}
171
172impl<T, E> uDebug for Result<T, E>
173where
174 T: uDebug,
175 E: uDebug,
176{
177 fn fmt<W>(&self, f: &mut Formatter<'_, W>) -> Result<(), W::Error>
178 where
179 W: uWrite + ?Sized,
180 {
181 match self {
182 Err(e) => f.debug_tuple("Err")?.field(e)?.finish(),
183 Ok(x) => f.debug_tuple("Ok")?.field(x)?.finish(),
184 }
185 }
186}