MCPcopy Create free account
hub / github.com/erans/pgsqlite / slice

Method slice

src/protocol/memory_mapped.rs:177–199  ·  view source on GitHub ↗

Create a slice view of a portion of the data (not implemented for mapped values)

(&self, start: usize, len: usize)

Source from the content-addressed store, hash-verified

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

Callers 1

test_value_slicingFunction · 0.80

Calls 1

lenMethod · 0.45

Tested by 1

test_value_slicingFunction · 0.64