haproxy_api/
stick_table.rs

1use std::ops::Deref;
2
3use mlua::{FromLua, Lua, ObjectLike, Result, Table, Value};
4
5/// The "StickTable" class can be used to access the HAProxy stick tables.
6#[derive(Clone)]
7pub struct StickTable(Table);
8
9impl StickTable {
10    /// Returns stick table attributes as a Lua table.
11    #[inline]
12    pub fn info(&self) -> Result<Table> {
13        self.call_method("info", ())
14    }
15
16    /// Returns stick table entry for given `key`.
17    #[inline]
18    pub fn lookup(&self, key: &str) -> Result<Table> {
19        self.call_method("lookup", key)
20    }
21
22    /// Returns all entries in stick table.
23    ///
24    /// An optional `filter` can be used to extract entries with specific data values.
25    /// Filter is a table with valid comparison operators as keys followed by data type name and value pairs.
26    /// Check out the HAProxy docs for "show table" for more details.
27    #[inline]
28    pub fn dump(&self, filter: Option<&str>) -> Result<Table> {
29        self.call_method("dump", filter)
30    }
31}
32
33impl FromLua for StickTable {
34    #[inline]
35    fn from_lua(value: Value, lua: &Lua) -> Result<Self> {
36        let class = Table::from_lua(value, lua)?;
37        Ok(StickTable(class))
38    }
39}
40
41impl Deref for StickTable {
42    type Target = Table;
43
44    #[inline]
45    fn deref(&self) -> &Self::Target {
46        &self.0
47    }
48}