@@ -200,7 +200,20 @@ impl fmt::Debug for Formatter {
200
200
}
201
201
}
202
202
203
- pub ( crate ) type FormatFn = Box < dyn Fn ( & mut Formatter , & Record < ' _ > ) -> io:: Result < ( ) > + Sync + Send > ;
203
+ pub ( crate ) trait RecordFormat {
204
+ fn format ( & self , formatter : & mut Formatter , record : & Record < ' _ > ) -> io:: Result < ( ) > ;
205
+ }
206
+
207
+ impl < F > RecordFormat for F
208
+ where
209
+ F : Fn ( & mut Formatter , & Record < ' _ > ) -> io:: Result < ( ) > ,
210
+ {
211
+ fn format ( & self , formatter : & mut Formatter , record : & Record < ' _ > ) -> io:: Result < ( ) > {
212
+ ( self ) ( formatter, record)
213
+ }
214
+ }
215
+
216
+ pub ( crate ) type FormatFn = Box < dyn RecordFormat + Sync + Send > ;
204
217
205
218
#[ derive( Default ) ]
206
219
pub ( crate ) struct Builder {
@@ -229,15 +242,7 @@ impl Builder {
229
242
if let Some ( fmt) = built. custom_format {
230
243
fmt
231
244
} else {
232
- Box :: new ( move |buf, record| {
233
- let fmt = DefaultFormatWriter {
234
- format : & built. default_format ,
235
- buf,
236
- written_header_value : false ,
237
- } ;
238
-
239
- fmt. write ( record)
240
- } )
245
+ Box :: new ( built. default_format )
241
246
}
242
247
}
243
248
}
@@ -304,6 +309,18 @@ impl Default for DefaultFormat {
304
309
}
305
310
}
306
311
312
+ impl RecordFormat for DefaultFormat {
313
+ fn format ( & self , formatter : & mut Formatter , record : & Record < ' _ > ) -> io:: Result < ( ) > {
314
+ let fmt = DefaultFormatWriter {
315
+ format : self ,
316
+ buf : formatter,
317
+ written_header_value : false ,
318
+ } ;
319
+
320
+ fmt. write ( record)
321
+ }
322
+ }
323
+
307
324
/// The default format.
308
325
///
309
326
/// This format needs to work with any combination of crate features.
0 commit comments