pub trait NewIndex<L>: AsRef<Object<L>>where
L: AsLua,{
// Provided methods
fn set<K, V>(&self, key: K, value: V)
where K: PushOneInto<LuaState>,
K::Err: Into<Void>,
V: PushOneInto<LuaState>,
V::Err: Into<Void> { ... }
fn try_set<K, V>(&self, key: K, value: V) -> Result<(), LuaError>
where K: PushOneInto<LuaState>,
K::Err: Into<Void>,
V: PushOneInto<LuaState>,
V::Err: Into<Void> { ... }
fn checked_set<K, V>(
&self,
key: K,
value: V
) -> Result<(), CheckedSetError<K::Err, V::Err>>
where K: PushOneInto<LuaState>,
V: PushOneInto<LuaState> { ... }
fn try_checked_set<K, V>(
&self,
key: K,
value: V
) -> Result<(), Result<CheckedSetError<K::Err, V::Err>, LuaError>>
where K: PushOneInto<LuaState>,
V: PushOneInto<LuaState> { ... }
}
Expand description
Types implementing this trait represent a single lua value that can be
changed by indexed, i.e. a regular lua table or other value implementing
__newindex
metamethod.
Provided Methods§
sourcefn set<K, V>(&self, key: K, value: V)
fn set<K, V>(&self, key: K, value: V)
Inserts or modifies a value
of the table (or other object using the
__index
or __newindex
metamethod) given its index
.
Contrary to NewIndex::checked_set
, can only be called when writing
the key and value cannot fail (which is the case for most types).
Panic
Will panic if an error happens during attempt to set value. Can happen
if __index
or __newindex
throws an error. Use NewIndex::try_set
if this is a possibility in your case.
The index must implement the PushOneInto
trait and the return type
must implement the LuaRead
trait. See the documentation at the
crate root for more information.
sourcefn try_set<K, V>(&self, key: K, value: V) -> Result<(), LuaError>
fn try_set<K, V>(&self, key: K, value: V) -> Result<(), LuaError>
Inserts or modifies a value
of the table (or other object using the
__index
or __newindex
metamethod) given its index
.
Contrary to NewIndex::try_checked_set
, can only be called when
writing the key and value cannot fail (which is the case for most
types).
Returns a LuaError::ExecutionError
in case an error happened during an
attempt to set value.
The index must implement the PushOneInto
trait and the return type
must implement the LuaRead
trait. See the documentation at the
crate root for more information.
sourcefn checked_set<K, V>(
&self,
key: K,
value: V
) -> Result<(), CheckedSetError<K::Err, V::Err>>
fn checked_set<K, V>( &self, key: K, value: V ) -> Result<(), CheckedSetError<K::Err, V::Err>>
Inserts or modifies a value
of the table (or other object using the
__newindex
metamethod) given its index
.
Returns an error if pushing index
or value
failed. This can only
happen for a limited set of types. You are encouraged to use the
NewIndex::set
method if pushing cannot fail.
Panic
Will panic if an error happens during attempt to set value. Can happen
if __index
or __newindex
throws an error. Use
NewIndex::try_checked_set
if this is a possibility in your case.
sourcefn try_checked_set<K, V>(
&self,
key: K,
value: V
) -> Result<(), Result<CheckedSetError<K::Err, V::Err>, LuaError>>
fn try_checked_set<K, V>( &self, key: K, value: V ) -> Result<(), Result<CheckedSetError<K::Err, V::Err>, LuaError>>
Inserts or modifies a value
of the table (or other object using the
__newindex
metamethod) given its index
.
Possible errors
- Returns an error if pushing
index
orvalue
failed. This can only happen for a limited set of types. You are encouraged to use theNewIndex::set
method if pushing cannot fail. - Returns a
LuaError::ExecutionError
in case an error happened during an attempt to set value.