falco_plugin/tables/import/
field_info.rs1use crate::tables::FieldTypeId;
2use num_traits::FromPrimitive;
3use std::fmt::Debug;
4
5#[repr(transparent)]
7pub struct FieldInfo(falco_plugin_api::ss_plugin_table_fieldinfo);
8
9impl Debug for FieldInfo {
10 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
11 f.debug_struct("FieldInfo")
12 .field("name", &self.name())
13 .field("read_only", &self.read_only())
14 .field("field_type", &self.field_type())
15 .finish()
16 }
17}
18
19impl FieldInfo {
20 pub fn name(&self) -> &str {
24 unsafe { std::ffi::CStr::from_ptr(self.0.name) }
25 .to_str()
26 .unwrap_or("<invalid field name>")
27 }
28
29 pub fn read_only(&self) -> bool {
31 self.0.read_only != 0
32 }
33
34 pub fn field_type(&self) -> Result<FieldTypeId, u32> {
39 match FieldTypeId::from_u32(self.0.field_type) {
40 Some(field_type) => Ok(field_type),
41 None => Err(self.0.field_type),
42 }
43 }
44}