pub struct Table<K, E = Entry<NoMetadata<()>>, M = <E as Entry>::Metadata> { /* private fields */ }
Expand description
§A table imported via the Falco plugin API
Implementations§
Source§impl<K, E, M> Table<K, E, M>where
K: Key,
E: Entry<Metadata = M>,
M: TableMetadata + Clone,
impl<K, E, M> Table<K, E, M>where
K: Key,
E: Entry<Metadata = M>,
M: TableMetadata + Clone,
Sourcepub fn get_entry(
&self,
reader_vtable: &impl TableReader,
key: &K,
) -> Result<E, Error>
pub fn get_entry( &self, reader_vtable: &impl TableReader, key: &K, ) -> Result<E, Error>
Look up an entry in table
corresponding to key
Sourcepub fn erase(
&self,
writer_vtable: &impl TableWriter,
key: &K,
) -> Result<(), Error>
pub fn erase( &self, writer_vtable: &impl TableWriter, key: &K, ) -> Result<(), Error>
Erase a table entry by key
Sourcepub fn insert(
&self,
reader_vtable: &impl TableReader,
writer_vtable: &impl TableWriter,
key: &K,
entry: E,
) -> Result<E, Error>
pub fn insert( &self, reader_vtable: &impl TableReader, writer_vtable: &impl TableWriter, key: &K, entry: E, ) -> Result<E, Error>
Attach an entry to a table key (insert an entry to the table)
Source§impl<K, E, M> Table<K, E, M>where
E: Entry<Metadata = M>,
M: TableMetadata + Clone,
impl<K, E, M> Table<K, E, M>where
E: Entry<Metadata = M>,
M: TableMetadata + Clone,
Sourcepub fn create_entry(&self, writer_vtable: &impl TableWriter) -> Result<E, Error>
pub fn create_entry(&self, writer_vtable: &impl TableWriter) -> Result<E, Error>
Create a new table entry (not yet attached to a key)
Sourcepub fn clear(&self, writer_vtable: &impl TableWriter) -> Result<(), Error>
pub fn clear(&self, writer_vtable: &impl TableWriter) -> Result<(), Error>
Remove all entries from the table
Sourcepub fn list_fields(
&self,
fields_vtable: &TableFields<'_>,
) -> &[ss_plugin_table_fieldinfo]
pub fn list_fields( &self, fields_vtable: &TableFields<'_>, ) -> &[ss_plugin_table_fieldinfo]
§List the available fields
Note: this method is of limited utility in actual plugin code (you know the fields you want to access), so it returns the unmodified structure from the plugin API, including raw pointers to C-style strings. This may change later.
Sourcepub fn get_field<V: Value + ?Sized>(
&self,
tables_input: &TablesInput<'_>,
name: &CStr,
) -> Result<Field<V, E>, Error>
pub fn get_field<V: Value + ?Sized>( &self, tables_input: &TablesInput<'_>, name: &CStr, ) -> Result<Field<V, E>, Error>
§Get a table field by name
The field must exist in the table and must be of the type V
, otherwise an error
will be returned.
Note that for regular tables the field objects remembers the table it was retrieved from and accessing an entry from a different table will cause an error at runtime. However, for nested tables there’s no such validation in the Rust SDK (because using the same fields across different nested tables is critical for supporting nested tables)
Sourcepub fn get_table_field<NK, V, U, F, R>(
&self,
tables_input: &TablesInput<'_>,
name: &CStr,
func: F,
) -> Result<(Field<V, E>, R), Error>
pub fn get_table_field<NK, V, U, F, R>( &self, tables_input: &TablesInput<'_>, name: &CStr, func: F, ) -> Result<(Field<V, E>, R), Error>
§Get a nested table field
This method takes a closure and executes it with a nested table as an argument. It’s used to get (at runtime) field descriptors for nested table fields.
You will usually just use the derive macro which hides all the complexity, but if you need to handle nested tables at runtime, you can use this method to get the table field and all subfields you need like this:
// get the parent table
let thread_table: Table<i64> = input.get_table(c"threads")?;
let (fd_field, fd_type_field) =
thread_table.get_table_field(input, c"file_descriptors", |table| {
table.get_field(input, c"type")
})?;
The call to get_table_field
takes a closure, which is passed a reference to
a sample entry in the nested table (enough to manage its fields) and returns a tuple
of (the table field, (whatever_the_closure_returns))
Sourcepub fn add_field<V: Value<AssocData = ()> + ?Sized>(
&self,
tables_input: &TablesInput<'_>,
name: &CStr,
) -> Result<Field<V, E>, Error>
pub fn add_field<V: Value<AssocData = ()> + ?Sized>( &self, tables_input: &TablesInput<'_>, name: &CStr, ) -> Result<Field<V, E>, Error>
§Add a table field
The field will have the specified name and the type is derived from the generic argument.
Note that for regular tables the field objects remembers the table it was retrieved from and accessing an entry from a different table will cause an error at runtime. However, for nested tables there’s no such validation in the Rust SDK (because using the same fields across different nested tables is critical for supporting nested tables)
Sourcepub fn get_name(&self, reader_vtable: &impl TableReader) -> Result<&str>
pub fn get_name(&self, reader_vtable: &impl TableReader) -> Result<&str>
§Get the table name
This method returns an error if the name cannot be represented as UTF-8
Sourcepub fn get_size(&self, reader_vtable: &impl TableReader) -> Result<usize>
pub fn get_size(&self, reader_vtable: &impl TableReader) -> Result<usize>
§Get the table size
Return the number of entries in the table
Sourcepub fn iter_entries_mut<F>(
&self,
reader_vtable: &impl TableReader,
func: F,
) -> Result<ControlFlow<()>>
pub fn iter_entries_mut<F>( &self, reader_vtable: &impl TableReader, func: F, ) -> Result<ControlFlow<()>>
§Iterate over all entries in a table with mutable access
The closure is called once for each table entry with a corresponding entry object as a parameter.
The iteration stops when either all entries have been processed or the closure returns
ControlFlow::Break
.