wleeaf commented on code in PR #11881:
URL: https://github.com/apache/arrow-rs/pull/11881#discussion_r4366813476


##########
arrow-buffer/src/buffer/immutable.rs:
##########
@@ -311,6 +311,17 @@ impl Buffer {
         }
     }
 
+    /// Returns a new [Buffer] that is a slice of this buffer starting at 
`offset`,
+    /// with `length` bytes, or `None` if `(offset + length)` is larger than 
the
+    /// existing length.
+    ///
+    /// This is the non-panicking version of [`Self::slice_with_length`], in 
the same
+    /// way as [`slice::get`] is for indexing.
+    pub fn checked_slice_with_length(&self, offset: usize, length: usize) -> 
Option<Self> {
+        (offset.saturating_add(length) <= self.length)

Review Comment:
   Done in 053c4343. It now returns `Result<Buffer, SliceOutOfBoundsError>`, 
and I renamed it `try_slice_with_length` to match the crate's other 
`Result`-returning methods (`try_reserve`, `try_push_length`).
   
   `arrow-buffer` has no `ArrowError`, so `SliceOutOfBoundsError` is a small 
error type next to `OverflowError` in `error.rs`. Its message is the one 
`slice_with_length` panicked with. `slice_with_length` now just calls it and 
panics with that message: `unwrap_or_else(|e| panic!("{e}"))` instead of 
`unwrap()`, so the panic text stays the same as before (the existing 
`should_panic` tests check it). The IPC reader maps the error to 
`ArrowError::IpcError` at the three call sites, and the local helper is gone.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to