diff options
author | HampusM <hampus@hampusmat.com> | 2025-03-30 23:12:47 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2025-03-30 23:12:47 +0200 |
commit | a8cf6007136779c121d90888ec976108baefa8b6 (patch) | |
tree | ba4d3305ffdf99071ae0dd2bb2d383a3af1021e5 /src | |
parent | 88414e46f5a8c127d7a8e5613276913f2b1ad141 (diff) |
Diffstat (limited to 'src')
-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)] |