Add MultiValue::get
& add clear error in Index
This commit is contained in:
parent
b46b476f80
commit
553251761f
15
src/value.rs
15
src/value.rs
|
@ -248,7 +248,15 @@ impl<'lua> Index<usize> for MultiValue<'lua> {
|
|||
|
||||
#[inline]
|
||||
fn index(&self, index: usize) -> &Self::Output {
|
||||
&self.0[self.0.len() - index - 1]
|
||||
if let Some(result) = self.get(index) {
|
||||
result
|
||||
} else {
|
||||
panic!(
|
||||
"index out of bounds: the len is {} but the index is {}",
|
||||
self.len(),
|
||||
index
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -266,6 +274,11 @@ impl<'lua> MultiValue<'lua> {
|
|||
v
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get(&self, index: usize) -> Option<&Value<'lua>> {
|
||||
self.0.get(self.0.len() - index - 1)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub(crate) fn reserve(&mut self, size: usize) {
|
||||
self.0.reserve(size);
|
||||
|
|
Loading…
Reference in a new issue