]> git.proxmox.com Git - rustc.git/blobdiff - vendor/object/src/read/read_ref.rs
New upstream version 1.55.0+dfsg1
[rustc.git] / vendor / object / src / read / read_ref.rs
index 55f58755c8e2194b9e7d2ce698bd1623f33babec..2f547a4e2c46403cd7015c16b31ccbd7f35412cc 100644 (file)
@@ -1,6 +1,7 @@
 #![allow(clippy::len_without_is_empty)]
 
 use core::convert::TryInto;
+use core::ops::Range;
 use core::{mem, result};
 
 use crate::pod::{from_bytes, slice_from_bytes, Pod};
@@ -42,13 +43,13 @@ pub trait ReadRef<'a>: Clone + Copy {
     /// Returns an error if offset or size are out of bounds.
     fn read_bytes_at(self, offset: u64, size: u64) -> Result<&'a [u8]>;
 
-    /// Get a reference to a delimited `u8` slice at the given offset.
+    /// Get a reference to a delimited `u8` slice which starts at range.start.
     ///
     /// Does not include the delimiter.
     ///
-    /// Returns an error if offset is out of bounds or the delimiter is
-    /// not found.
-    fn read_bytes_at_until(self, offset: u64, delimiter: u8) -> Result<&'a [u8]>;
+    /// Returns an error if the range is out of bounds or the delimiter is
+    /// not found in the range.
+    fn read_bytes_at_until(self, range: Range<u64>, delimiter: u8) -> Result<&'a [u8]>;
 
     /// Get a reference to a `u8` slice at the given offset, and update the offset.
     ///
@@ -121,9 +122,10 @@ impl<'a> ReadRef<'a> for &'a [u8] {
         self.get(offset..).ok_or(())?.get(..size).ok_or(())
     }
 
-    fn read_bytes_at_until(self, offset: u64, delimiter: u8) -> Result<&'a [u8]> {
-        let offset: usize = offset.try_into().map_err(|_| ())?;
-        let bytes = self.get(offset..).ok_or(())?;
+    fn read_bytes_at_until(self, range: Range<u64>, delimiter: u8) -> Result<&'a [u8]> {
+        let start: usize = range.start.try_into().map_err(|_| ())?;
+        let end: usize = range.end.try_into().map_err(|_| ())?;
+        let bytes = self.get(start..end).ok_or(())?;
         match memchr::memchr(delimiter, bytes) {
             Some(len) => {
                 // This will never fail.