haproxy_api/
fetches.rs

1use mlua::{FromLua, IntoLuaMulti, Lua, Result, Table, TableExt, Value};
2
3/// The "Fetches" class allows to call a lot of internal HAProxy sample fetches.
4#[derive(Clone)]
5pub struct Fetches<'lua>(Table<'lua>);
6
7impl<'lua> Fetches<'lua> {
8    /// Executes an internal haproxy sample fetch.
9    #[inline]
10    pub fn get<A, R>(&self, name: &str, args: A) -> Result<R>
11    where
12        A: IntoLuaMulti<'lua>,
13        R: FromLua<'lua>,
14    {
15        self.0.call_method(name, args)
16    }
17
18    /// The same as `get` but always returns string.
19    #[inline]
20    pub fn get_str<A>(&self, name: &str, args: A) -> Result<String>
21    where
22        A: IntoLuaMulti<'lua>,
23    {
24        Ok((self.0.call_method::<_, Option<_>>(name, args)?).unwrap_or_default())
25    }
26}
27
28impl<'lua> FromLua<'lua> for Fetches<'lua> {
29    #[inline]
30    fn from_lua(value: Value<'lua>, lua: &'lua Lua) -> Result<Self> {
31        Ok(Fetches(Table::from_lua(value, lua)?))
32    }
33}