Skip to content

Commit

Permalink
override put_slice for &mut [u8] (#483)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zettroke committed Feb 16, 2021
1 parent e418280 commit 268f6f8
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 @@ -1012,6 +1012,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());
}
}
}

unsafe impl BufMut for Vec<u8> {
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 @@ -70,6 +70,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 268f6f8

Please sign in to comment.