Skip to content

Commit

Permalink
override put_slice for &mut [u8] (tokio-rs#483)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zettroke authored and lelongg committed Jan 9, 2023
1 parent b2fef63 commit d8d398b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/buf/buf_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1014,6 +1014,14 @@ unsafe impl BufMut for &mut [u8] {
let (_, b) = core::mem::replace(self, &mut []).split_at_mut(cnt);
*self = b;
}

#[inline]
fn put_slice(&mut self, src: &[u8]) {
self[..src.len()].copy_from_slice(src);
unsafe {
self.advance_mut(src.len());
}
}
}

#[cfg(feature = "alloc")]
Expand Down
3 changes: 3 additions & 0 deletions tests/test_buf_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ fn test_mut_slice() {
let mut v = vec![0, 0, 0, 0];
let mut s = &mut v[..];
s.put_u32(42);

assert_eq!(s.len(), 0);
assert_eq!(&v, &[0, 0, 0, 42]);
}

#[test]
Expand Down

0 comments on commit d8d398b

Please sign in to comment.