falco_plugin/plugin/tables/field/
mod.rs

1use crate::plugin::tables::data::Value;
2use crate::plugin::tables::field::raw::RawField;
3use crate::plugin::tables::runtime::RuntimeEntry;
4use crate::plugin::tables::runtime_table_validator::RuntimeTableValidator;
5use crate::plugin::tables::traits::RawFieldValueType;
6use std::fmt::{Debug, Formatter};
7use std::marker::PhantomData;
8
9pub(in crate::plugin::tables) mod raw;
10
11/// # Table field descriptor
12///
13/// This struct wraps an opaque pointer from the Falco plugin API, representing a particular
14/// field of a table, while also remembering which data type the field holds.
15///
16/// You probably won't need to construct any values of this type, but you will receive
17/// them from [`crate::tables::import::Table::get_field`]
18/// and use the type to define fields in the metadata struct (see [module docs](`crate::tables::import`)).
19pub struct Field<V: Value + ?Sized, T = RuntimeEntry<()>> {
20    pub(in crate::plugin::tables) field: RawField<V>,
21    pub(in crate::plugin::tables) validator: RuntimeTableValidator,
22    pub(in crate::plugin::tables) tag: PhantomData<T>,
23}
24
25impl<V, T> Debug for Field<V, T>
26where
27    V: Value + Debug + ?Sized,
28    V::AssocData: Debug,
29{
30    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
31        f.debug_struct("field")
32            .field("field", &self.field)
33            .field("validator", &self.validator)
34            .field("tag", &self.tag)
35            .finish()
36    }
37}
38
39impl<V: Value + ?Sized, T> Field<V, T> {
40    pub(crate) fn new(field: RawField<V>, validator: RuntimeTableValidator) -> Self {
41        Self {
42            field,
43            validator,
44            tag: PhantomData,
45        }
46    }
47}
48
49impl<V: Value + ?Sized, T> RawFieldValueType for Field<V, T> {
50    type TableValue = V;
51    type EntryValue<'a>
52        = <V as Value>::Value<'a>
53    where
54        Self: 'a;
55}
56
57impl<V: Value + ?Sized, E> From<RawField<V>> for Field<V, E> {
58    fn from(raw_field: RawField<V>) -> Self {
59        let validator = RuntimeTableValidator::new(std::ptr::null_mut());
60
61        Self {
62            field: raw_field,
63            validator,
64            tag: Default::default(),
65        }
66    }
67}