summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2025-03-30 23:12:47 +0200
committerHampusM <hampus@hampusmat.com>2025-03-30 23:12:47 +0200
commita8cf6007136779c121d90888ec976108baefa8b6 (patch)
treeba4d3305ffdf99071ae0dd2bb2d383a3af1021e5 /src
parent88414e46f5a8c127d7a8e5613276913f2b1ad141 (diff)
feat: add FieldSlice get_item fnHEADmaster
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 6282a8b..6f0c95f 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -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)]