Skip to content

Commit d205d76

Browse files
authored
Update slice_bytes.rs
1 parent dc441d6 commit d205d76

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/slice/slice_bytes.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ impl Slice {
3737
}
3838

3939
/// Constructs a [`Slice`] from an I/O reader by pulling in `len` bytes.
40+
///
41+
/// The reader may not read the existing buffer.
4042
#[doc(hidden)]
4143
pub fn from_reader<R: std::io::Read>(reader: &mut R, len: usize) -> std::io::Result<Self> {
4244
// Use `with_capacity` & `set_len`` to avoid zeroing the buffer
@@ -49,6 +51,11 @@ impl Slice {
4951
builder.set_len(len);
5052
}
5153

54+
/// SAFETY: Normally, read_exact over an uninitialized buffer is UB,
55+
/// however we know that in lsm-tree etc. only I/O readers or cursors over Vecs are used
56+
/// so it's safe
57+
///
58+
/// The safe API is unstable: https://github.com/rust-lang/rust/issues/78485
5259
reader.read_exact(&mut builder)?;
5360

5461
Ok(Self(builder.freeze()))

0 commit comments

Comments
 (0)