falco_plugin/tables/import/
table_input.rs1use crate::error::as_result::WithLastError;
2use crate::tables::import::traits::{TableAccess, TableMetadata};
3use crate::tables::import::RawTable;
4use crate::tables::{Key, TablesInput};
5use falco_plugin_api::ss_plugin_state_type;
6use std::ffi::CStr;
7
8impl TablesInput<'_> {
9 pub fn get_table<T, K>(&self, name: &CStr) -> Result<T, anyhow::Error>
14 where
15 T: TableAccess<Key = K>,
16 K: Key,
17 {
18 let table = unsafe {
19 (self.get_table)(
20 self.owner,
21 name.as_ptr().cast(),
22 K::TYPE_ID as ss_plugin_state_type,
23 )
24 };
25 if table.is_null() {
26 Err(anyhow::anyhow!("Could not get table {:?}", name)).with_last_error(&self.last_error)
27 } else {
28 let table = RawTable { table };
30 let metadata = T::Metadata::new(&table, self)?;
31 Ok(T::new(table, metadata, false))
32 }
33 }
34}