diff options
author | 2022-07-10 20:44:29 +1000 | |
---|---|---|
committer | 2022-07-10 12:44:29 +0200 | |
commit | 068ed41bc02c21fe0a0a4d8e95af8a4668276f5d (patch) | |
tree | ac10afeab37faa38b79af6ee8cec52c38e456306 /tests/test_bytes.rs | |
parent | f514bd38dac85695e9053d990b251643e9e4ef92 (diff) | |
download | bytes-068ed41bc02c21fe0a0a4d8e95af8a4668276f5d.tar.gz bytes-068ed41bc02c21fe0a0a4d8e95af8a4668276f5d.tar.zst bytes-068ed41bc02c21fe0a0a4d8e95af8a4668276f5d.zip |
Add conversion from BytesMut to Vec<u8> (#543)
Diffstat (limited to 'tests/test_bytes.rs')
-rw-r--r-- | tests/test_bytes.rs | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/test_bytes.rs b/tests/test_bytes.rs index 6853677..ef7512b 100644 --- a/tests/test_bytes.rs +++ b/tests/test_bytes.rs @@ -1028,3 +1028,40 @@ fn box_slice_empty() { let b = Bytes::from(empty); assert!(b.is_empty()); } + +#[test] +fn bytes_into_vec() { + // Test kind == KIND_VEC + let content = b"helloworld"; + + let mut bytes = BytesMut::new(); + bytes.put_slice(content); + + let vec: Vec<u8> = bytes.into(); + assert_eq!(&vec, content); + + // Test kind == KIND_ARC, shared.is_unique() == True + let mut bytes = BytesMut::new(); + bytes.put_slice(b"abcdewe23"); + bytes.put_slice(content); + + // Overwrite the bytes to make sure only one reference to the underlying + // Vec exists. + bytes = bytes.split_off(9); + + let vec: Vec<u8> = bytes.into(); + assert_eq!(&vec, content); + + // Test kind == KIND_ARC, shared.is_unique() == False + let prefix = b"abcdewe23"; + + let mut bytes = BytesMut::new(); + bytes.put_slice(prefix); + bytes.put_slice(content); + + let vec: Vec<u8> = bytes.split_off(prefix.len()).into(); + assert_eq!(&vec, content); + + let vec: Vec<u8> = bytes.into(); + assert_eq!(&vec, prefix); +} |