Skip to content

Commit e21c402

Browse files
authored
Merge pull request #203 from kpp/simplify_histbuf
Simplify code in histbuf for const generics
2 parents 5d294a7 + 6bee0f8 commit e21c402

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

src/histbuf.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,7 @@ impl<T, const N: usize> HistoryBuffer<T, N> {
174174
/// Returns the array slice backing the buffer, without keeping track
175175
/// of the write position. Therefore, the element order is unspecified.
176176
pub fn as_slice(&self) -> &[T] {
177-
if self.filled {
178-
unsafe { slice::from_raw_parts(self.data.as_ptr() as *const _, self.capacity()) }
179-
} else {
180-
unsafe { slice::from_raw_parts(self.data.as_ptr() as *const _, self.write_at) }
181-
}
177+
unsafe { slice::from_raw_parts(self.data.as_ptr() as *const _, self.len()) }
182178
}
183179
}
184180

@@ -276,6 +272,8 @@ mod tests {
276272
fn as_slice() {
277273
let mut x: HistoryBuffer<u8, 4> = HistoryBuffer::new();
278274

275+
assert_eq!(x.as_slice(), []);
276+
279277
x.extend([1, 2, 3, 4, 5].iter());
280278

281279
assert_eq!(x.as_slice(), [5, 2, 3, 4]);

0 commit comments

Comments
 (0)