Create a slice view of a portion of the data (not implemented for mapped values)
(&self, start: usize, len: usize)
| 175 | |
| 176 | /// Create a slice view of a portion of the data (not implemented for mapped values) |
| 177 | pub fn slice(&self, start: usize, len: usize) -> Option<MappedValue> { |
| 178 | if start + len > self.len() { |
| 179 | return None; |
| 180 | } |
| 181 | |
| 182 | match self { |
| 183 | MappedValue::Memory(data) => { |
| 184 | Some(MappedValue::Memory(data[start..start + len].to_vec())) |
| 185 | } |
| 186 | MappedValue::Mapped { .. } => { |
| 187 | // Slicing mapped values is complex and not implemented yet |
| 188 | // Would require additional reference counting for the mmap |
| 189 | None |
| 190 | } |
| 191 | MappedValue::Reference(data) => { |
| 192 | Some(MappedValue::Reference(&data[start..start + len])) |
| 193 | } |
| 194 | MappedValue::Small(_) => { |
| 195 | // Small values cannot be sliced |
| 196 | None |
| 197 | } |
| 198 | } |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | /// Reader for memory-mapped values that provides zero-copy access |