diff options
author | HampusM <hampus@hampusmat.com> | 2025-03-27 22:03:21 +0100 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2025-03-28 11:53:10 +0100 |
commit | e71c96e85eeb1878909bb081b3f418ed266ace93 (patch) | |
tree | 24c292302d29c1f29b940ef043ca9b3c9472dee4 | |
parent | 8fe9532383cbcf4b68dd4273ec35919fe589fa73 (diff) |
feat: add get_item_mut fn to FieldSliceMut
-rw-r--r-- | src/lib.rs | 18 |
1 files changed, 18 insertions, 0 deletions
@@ -501,6 +501,24 @@ pub struct FieldSliceMut<'mv> impl FieldSliceMut<'_> { + pub fn get_item_mut(&mut self, item_index: usize) -> Option<FieldMut<'_>> + { + let start_off = item_index * self.field_metadata.size; + + if item_index >= self.len { + return None; + } + + let field_bytes = self + .bytes + .get_mut(start_off..start_off + self.field_metadata.size)?; + + Some(FieldMut { + bytes: field_bytes, + field_metadata: self.field_metadata, + }) + } + pub fn iter_mut(&mut self) -> FieldSliceIterMut<'_> { FieldSliceIterMut { |