flow_record_common/
record_field.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use getset::Getters;
use rmpv::Value;

use crate::FieldType;

#[derive(Clone, Eq, PartialEq, Debug, Hash, Getters)]
#[getset(get = "pub")]
pub struct RecordField {
    field_name: String,
    field_type: FieldType,
}

impl RecordField {
    pub fn dissolve(self) -> (String, FieldType) {
        (self.field_name, self.field_type)
    }
}

impl From<(String, FieldType)> for RecordField {
    fn from(value: (String, FieldType)) -> Self {
        Self {
            field_name: value.0,
            field_type: value.1,
        }
    }
}

impl From<RecordField> for Value {
    fn from(value: RecordField) -> Self {
        Value::Array(vec![
            value.field_type.into(),
            Value::String(value.field_name.into()),
        ])
    }
}