diff options
-rw-r--r-- | src/lib.rs | 27 |
1 files changed, 27 insertions, 0 deletions
@@ -731,6 +731,24 @@ impl FieldSlice<'_> unsafe { self.bytes.cast::<Item>() } } + pub fn get_item(&self, item_index: usize) -> Option<Field<'_>> + { + let start_off = self.get_item_offset(item_index)?; + + if item_index >= self.len { + return None; + } + + let field_bytes = self + .bytes + .get(start_off..start_off + self.field_metadata.size)?; + + Some(Field { + bytes: field_bytes, + field_metadata: self.field_metadata, + }) + } + pub fn iter(&self) -> FieldSliceIter<'_> { FieldSliceIter { @@ -740,6 +758,15 @@ impl FieldSlice<'_> field_metadata: self.field_metadata, } } + + fn get_item_offset(&self, item_index: usize) -> Option<usize> + { + if item_index >= self.len { + return None; + } + + Some(item_index * self.field_metadata.size) + } } #[derive(Debug)] |