diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/lib.rs | 11 |
1 files changed, 4 insertions, 7 deletions
@@ -101,15 +101,12 @@ where pub fn get<FieldSel>( &self, index: usize, - ) -> &<FieldSel as ItemFieldSelection<ItemT>>::Field + ) -> Option<&<FieldSel as ItemFieldSelection<ItemT>>::Field> where FieldSel: ItemFieldSelection<ItemT>, { if index >= self.length { - panic!( - "Index {index} is out of bounds in MultiVec with length {}", - self.length - ); + return None; } let field_metadata = FieldSel::metadata(); @@ -120,7 +117,7 @@ where let field_ptr = unsafe { field_arr_ptr.add(field_metadata.size * index) }; - unsafe { field_ptr.cast().as_ref() } + Some(unsafe { field_ptr.cast().as_ref() }) } /// Returns the number of items stored in this `MultiVec`. @@ -513,7 +510,7 @@ mod tests multi_vec.push(Foo { num_a: 12338, num_b: 191 }); - let item = multi_vec.get::<FooFieldNumA>(1); + let item = multi_vec.get::<FooFieldNumA>(1).unwrap(); println!("yay: {}", *item); } |