pub struct Server(/* private fields */);
Expand description
The “Server” class provides a way for manipulating servers and retrieving information.
Implementations§
Source§impl Server
impl Server
Sourcepub fn is_draining(&self) -> Result<bool>
pub fn is_draining(&self) -> Result<bool>
Returns true if the server is currently draining sticky connections.
Sourcepub fn is_dynamic(&self) -> Result<bool>
pub fn is_dynamic(&self) -> Result<bool>
Return true if the server was instantiated at runtime (e.g.: from the cli).
Sourcepub fn get_cur_sess(&self) -> Result<u64>
pub fn get_cur_sess(&self) -> Result<u64>
Return the number of currently active sessions on the server.
Sourcepub fn get_pend_conn(&self) -> Result<u64>
pub fn get_pend_conn(&self) -> Result<u64>
Return the number of pending connections to the server.
Sourcepub fn set_maxconn(&self, maxconn: u64) -> Result<()>
pub fn set_maxconn(&self, maxconn: u64) -> Result<()>
Dynamically changes the maximum connections of the server.
Sourcepub fn get_maxconn(&self) -> Result<u64>
pub fn get_maxconn(&self) -> Result<u64>
Returns an integer representing the server maximum connections.
Sourcepub fn set_weight(&self, weight: &str) -> Result<()>
pub fn set_weight(&self, weight: &str) -> Result<()>
Dynamically changes the weight of the server. See the management socket documentation for more information about the format of the string.
Sourcepub fn get_weight(&self) -> Result<u32>
pub fn get_weight(&self) -> Result<u32>
Returns an integer representing the server weight.
Sourcepub fn set_addr(&self, addr: String, port: Option<u16>) -> Result<()>
pub fn set_addr(&self, addr: String, port: Option<u16>) -> Result<()>
Dynamically changes the address of the server.
Sourcepub fn get_addr(&self) -> Result<String>
pub fn get_addr(&self) -> Result<String>
Returns a string describing the address of the server.
Sourcepub fn check_enable(&self) -> Result<()>
pub fn check_enable(&self) -> Result<()>
Enables health checks.
Sourcepub fn check_disable(&self) -> Result<()>
pub fn check_disable(&self) -> Result<()>
Disables health checks.
Sourcepub fn check_force_up(&self) -> Result<()>
pub fn check_force_up(&self) -> Result<()>
Forces health-check up.
Sourcepub fn check_force_nolb(&self) -> Result<()>
pub fn check_force_nolb(&self) -> Result<()>
Forces health-check nolb mode.
Sourcepub fn check_force_down(&self) -> Result<()>
pub fn check_force_down(&self) -> Result<()>
Forces health-check down.
Sourcepub fn agent_enable(&self) -> Result<()>
pub fn agent_enable(&self) -> Result<()>
Enables agent check.
Sourcepub fn agent_disable(&self) -> Result<()>
pub fn agent_disable(&self) -> Result<()>
Disables agent check.
Sourcepub fn agent_force_up(&self) -> Result<()>
pub fn agent_force_up(&self) -> Result<()>
Forces agent check up.
Sourcepub fn agent_force_down(&self) -> Result<()>
pub fn agent_force_down(&self) -> Result<()>
Forces agent check down.
Sourcepub fn tracking(&self) -> Result<Option<Server>>
pub fn tracking(&self) -> Result<Option<Server>>
Check if the current server is tracking another server.
Sourcepub fn get_trackers(&self) -> Result<Vec<Server>>
pub fn get_trackers(&self) -> Result<Vec<Server>>
Check if the current server is being tracked by other servers.
Sourcepub fn event_sub(
&self,
event_types: &[&str],
code: impl AsChunk,
) -> Result<EventSub>
pub fn event_sub( &self, event_types: &[&str], code: impl AsChunk, ) -> Result<EventSub>
Register a function that will be called on specific server events.
It works exactly like core.event_sub()
except that the subscription
will be performed within the server dedicated subscription list instead of the global one.
Methods from Deref<Target = Table>§
Sourcepub fn set(&self, key: impl IntoLua, value: impl IntoLua) -> Result<(), Error>
pub fn set(&self, key: impl IntoLua, value: impl IntoLua) -> 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<V>(&self, key: impl IntoLua) -> Result<V, Error>where
V: FromLua,
pub fn get<V>(&self, key: impl IntoLua) -> Result<V, Error>where
V: FromLua,
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(&self, key: impl IntoLua) -> Result<bool, Error>
pub fn contains_key(&self, key: impl IntoLua) -> Result<bool, Error>
Checks whether the table contains a non-nil value for key
.
This might invoke the __index
metamethod.
Sourcepub fn push(&self, value: impl IntoLua) -> Result<(), Error>
pub fn push(&self, value: impl IntoLua) -> Result<(), Error>
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,
pub fn pop<V>(&self) -> Result<V, Error>where
V: FromLua,
Removes the last element from the table and returns it.
This might invoke the __len
and __newindex
metamethods.
Sourcepub fn equals(&self, other: &Table) -> Result<bool, Error>
pub fn equals(&self, other: &Table) -> 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(
&self,
key: impl IntoLua,
value: impl IntoLua,
) -> Result<(), Error>
pub fn raw_set( &self, key: impl IntoLua, value: impl IntoLua, ) -> Result<(), Error>
Sets a key-value pair without invoking metamethods.
Sourcepub fn raw_get<V>(&self, key: impl IntoLua) -> Result<V, Error>where
V: FromLua,
pub fn raw_get<V>(&self, key: impl IntoLua) -> Result<V, Error>where
V: FromLua,
Gets the value associated to key
without invoking metamethods.
Sourcepub fn raw_insert(&self, idx: i64, value: impl IntoLua) -> Result<(), Error>
pub fn raw_insert(&self, idx: i64, value: impl IntoLua) -> Result<(), Error>
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(&self, value: impl IntoLua) -> Result<(), Error>
pub fn raw_push(&self, value: impl IntoLua) -> Result<(), Error>
Appends a value to the back of the table without invoking metamethods.
Sourcepub fn raw_pop<V>(&self) -> Result<V, Error>where
V: FromLua,
pub fn raw_pop<V>(&self) -> Result<V, Error>where
V: FromLua,
Removes the last element from the table and returns it, without invoking metamethods.
Sourcepub fn raw_remove(&self, key: impl IntoLua) -> Result<(), Error>
pub fn raw_remove(&self, key: impl IntoLua) -> Result<(), Error>
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 Table::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 metatable(&self) -> Option<Table>
pub fn metatable(&self) -> Option<Table>
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>) -> Result<(), Error>
pub fn set_metatable(&self, metatable: Option<Table>) -> Result<(), Error>
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.
Sourcepub fn pairs<K, V>(&self) -> TablePairs<'_, K, V>
pub fn pairs<K, V>(&self) -> TablePairs<'_, K, V>
Returns an iterator over the pairs of the table.
This works like the Lua pairs
function, but does not invoke the __pairs
metamethod.
The pairs are wrapped in a Result
, since they are lazily converted to K
and V
types.
§Examples
Iterate over all globals:
let globals = lua.globals();
for pair in globals.pairs::<Value, Value>() {
let (key, value) = pair?;
// ...
}
Sourcepub fn for_each<K, V>(
&self,
f: impl FnMut(K, V) -> Result<(), Error>,
) -> Result<(), Error>
pub fn for_each<K, V>( &self, f: impl FnMut(K, V) -> Result<(), Error>, ) -> Result<(), Error>
Iterates over the pairs of the table, invoking the given closure on each pair.
This method is similar to Table::pairs
, but optimized for performance.
It does not invoke the __pairs
metamethod.
Sourcepub fn sequence_values<V>(&self) -> TableSequence<'_, V>where
V: FromLua,
pub fn sequence_values<V>(&self) -> TableSequence<'_, V>where
V: FromLua,
Returns an iterator over all values in the sequence part of the table.
The iterator will yield all values t[1]
, t[2]
and so on, until a nil
value is
encountered. This mirrors the behavior of Lua’s ipairs
function but does not invoke
any metamethods.
§Examples
let my_table: Table = lua.load(r#"
{
[1] = 4,
[2] = 5,
[4] = 7,
key = 2
}
"#).eval()?;
let expected = [4, 5];
for (&expected, got) in expected.iter().zip(my_table.sequence_values::<u32>()) {
assert_eq!(expected, got?);
}
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Server
impl !RefUnwindSafe for Server
impl !Send for Server
impl !Sync for Server
impl Unpin for Server
impl !UnwindSafe for Server
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FromLuaMulti for Twhere
T: FromLua,
impl<T> FromLuaMulti for Twhere
T: FromLua,
Source§fn from_lua_multi(values: MultiValue, lua: &Lua) -> Result<T, Error>
fn from_lua_multi(values: MultiValue, lua: &Lua) -> Result<T, Error>
fn from_lua_args( args: MultiValue, i: usize, to: Option<&str>, lua: &Lua, ) -> Result<T, Error>
unsafe fn from_stack_multi(nvals: i32, lua: &RawLua) -> Result<T, Error>
unsafe fn from_stack_args( nargs: i32, i: usize, to: Option<&str>, lua: &RawLua, ) -> Result<T, Error>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more