haproxy_api/
converters.rs

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