Compare commits

...
18 Commits
Author SHA1 Message Date
Carl Lerche e5c7ef3b86 Bump version to v0.4.3 2017-04-30 16:25:54 -07:00
Dan BurkertandCarl Lerche 30bd7c1f21 Vec::advance_mut can advance past the end of the buffer (#108) 2017-04-30 16:14:54 -07:00
Arthur SilvaandCarl Lerche 923d927bd1 Bump minimum rust version to 1.15 (#107) 2017-04-26 11:35:10 -07:00
Phil RuffwindandCarl Lerche 0b4185c716 Fix typos in src/bytes.rs (#106) 2017-04-24 12:47:24 -07:00
jaystrictorandCarl Lerche e158160418 Remove calls to deprecated drain* methods from docs (#102) 2017-04-14 09:06:58 -07:00
Sean McArthurandCarl Lerche 4645f6ec4b implement put_u8 for BytesMut (#101) 2017-04-06 08:59:13 -07:00
Carl Lerche 1a6901cdcd Bump version to v0.4.2 2017-04-05 12:12:05 -07:00
Carl LercheandGitHub 9aa24ebea1 Bytes: only the vec repr is not shared (#100)
The shared debug_assert is to ensure that the internal Bytes
representation is such that offset views are supported. The only
representation that does not support offset views is vec.

Fixes #97
2017-03-30 14:49:30 -07:00
Stepan KoltsovandCarl Lerche 627864187c Bytes::split_{off,to} should panic if at > len (#91) 2017-03-28 12:38:48 -07:00
Stepan KoltsovandCarl Lerche b78bb3baaa Handle corner cases of Bytes::split_{off,to} (#87)
Before this commit `Bytes::split_{off,to}` always created a shallow copy if `self` is arc or vec.

However, in certain cases `split_off` or `split_to` is called with `len` or `0` parameter. E. g. if you are reading a frame from buffered stream, it is likely that buffer contains exactly the frame size bytes, so `split_to` will be called with `len` param.

Although, `split_off` and `split_to` functions are `O(1)`, shallow copy have downsides:

* shallow copy on vector does malloc and atomic cmpxchg
* after shallow copy, following operations (e. g. `drop`) on both `bytes` objects require atomics
* memory will be probably released to the system later
* `try_mut` will fail
* [into_vec](https://github.com/carllerche/bytes/issues/86) will copy
2017-03-27 20:45:22 -07:00
Alex CrichtonandCarl Lerche 6c6c55d8e1 Flag Deref methods as #[inline] (#93) 2017-03-24 07:39:57 -07:00
Stepan KoltsovandCarl Lerche 613d4bd5d5 Reimplement fmt::Debug for Bytes and BytesMut (#84)
Standard `Debug` implementation for `[u8]` is comma separated list
of numbers. Since large amount of byte strings are in fact ASCII
strings or contain a lot of ASCII strings (e. g. HTTP), it is
convenient to print strings as ASCII when possible.
2017-03-20 21:09:44 -07:00
Carl LercheandGitHub dc9c8e304e Misc CI fixes (#89)
Limit the number of threads when using qemu to 1. Also, don't bother
running the stress test as this will trigger qemu bugs. Finally, also
make the stress test actually stress test.
2017-03-20 10:12:23 -07:00
Carl Lerche bed128b2c0 Clarify when BufMut::bytes_mut can return &[]
Closes #79
2017-03-19 13:58:44 -07:00
Dan BurkertandCarl Lerche 5a265cc8eb Add inline attributes to Vec's MutBuf methods (#80)
I found this significantly improved a
[benchmark](https://gist.github.com/danburkert/34a7d6680d97bc86dca7f396eb8d0abf)
which calls `bytes_mut`, writes 1 byte, and advances the pointer with
`advance_mut` in a pretty tight loop. In particular, it seems to be the
inline annotation on `bytes_mut` which had the most effect. I also took
the opportunity to simplify the bounds checking in advance_mut.

before:

```
test encode_varint_small  ... bench:         540 ns/iter (+/- 85) = 1481 MB/s
```

after:

```
test encode_varint_small  ... bench:         422 ns/iter (+/- 24) = 1895 MB/s
```

As you can see, the variance is also significantly improved.

Interestingly, I tried to change the last statement in `bytes_mut` from

```
&mut slice::from_raw_parts_mut(ptr, cap)[len..]
```

to

```
slice::from_raw_parts_mut(ptr.offset(len as isize), cap - len)
```

but, this caused a very measurable perf regression (almost completely
negating the gains from marking bytes_mut inline).
2017-03-19 13:54:09 -07:00
Dan BurkertandCarl Lerche 4fe4e9429a Clarify BufMut::advance_mut docs (#78)
Also fixes an issue with a line wrap in the middle of an inline code
block.
2017-03-19 13:53:33 -07:00
Carl Lerche 9a4018e757 Fix tests on nightly
Closes #83
2017-03-19 09:08:41 -07:00
Carl LercheandGitHub 99fba239db Tweak docs (#76) 2017-03-16 12:11:10 -07:00
12 changed files with 316 additions and 56 deletions
+3 -3
View File
@@ -19,7 +19,7 @@ matrix:
#
# This job will also build and deploy the docs to gh-pages.
- env: TARGET=x86_64-unknown-linux-gnu
rust: 1.10.0
rust: 1.15.0
after_success:
- |
pip install 'travis-cargo<0.2' --user &&
@@ -30,8 +30,8 @@ matrix:
# Run tests on some extra platforms
- env: TARGET=i686-unknown-linux-gnu
- env: TARGET=armv7-unknown-linux-gnueabihf
- env: TARGET=powerpc-unknown-linux-gnu
- env: TARGET=powerpc64-unknown-linux-gnu
- env: RUST_TEST_THREADS=1 TARGET=powerpc-unknown-linux-gnu
- env: RUST_TEST_THREADS=1 TARGET=powerpc64-unknown-linux-gnu
before_install: set -e
+11
View File
@@ -1,3 +1,14 @@
# 0.4.3 (April, 30, 2017)
* Fix Vec::advance_mut bug
* Bump minimum Rust version to 1.15
* Misc performance tweaks
# 0.4.2 (April, 5, 2017)
* Misc performance tweaks
* Improved `Debug` implementation for `Bytes`
* Avoid some incorrect assert panics
# 0.4.1 (March 15, 2017)
+1 -1
View File
@@ -1,7 +1,7 @@
[package]
name = "bytes"
version = "0.4.1"
version = "0.4.3"
license = "MIT"
authors = ["Carl Lerche <[email protected]>"]
description = "Types and traits for working with bytes"
+2 -1
View File
@@ -9,7 +9,8 @@ use std::{cmp, io, ptr};
/// A buffer stores bytes in memory such that read operations are infallible.
/// The underlying storage may or may not be in contiguous memory. A `Buf` value
/// is a cursor into the buffer. Reading from `Buf` advances the cursor
/// position.
/// position. It can be thought of as an efficient `Iterator` for collections of
/// bytes.
///
/// The simplest `Buf` is a `Cursor` wrapping a `[u8]`.
///
+18 -14
View File
@@ -59,7 +59,7 @@ pub trait BufMut {
/// further into the underlying buffer.
///
/// This function is unsafe because there is no guarantee that the bytes
/// being advanced to have been initialized.
/// being advanced past have been initialized.
///
/// # Examples
///
@@ -90,9 +90,9 @@ pub trait BufMut {
///
/// # Implementer notes
///
/// It is recommended for implementations of `advance_mut` to panic if `cnt
/// > self.remaining_mut()`. If the implementation does not panic, the call
/// must behave as if `cnt == self.remaining_mut()`.
/// It is recommended for implementations of `advance_mut` to panic if
/// `cnt > self.remaining_mut()`. If the implementation does not panic,
/// the call must behave as if `cnt == self.remaining_mut()`.
///
/// A call with `cnt == 0` should never panic and be a no-op.
unsafe fn advance_mut(&mut self, cnt: usize);
@@ -153,8 +153,10 @@ pub trait BufMut {
///
/// # Implementer notes
///
/// This function should never panic. Once the end of the buffer is reached,
/// i.e., `BufMut::remaining_mut` returns 0, calls to `bytes_mut` should
/// This function should never panic. `bytes_mut` should return an empty
/// slice **if and only if** `remaining_mut` returns 0. In other words,
/// `bytes_mut` returning an empty slice implies that `remaining_mut` will
/// return 0 and `remaining_mut` returning 0 implies that `bytes_mut` will
/// return an empty slice.
unsafe fn bytes_mut(&mut self) -> &mut [u8];
@@ -699,23 +701,25 @@ impl<T: AsMut<[u8]> + AsRef<[u8]>> BufMut for io::Cursor<T> {
}
impl BufMut for Vec<u8> {
#[inline]
fn remaining_mut(&self) -> usize {
usize::MAX - self.len()
}
#[inline]
unsafe fn advance_mut(&mut self, cnt: usize) {
let cap = self.capacity();
let len = self.len().checked_add(cnt)
.expect("overflow");
if len > cap {
// Reserve additional
self.reserve(cap - len);
let len = self.len();
let remaining = self.capacity() - len;
if cnt > remaining {
// Reserve additional capacity, and ensure that the total length
// will not overflow usize.
self.reserve(cnt);
}
self.set_len(len);
self.set_len(len + cnt);
}
#[inline]
unsafe fn bytes_mut(&mut self) -> &mut [u8] {
use std::slice;
+77 -8
View File
@@ -1,5 +1,6 @@
use {IntoBuf, Buf, BufMut};
use buf::Iter;
use debug;
use std::{cmp, fmt, mem, hash, ops, slice, ptr, usize};
use std::borrow::Borrow;
@@ -86,13 +87,13 @@ use std::sync::atomic::Ordering::{Relaxed, Acquire, Release, AcqRel};
/// underlying memory slice and may not be mutated, `BytesMut` handles are
/// guaranteed to be the only handle able to view that slice of memory. As such,
/// `BytesMut` handles are able to mutate the underlying memory. Note that
/// holding a unique view to a region of memory does not mean that there are not
/// holding a unique view to a region of memory does not mean that there are no
/// other `Bytes` and `BytesMut` handles with disjoint views of the underlying
/// memory.
///
/// # Inline bytes.
///
/// As an opitmization, when the slice referenced by a `Bytes` or `BytesMut`
/// As an optimization, when the slice referenced by a `Bytes` or `BytesMut`
/// handle is small enough [1], `Bytes` will avoid the allocation by inlining
/// the slice directly in the handle. In this case, a clone is no longer
/// "shallow" and the data will be copied.
@@ -107,10 +108,24 @@ pub struct Bytes {
///
/// `BytesMut` represents a unique view into a potentially shared memory region.
/// Given the uniqueness guarantee, owners of `BytesMut` handles are able to
/// mutate the memory.
/// mutate the memory. It is similar to a `Vec<u8>` but with less copies and
/// allocations.
///
/// For more detail, see [Bytes](struct.Bytes.html).
///
/// # Growth
///
/// One key difference from `Vec<u8>` is that most operations **do not
/// implicitly grow the buffer**. This means that calling `my_bytes.put("hello
/// world");` could panic if `my_bytes` does not have enough capacity. Before
/// writing to the buffer, ensure that there is enough remaining capacity by
/// calling `my_bytes.remaining_mut()`. In general, avoiding calls to `reserve`
/// is preferable.
///
/// The only exception is `extend` which implicitly reserves required capacity.
///
/// # Examples
///
/// ```
/// use bytes::{BytesMut, BufMut};
///
@@ -534,6 +549,16 @@ impl Bytes {
///
/// Panics if `at > len`
pub fn split_off(&mut self, at: usize) -> Bytes {
assert!(at <= self.len());
if at == self.len() {
return Bytes::new();
}
if at == 0 {
return mem::replace(self, Bytes::new());
}
Bytes {
inner: Inner2 {
inner: self.inner.split_off(at),
@@ -565,6 +590,16 @@ impl Bytes {
///
/// Panics if `at > len`
pub fn split_to(&mut self, at: usize) -> Bytes {
assert!(at <= self.len());
if at == self.len() {
return mem::replace(self, Bytes::new());
}
if at == 0 {
return Bytes::new();
}
Bytes {
inner: Inner2 {
inner: self.inner.split_to(at),
@@ -650,6 +685,7 @@ impl AsRef<[u8]> for Bytes {
impl ops::Deref for Bytes {
type Target = [u8];
#[inline]
fn deref(&self) -> &[u8] {
self.inner.as_ref()
}
@@ -708,7 +744,7 @@ impl Eq for Bytes {
impl fmt::Debug for Bytes {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fmt::Debug::fmt(&self.inner.as_ref(), fmt)
fmt::Debug::fmt(&debug::BsDebug(&self.inner.as_ref()), fmt)
}
}
@@ -1075,7 +1111,7 @@ impl BytesMut {
/// buf.put(&[0; 64][..]);
///
/// let ptr = buf.as_ptr();
/// let other = buf.drain();
/// let other = buf.take();
///
/// assert!(buf.is_empty());
/// assert_eq!(buf.capacity(), 64);
@@ -1128,6 +1164,16 @@ impl BufMut for BytesMut {
self.advance_mut(len);
}
}
#[inline]
fn put_u8(&mut self, n: u8) {
self.inner.put_u8(n);
}
#[inline]
fn put_i8(&mut self, n: i8) {
self.put_u8(n as u8);
}
}
impl IntoBuf for BytesMut {
@@ -1155,12 +1201,14 @@ impl AsRef<[u8]> for BytesMut {
impl ops::Deref for BytesMut {
type Target = [u8];
#[inline]
fn deref(&self) -> &[u8] {
self.as_ref()
}
}
impl ops::DerefMut for BytesMut {
#[inline]
fn deref_mut(&mut self) -> &mut [u8] {
self.inner.as_mut()
}
@@ -1246,7 +1294,7 @@ impl Eq for BytesMut {
impl fmt::Debug for BytesMut {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fmt::Debug::fmt(self.inner.as_ref(), fmt)
fmt::Debug::fmt(&debug::BsDebug(&self.inner.as_ref()), fmt)
}
}
@@ -1425,6 +1473,25 @@ impl Inner {
}
}
/// Insert a byte into the next slot and advance the len by 1.
#[inline]
fn put_u8(&mut self, n: u8) {
if self.is_inline() {
let len = self.inline_len();
assert!(len < INLINE_CAP);
unsafe {
*self.inline_ptr().offset(len as isize) = n;
}
self.set_inline_len(len + 1);
} else {
assert!(self.len < self.cap);
unsafe {
*self.ptr.offset(self.len as isize) = n;
}
self.len += 1;
}
}
#[inline]
fn len(&self) -> usize {
if self.is_inline() {
@@ -1852,8 +1919,8 @@ impl Inner {
#[inline]
fn is_shared(&mut self) -> bool {
match self.kind() {
KIND_INLINE | KIND_ARC => true,
_ => false,
KIND_VEC => false,
_ => true,
}
}
@@ -1984,12 +2051,14 @@ unsafe impl Sync for Inner {}
impl ops::Deref for Inner2 {
type Target = Inner;
#[inline]
fn deref(&self) -> &Inner {
&self.inner
}
}
impl ops::DerefMut for Inner2 {
#[inline]
fn deref_mut(&mut self) -> &mut Inner {
&mut self.inner
}
+40
View File
@@ -0,0 +1,40 @@
use std::fmt;
/// Alternative implementation of `fmt::Debug` for byte slice.
///
/// Standard `Debug` implementation for `[u8]` is comma separated
/// list of numbers. Since large amount of byte strings are in fact
/// ASCII strings or contain a lot of ASCII strings (e. g. HTTP),
/// it is convenient to print strings as ASCII when possible.
///
/// This struct wraps `&[u8]` just to override `fmt::Debug`.
///
/// `BsDebug` is not a part of public API of bytes crate.
pub struct BsDebug<'a>(pub &'a [u8]);
impl<'a> fmt::Debug for BsDebug<'a> {
fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> {
try!(write!(fmt, "b\""));
for &c in self.0 {
// https://doc.rust-lang.org/reference.html#byte-escapes
if c == b'\n' {
try!(write!(fmt, "\\n"));
} else if c == b'\r' {
try!(write!(fmt, "\\r"));
} else if c == b'\t' {
try!(write!(fmt, "\\t"));
} else if c == b'\\' || c == b'"' {
try!(write!(fmt, "\\{}", c as char));
} else if c == b'\0' {
try!(write!(fmt, "\\0"));
// ASCII printable except space
} else if c > 0x20 && c < 0x7f {
try!(write!(fmt, "{}", c as char));
} else {
try!(write!(fmt, "\\x{:02x}", c));
}
}
try!(write!(fmt, "\""));
Ok(())
}
}
+3 -2
View File
@@ -29,12 +29,12 @@
//! buf.put(&b"hello world"[..]);
//! buf.put_u16::<BigEndian>(1234);
//!
//! let a = buf.drain();
//! let a = buf.take();
//! assert_eq!(a, b"hello world\x04\xD2"[..]);
//!
//! buf.put(&b"goodbye world"[..]);
//!
//! let b = buf.drain();
//! let b = buf.take();
//! assert_eq!(b, b"goodbye world"[..]);
//!
//! assert_eq!(buf.capacity(), 998);
@@ -89,6 +89,7 @@ pub use buf::{
};
mod bytes;
mod debug;
pub use bytes::{Bytes, BytesMut};
pub use byteorder::{ByteOrder, BigEndian, LittleEndian};
+11
View File
@@ -49,6 +49,17 @@ fn test_put_u16() {
assert_eq!(b"\x54\x21", &buf[..]);
}
#[test]
fn test_vec_advance_mut() {
// Regression test for carllerche/bytes#108.
let mut buf = Vec::with_capacity(8);
unsafe {
buf.advance_mut(12);
assert_eq!(buf.len(), 12);
assert!(buf.capacity() >= 12, "capacity: {}", buf.capacity());
}
}
#[test]
fn test_clone() {
let mut buf = BytesMut::with_capacity(100);
+82 -3
View File
@@ -43,7 +43,7 @@ fn from_slice() {
#[test]
fn fmt() {
let a = format!("{:?}", Bytes::from(&b"abcdefg"[..]));
let b = format!("{:?}", b"abcdefg");
let b = "b\"abcdefg\"";
assert_eq!(a, b);
@@ -134,6 +134,50 @@ fn split_off_uninitialized() {
assert_eq!(other.capacity(), 896);
}
#[test]
fn split_off_to_loop() {
let s = b"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
for i in 0..(s.len() + 1) {
{
let mut bytes = Bytes::from(&s[..]);
let off = bytes.split_off(i);
assert_eq!(i, bytes.len());
let mut sum = Vec::new();
sum.extend(&bytes);
sum.extend(&off);
assert_eq!(&s[..], &sum[..]);
}
{
let mut bytes = BytesMut::from(&s[..]);
let off = bytes.split_off(i);
assert_eq!(i, bytes.len());
let mut sum = Vec::new();
sum.extend(&bytes);
sum.extend(&off);
assert_eq!(&s[..], &sum[..]);
}
{
let mut bytes = Bytes::from(&s[..]);
let off = bytes.split_to(i);
assert_eq!(i, off.len());
let mut sum = Vec::new();
sum.extend(&off);
sum.extend(&bytes);
assert_eq!(&s[..], &sum[..]);
}
{
let mut bytes = BytesMut::from(&s[..]);
let off = bytes.split_to(i);
assert_eq!(i, off.len());
let mut sum = Vec::new();
sum.extend(&off);
sum.extend(&bytes);
assert_eq!(&s[..], &sum[..]);
}
}
}
#[test]
fn split_to_1() {
// Inline
@@ -194,6 +238,28 @@ fn split_to_uninitialized() {
assert_eq!(other.capacity(), 128);
}
#[test]
fn split_off_to_at_gt_len() {
fn make_bytes() -> Bytes {
let mut bytes = BytesMut::with_capacity(100);
bytes.put_slice(&[10, 20, 30, 40]);
bytes.freeze()
}
use std::panic;
make_bytes().split_to(4);
make_bytes().split_off(4);
assert!(panic::catch_unwind(move || {
make_bytes().split_to(5);
}).is_err());
assert!(panic::catch_unwind(move || {
make_bytes().split_off(5);
}).is_err());
}
#[test]
fn fns_defined_for_bytes_mut() {
let mut bytes = BytesMut::from(&b"hello world"[..]);
@@ -298,6 +364,18 @@ fn extend() {
}
#[test]
fn from_static() {
let mut a = Bytes::from_static(b"ab");
let b = a.split_off(1);
assert_eq!(a, b"a"[..]);
assert_eq!(b, b"b"[..]);
}
#[test]
// Only run these tests on little endian systems. CI uses qemu for testing
// little endian... and qemu doesn't really support threading all that well.
#[cfg(target_endian = "little")]
fn stress() {
// Tests promoting a buffer from a vec -> shared in a concurrent situation
use std::sync::{Arc, Barrier};
@@ -308,7 +386,7 @@ fn stress() {
for i in 0..ITERS {
let data = [i as u8; 256];
let buf = Arc::new(BytesMut::from(&data[..]));
let buf = Arc::new(Bytes::from(&data[..]));
let barrier = Arc::new(Barrier::new(THREADS));
let mut joins = Vec::with_capacity(THREADS);
@@ -319,7 +397,8 @@ fn stress() {
joins.push(thread::spawn(move || {
c.wait();
let _buf = buf.clone();
let buf: Bytes = (*buf).clone();
drop(buf);
}));
}
+33 -24
View File
@@ -53,41 +53,50 @@ fn vectored_read() {
let b = Cursor::new(Bytes::from(&b"world"[..]));
let mut buf = a.chain(b);
let mut iovecs: [&IoVec; 4] = Default::default();
assert_eq!(2, buf.bytes_vec(&mut iovecs));
assert_eq!(iovecs[0][..], b"hello"[..]);
assert_eq!(iovecs[1][..], b"world"[..]);
assert!(iovecs[2].is_empty());
assert!(iovecs[3].is_empty());
{
let mut iovecs: [&IoVec; 4] = Default::default();
assert_eq!(2, buf.bytes_vec(&mut iovecs));
assert_eq!(iovecs[0][..], b"hello"[..]);
assert_eq!(iovecs[1][..], b"world"[..]);
assert!(iovecs[2].is_empty());
assert!(iovecs[3].is_empty());
}
buf.advance(2);
iovecs = Default::default();
{
let mut iovecs: [&IoVec; 4] = Default::default();
assert_eq!(2, buf.bytes_vec(&mut iovecs));
assert_eq!(iovecs[0][..], b"llo"[..]);
assert_eq!(iovecs[1][..], b"world"[..]);
assert!(iovecs[2].is_empty());
assert!(iovecs[3].is_empty());
assert_eq!(2, buf.bytes_vec(&mut iovecs));
assert_eq!(iovecs[0][..], b"llo"[..]);
assert_eq!(iovecs[1][..], b"world"[..]);
assert!(iovecs[2].is_empty());
assert!(iovecs[3].is_empty());
}
buf.advance(3);
iovecs = Default::default();
{
let mut iovecs: [&IoVec; 4] = Default::default();
assert_eq!(1, buf.bytes_vec(&mut iovecs));
assert_eq!(iovecs[0][..], b"world"[..]);
assert!(iovecs[1].is_empty());
assert!(iovecs[2].is_empty());
assert!(iovecs[3].is_empty());
assert_eq!(1, buf.bytes_vec(&mut iovecs));
assert_eq!(iovecs[0][..], b"world"[..]);
assert!(iovecs[1].is_empty());
assert!(iovecs[2].is_empty());
assert!(iovecs[3].is_empty());
}
buf.advance(3);
iovecs = Default::default();
{
let mut iovecs: [&IoVec; 4] = Default::default();
assert_eq!(1, buf.bytes_vec(&mut iovecs));
assert_eq!(iovecs[0][..], b"ld"[..]);
assert!(iovecs[1].is_empty());
assert!(iovecs[2].is_empty());
assert!(iovecs[3].is_empty());
assert_eq!(1, buf.bytes_vec(&mut iovecs));
assert_eq!(iovecs[0][..], b"ld"[..]);
assert!(iovecs[1].is_empty());
assert!(iovecs[2].is_empty());
assert!(iovecs[3].is_empty());
}
}
+35
View File
@@ -0,0 +1,35 @@
extern crate bytes;
use bytes::Bytes;
#[test]
fn fmt() {
let vec: Vec<_> = (0..0x100).map(|b| b as u8).collect();
let expected = "b\"\
\\0\\x01\\x02\\x03\\x04\\x05\\x06\\x07\
\\x08\\t\\n\\x0b\\x0c\\r\\x0e\\x0f\
\\x10\\x11\\x12\\x13\\x14\\x15\\x16\\x17\
\\x18\\x19\\x1a\\x1b\\x1c\\x1d\\x1e\\x1f\
\\x20!\\\"#$%&'()*+,-./0123456789:;<=>?\
@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\\\]^_\
`abcdefghijklmnopqrstuvwxyz{|}~\\x7f\
\\x80\\x81\\x82\\x83\\x84\\x85\\x86\\x87\
\\x88\\x89\\x8a\\x8b\\x8c\\x8d\\x8e\\x8f\
\\x90\\x91\\x92\\x93\\x94\\x95\\x96\\x97\
\\x98\\x99\\x9a\\x9b\\x9c\\x9d\\x9e\\x9f\
\\xa0\\xa1\\xa2\\xa3\\xa4\\xa5\\xa6\\xa7\
\\xa8\\xa9\\xaa\\xab\\xac\\xad\\xae\\xaf\
\\xb0\\xb1\\xb2\\xb3\\xb4\\xb5\\xb6\\xb7\
\\xb8\\xb9\\xba\\xbb\\xbc\\xbd\\xbe\\xbf\
\\xc0\\xc1\\xc2\\xc3\\xc4\\xc5\\xc6\\xc7\
\\xc8\\xc9\\xca\\xcb\\xcc\\xcd\\xce\\xcf\
\\xd0\\xd1\\xd2\\xd3\\xd4\\xd5\\xd6\\xd7\
\\xd8\\xd9\\xda\\xdb\\xdc\\xdd\\xde\\xdf\
\\xe0\\xe1\\xe2\\xe3\\xe4\\xe5\\xe6\\xe7\
\\xe8\\xe9\\xea\\xeb\\xec\\xed\\xee\\xef\
\\xf0\\xf1\\xf2\\xf3\\xf4\\xf5\\xf6\\xf7\
\\xf8\\xf9\\xfa\\xfb\\xfc\\xfd\\xfe\\xff\"";
assert_eq!(expected, format!("{:?}", Bytes::from(vec)));
}