diff --git a/src/value.rs b/src/value.rs index 1288ca0..b77f2bc 100644 --- a/src/value.rs +++ b/src/value.rs @@ -248,7 +248,15 @@ impl<'lua> Index 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);