Struct Table

Source
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,

Source

pub fn get_entry( &self, reader_vtable: &impl TableReader, key: &K, ) -> Result<E, Error>

Look up an entry in table corresponding to key

Source

pub fn erase( &self, writer_vtable: &impl TableWriter, key: &K, ) -> Result<(), Error>

Erase a table entry by key

Source

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,

Source

pub fn create_entry(&self, writer_vtable: &impl TableWriter) -> Result<E, Error>

Create a new table entry (not yet attached to a key)

Source

pub fn clear(&self, writer_vtable: &impl TableWriter) -> Result<(), Error>

Remove all entries from the table

Source

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.

Source

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)

Source

pub fn get_table_field<NK, V, U, F, R>( &self, tables_input: &TablesInput<'_>, name: &CStr, func: F, ) -> Result<(Field<V, E>, R), Error>
where NK: Key, for<'a> V::AssocData: From<&'a M>, V: Value + ?Sized, U: Entry, U::Metadata: for<'a> From<&'a V::AssocData>, F: FnOnce(&Table<(), U>) -> Result<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))

Source

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)

Source

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

Source

pub fn get_size(&self, reader_vtable: &impl TableReader) -> Result<usize>

§Get the table size

Return the number of entries in the table

Source

pub fn iter_entries_mut<F>( &self, reader_vtable: &impl TableReader, func: F, ) -> Result<ControlFlow<()>>
where F: FnMut(&mut E) -> 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.

Trait Implementations§

Source§

impl<K: Debug, E: Debug, M: Debug> Debug for Table<K, E, M>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<K, E, M> TableData for Table<K, E, M>

Source§

const TYPE_ID: FieldTypeId = FieldTypeId::Table

The Falco plugin type id of the data
Source§

fn to_data(&self) -> ss_plugin_state_data

Convert to the raw FFI representation Read more

Auto Trait Implementations§

§

impl<K, E, M> Freeze for Table<K, E, M>
where M: Freeze,

§

impl<K, E, M> RefUnwindSafe for Table<K, E, M>

§

impl<K, E = Entry<NoMetadata<()>>, M = <E as Entry>::Metadata> !Send for Table<K, E, M>

§

impl<K, E = Entry<NoMetadata<()>>, M = <E as Entry>::Metadata> !Sync for Table<K, E, M>

§

impl<K, E, M> Unpin for Table<K, E, M>
where M: Unpin, K: Unpin, E: Unpin,

§

impl<K, E, M> UnwindSafe for Table<K, E, M>
where M: UnwindSafe, K: UnwindSafe, E: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.