From e71c96e85eeb1878909bb081b3f418ed266ace93 Mon Sep 17 00:00:00 2001 From: HampusM Date: Thu, 27 Mar 2025 22:03:21 +0100 Subject: feat: add get_item_mut fn to FieldSliceMut --- src/lib.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index 12689c7..1d52d91 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -501,6 +501,24 @@ pub struct FieldSliceMut<'mv> impl FieldSliceMut<'_> { + pub fn get_item_mut(&mut self, item_index: usize) -> Option> + { + 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 { -- cgit v1.2.3-18-g5258