pub struct Channel<'lua> { /* private fields */ }
Expand description
The “Channel” class contains all functions to manipulate channels.
Please refer to HAProxy documentation to get more information.
Implementations§
Source§impl<'lua> Channel<'lua>
impl<'lua> Channel<'lua>
Sourcepub fn append(&self, data: impl AsRef<[u8]>) -> Result<isize>
pub fn append(&self, data: impl AsRef<[u8]>) -> Result<isize>
Copies the string string at the end of incoming data of the channel buffer. Returns the copied length on success or -1 if data cannot be copied.
Sourcepub fn data(
&self,
offset: Option<isize>,
length: Option<isize>,
) -> Result<Option<LuaString<'lua>>>
pub fn data( &self, offset: Option<isize>, length: Option<isize>, ) -> Result<Option<LuaString<'lua>>>
Returns length
bytes of incoming data from the channel buffer, starting at the offset
.
The data are not removed from the buffer.
Sourcepub fn forward(&self, length: usize) -> Result<usize>
pub fn forward(&self, length: usize) -> Result<usize>
Forwards length
bytes of data from the channel buffer.
Returns the amount of data forwarded and must not be called from an action to avoid yielding.
Sourcepub fn input(&self) -> Result<usize>
pub fn input(&self) -> Result<usize>
Returns the length of incoming data in the channel buffer.
Sourcepub fn insert(
&self,
data: impl AsRef<[u8]>,
offset: Option<isize>,
) -> Result<isize>
pub fn insert( &self, data: impl AsRef<[u8]>, offset: Option<isize>, ) -> Result<isize>
Copies the data
at the offset
in incoming data of the channel buffer.
Returns the copied length on success or -1 if data cannot be copied.
By default, if no offset
is provided, the string is copied in front of incoming data.
A positive offset
is relative to the beginning of incoming data of the channel buffer while negative offset is relative to their end.
Sourcepub fn line(
&self,
offset: Option<isize>,
length: Option<isize>,
) -> Result<Option<LuaString<'lua>>>
pub fn line( &self, offset: Option<isize>, length: Option<isize>, ) -> Result<Option<LuaString<'lua>>>
Parses length
bytes of incoming data of the channel buffer, starting at offset
,
and returns the first line found, including the \n
.
The data are not removed from the buffer. If no line is found, all data are returned.
Sourcepub fn output(&self) -> Result<usize>
pub fn output(&self) -> Result<usize>
Returns the length of outgoing data of the channel buffer.
Sourcepub fn prepend(&self, data: impl AsRef<[u8]>) -> Result<isize>
pub fn prepend(&self, data: impl AsRef<[u8]>) -> Result<isize>
Copies the data
in front of incoming data of the channel buffer.
Returns the copied length on success or -1 if data cannot be copied.
Sourcepub fn remove(
&self,
offset: Option<isize>,
length: Option<usize>,
) -> Result<isize>
pub fn remove( &self, offset: Option<isize>, length: Option<usize>, ) -> Result<isize>
Removes length
bytes of incoming data of the channel buffer, starting at offset
.
Returns number of bytes removed on success.
Methods from Deref<Target = Table<'lua>>§
Sourcepub fn set<K, V>(&self, key: K, value: V) -> Result<(), Error>
pub fn set<K, V>(&self, key: K, value: V) -> Result<(), Error>
Sets a key-value pair in the table.
If the value is nil
, this will effectively remove the pair.
This might invoke the __newindex
metamethod. Use the raw_set
method if that is not
desired.
§Examples
Export a value as a global to make it usable from Lua:
let globals = lua.globals();
globals.set("assertions", cfg!(debug_assertions))?;
lua.load(r#"
if assertions == true then
-- ...
elseif assertions == false then
-- ...
else
error("assertions neither on nor off?")
end
"#).exec()?;
Sourcepub fn get<K, V>(&self, key: K) -> Result<V, Error>
pub fn get<K, V>(&self, key: K) -> Result<V, Error>
Gets the value associated to key
from the table.
If no value is associated to key
, returns the nil
value.
This might invoke the __index
metamethod. Use the raw_get
method if that is not
desired.
§Examples
Query the version of the Lua interpreter:
let globals = lua.globals();
let version: String = globals.get("_VERSION")?;
println!("Lua version: {}", version);
Sourcepub fn contains_key<K>(&self, key: K) -> Result<bool, Error>where
K: IntoLua<'lua>,
pub fn contains_key<K>(&self, key: K) -> Result<bool, Error>where
K: IntoLua<'lua>,
Checks whether the table contains a non-nil value for key
.
This might invoke the __index
metamethod.
Sourcepub fn push<V>(&self, value: V) -> Result<(), Error>where
V: IntoLua<'lua>,
pub fn push<V>(&self, value: V) -> Result<(), Error>where
V: IntoLua<'lua>,
Appends a value to the back of the table.
This might invoke the __len
and __newindex
metamethods.
Sourcepub fn pop<V>(&self) -> Result<V, Error>where
V: FromLua<'lua>,
pub fn pop<V>(&self) -> Result<V, Error>where
V: FromLua<'lua>,
Removes the last element from the table and returns it.
This might invoke the __len
and __newindex
metamethods.
Sourcepub fn equals<T>(&self, other: T) -> Result<bool, Error>
pub fn equals<T>(&self, other: T) -> Result<bool, Error>
Compares two tables for equality.
Tables are compared by reference first.
If they are not primitively equals, then mlua will try to invoke the __eq
metamethod.
mlua will check self
first for the metamethod, then other
if not found.
§Examples
Compare two tables using __eq
metamethod:
let table1 = lua.create_table()?;
table1.set(1, "value")?;
let table2 = lua.create_table()?;
table2.set(2, "value")?;
let always_equals_mt = lua.create_table()?;
always_equals_mt.set("__eq", lua.create_function(|_, (_t1, _t2): (Table, Table)| Ok(true))?)?;
table2.set_metatable(Some(always_equals_mt));
assert!(table1.equals(&table1.clone())?);
assert!(table1.equals(&table2)?);
Sourcepub fn raw_set<K, V>(&self, key: K, value: V) -> Result<(), Error>
pub fn raw_set<K, V>(&self, key: K, value: V) -> Result<(), Error>
Sets a key-value pair without invoking metamethods.
Sourcepub fn raw_get<K, V>(&self, key: K) -> Result<V, Error>
pub fn raw_get<K, V>(&self, key: K) -> Result<V, Error>
Gets the value associated to key
without invoking metamethods.
Sourcepub fn raw_insert<V>(&self, idx: i64, value: V) -> Result<(), Error>where
V: IntoLua<'lua>,
pub fn raw_insert<V>(&self, idx: i64, value: V) -> Result<(), Error>where
V: IntoLua<'lua>,
Inserts element value at position idx
to the table, shifting up the elements from table[idx]
.
The worst case complexity is O(n), where n is the table length.
Sourcepub fn raw_push<V>(&self, value: V) -> Result<(), Error>where
V: IntoLua<'lua>,
pub fn raw_push<V>(&self, value: V) -> Result<(), Error>where
V: IntoLua<'lua>,
Appends a value to the back of the table without invoking metamethods.
Sourcepub fn raw_pop<V>(&self) -> Result<V, Error>where
V: FromLua<'lua>,
pub fn raw_pop<V>(&self) -> Result<V, Error>where
V: FromLua<'lua>,
Removes the last element from the table and returns it, without invoking metamethods.
Sourcepub fn raw_remove<K>(&self, key: K) -> Result<(), Error>where
K: IntoLua<'lua>,
pub fn raw_remove<K>(&self, key: K) -> Result<(), Error>where
K: IntoLua<'lua>,
Removes a key from the table.
If key
is an integer, mlua shifts down the elements from table[key+1]
,
and erases element table[key]
. The complexity is O(n) in the worst case,
where n is the table length.
For other key types this is equivalent to setting table[key] = nil
.
Sourcepub fn clear(&self) -> Result<(), Error>
pub fn clear(&self) -> Result<(), Error>
Clears the table, removing all keys and values from array and hash parts, without invoking metamethods.
This method is useful to clear the table while keeping its capacity.
Sourcepub fn len(&self) -> Result<i64, Error>
pub fn len(&self) -> Result<i64, Error>
Returns the result of the Lua #
operator.
This might invoke the __len
metamethod. Use the raw_len
method if that is not desired.
Sourcepub fn raw_len(&self) -> usize
pub fn raw_len(&self) -> usize
Returns the result of the Lua #
operator, without invoking the __len
metamethod.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true
if the table is empty, without invoking metamethods.
It checks both the array part and the hash part.
Sourcepub fn get_metatable(&self) -> Option<Table<'lua>>
pub fn get_metatable(&self) -> Option<Table<'lua>>
Returns a reference to the metatable of this table, or None
if no metatable is set.
Unlike the getmetatable
Lua function, this method ignores the __metatable
field.
Sourcepub fn set_metatable(&self, metatable: Option<Table<'lua>>)
pub fn set_metatable(&self, metatable: Option<Table<'lua>>)
Sets or removes the metatable of this table.
If metatable
is None
, the metatable is removed (if no metatable is set, this does
nothing).
Sourcepub fn to_pointer(&self) -> *const c_void
pub fn to_pointer(&self) -> *const c_void
Converts this table to a generic C pointer.
Different tables will give different pointers. There is no way to convert the pointer back to its original value.
Typically this function is used only for hashing and debug information.