@@ -216,6 +216,23 @@ impl FromDatum for Cell {
216
216
}
217
217
}
218
218
219
+ pub trait CellFormatter {
220
+ fn fmt_cell ( & mut self , cell : & Cell ) -> String ;
221
+ }
222
+
223
+ struct DefaultFormatter { }
224
+
225
+ impl DefaultFormatter {
226
+ fn new ( ) -> Self {
227
+ Self { }
228
+ }
229
+ }
230
+
231
+ impl CellFormatter for DefaultFormatter {
232
+ fn fmt_cell ( & mut self , cell : & Cell ) -> String {
233
+ format ! ( "{}" , cell)
234
+ }
235
+ }
219
236
/// A data row in a table
220
237
///
221
238
/// The row contains a column name list and cell list with same number of
@@ -352,13 +369,20 @@ pub struct Qual {
352
369
353
370
impl Qual {
354
371
pub fn deparse ( & self ) -> String {
372
+ let mut formatter = DefaultFormatter :: new ( ) ;
373
+ self . deparse_with_fmt ( & mut formatter)
374
+ }
375
+
376
+ pub fn deparse_with_fmt < T : CellFormatter > ( & self , t : & mut T ) -> String {
355
377
if self . use_or {
356
378
match & self . value {
357
379
Value :: Cell ( _) => unreachable ! ( ) ,
358
380
Value :: Array ( cells) => {
359
381
let conds: Vec < String > = cells
360
382
. iter ( )
361
- . map ( |cell| format ! ( "{} {} {}" , self . field, self . operator, cell) )
383
+ . map ( |cell| {
384
+ format ! ( "{} {} {}" , self . field, self . operator, t. fmt_cell( cell) )
385
+ } )
362
386
. collect ( ) ;
363
387
conds. join ( " or " )
364
388
}
@@ -370,11 +394,11 @@ impl Qual {
370
394
Cell :: String ( cell) if cell == "null" => {
371
395
format ! ( "{} {} null" , self . field, self . operator)
372
396
}
373
- _ => format ! ( "{} {} {}" , self . field, self . operator, cell) ,
397
+ _ => format ! ( "{} {} {}" , self . field, self . operator, t . fmt_cell ( cell) ) ,
374
398
} ,
375
- "~~" => format ! ( "{} like {}" , self . field, cell) ,
376
- "!~~" => format ! ( "{} not like {}" , self . field, cell) ,
377
- _ => format ! ( "{} {} {}" , self . field, self . operator, cell) ,
399
+ "~~" => format ! ( "{} like {}" , self . field, t . fmt_cell ( cell) ) ,
400
+ "!~~" => format ! ( "{} not like {}" , self . field, t . fmt_cell ( cell) ) ,
401
+ _ => format ! ( "{} {} {}" , self . field, self . operator, t . fmt_cell ( cell) ) ,
378
402
} ,
379
403
Value :: Array ( _) => unreachable ! ( ) ,
380
404
}
0 commit comments