follow bytes::Bytes convention for AlignedBuffer

Signed-off-by: Yuchen Liang <yuchen@neon.tech>
This commit is contained in:
Yuchen Liang
2024-10-18 18:06:16 +00:00
parent d99a61bd75
commit ad44e11a69
2 changed files with 16 additions and 3 deletions

View File

@@ -823,7 +823,7 @@ impl InMemoryLayer {
len,
will_init,
} = entry;
let buf = file_contents.slice(pos as usize, (pos + len) as usize);
let buf = file_contents.slice(pos as usize..(pos + len) as usize);
let (_buf, res) = delta_layer_writer
.put_value_bytes(
Key::from_compact(*key),

View File

@@ -1,5 +1,5 @@
use std::{
ops::{Deref, Range},
ops::{Deref, Range, RangeBounds},
sync::Arc,
};
@@ -49,9 +49,22 @@ impl<A: Alignment> AlignedBuffer<A> {
}
/// Returns a slice of self for the index range `[begin..end)`.
pub fn slice(&self, begin: usize, end: usize) -> Self {
pub fn slice(&self, range: impl RangeBounds<usize>) -> Self {
use core::ops::Bound;
let len = self.len();
let begin = match range.start_bound() {
Bound::Included(&n) => n,
Bound::Excluded(&n) => n.checked_add(1).expect("out of range"),
Bound::Unbounded => 0,
};
let end = match range.end_bound() {
Bound::Included(&n) => n.checked_add(1).expect("out of range"),
Bound::Excluded(&n) => n,
Bound::Unbounded => len,
};
assert!(
begin <= end,
"range start must not be greater than end: {:?} <= {:?}",