Skip to content

Commit 03ce3fe

Browse files
committed
Use @josephlr's suggestion
1 parent 7a14dfe commit 03ce3fe

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

rand_core/src/impls.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,16 @@ fn fill_via_chunks<T: Observable>(src: &[T], dest: &mut [u8]) -> (usize, usize)
8888
zipped.for_each(|(dest, src)| dest.copy_from_slice(src.to_le_bytes().as_ref()));
8989

9090
let byte_len = num_chunks * size;
91-
if let (dest_tail @ [_, ..], Some(src)) = (dest.into_remainder(), src.next()) {
92-
let n = dest_tail.len();
93-
dest_tail.copy_from_slice(&src.to_le_bytes().as_ref()[..n]);
94-
(num_chunks + 1, byte_len + n)
95-
} else {
96-
(num_chunks, byte_len)
91+
if let Some(src) = src.next() {
92+
// We have consumed all full chunks of dest, but not src.
93+
let dest = dest.into_remainder();
94+
let n = dest.len();
95+
if n > 0 {
96+
dest.copy_from_slice(&src.to_le_bytes().as_ref()[..n]);
97+
return (num_chunks + 1, byte_len + n);
98+
}
9799
}
100+
(num_chunks, byte_len)
98101
}
99102

100103
/// Implement `fill_bytes` by reading chunks from the output buffer of a block

0 commit comments

Comments
 (0)