Skip to main content

RecordFormatter

Trait RecordFormatter 

Source
pub trait RecordFormatter: ValueFormatter {
    // Required method
    fn fmt_record(&self, record: &DataRecord) -> Self::Output;

    // Provided method
    fn fmt_field(&self, field: &FieldStorage) -> Self::Output { ... }
}
Expand description

扩展 trait:记录格式化器

在 ValueFormatter 基础上,提供格式化字段和记录的能力。 大部分实现都可以使用默认实现。

Required Methods§

Source

fn fmt_record(&self, record: &DataRecord) -> Self::Output

格式化整条记录

这个方法需要具体实现,因为不同格式对记录的表示方式差异很大:

  • JSON: {"name":"Alice","age":30}
  • CSV: Alice,30
  • KV: name: "Alice", age: 30

Provided Methods§

Source

fn fmt_field(&self, field: &FieldStorage) -> Self::Output

格式化单个字段

默认实现:只格式化字段的值,忽略字段名

Implementors§