MCPcopy Create free account
hub / github.com/apache/arrow-rs / slice_with_length

Method slice_with_length

arrow-buffer/src/buffer/immutable.rs:287–301  ·  view source on GitHub ↗

Returns a new [Buffer] that is a slice of this buffer starting at `offset`, with `length` bytes. This function is `O(1)` and does not copy any data, allowing the same memory region to be shared between buffers. # Panics Panics iff `(offset + length)` is larger than the existing length.

(&self, offset: usize, length: usize)

Source from the content-addressed store, hash-verified

285 /// # Panics
286 /// Panics iff `(offset + length)` is larger than the existing length.
287 pub fn slice_with_length(&self, offset: usize, length: usize) -> Self {
288 assert!(
289 offset.saturating_add(length) <= self.length,
290 "the offset of the new Buffer cannot exceed the existing length: slice offset={offset} length={length} selflen={}",
291 self.length
292 );
293 // Safety:
294 // offset + length <= self.length
295 let ptr = unsafe { self.ptr.add(offset) };
296 Self {
297 data: self.data.clone(),
298 ptr,
299 length,
300 }
301 }
302
303 /// Returns a pointer to the start of this buffer.
304 ///

Callers 15

newMethod · 0.80
get_batchMethod · 0.80
newMethod · 0.80
bit_sliceMethod · 0.80
test_sliceFunction · 0.80
test_shrink_to_fitFunction · 0.80
slice_overflowFunction · 0.80
test_vec_interopFunction · 0.80
into_builderMethod · 0.80
sliceMethod · 0.80

Calls 2

addMethod · 0.45
cloneMethod · 0.45

Tested by 9

test_sliceFunction · 0.64
test_shrink_to_fitFunction · 0.64
test_vec_interopFunction · 0.64
test_eosFunction · 0.64
test_schemaFunction · 0.64