Remove io::Cursor, and implement Buf/BufMut for slices instead (#261)

This commit is contained in:
Sean McArthur
2019-06-07 12:31:10 -07:00
committed by Carl Lerche
parent d8134903de
commit 55aa530dc1
15 changed files with 191 additions and 254 deletions
+6 -7
View File
@@ -1,34 +1,33 @@
extern crate bytes;
use bytes::{Buf, Bytes, BytesMut};
use std::io::Cursor;
const LONG: &'static [u8] = b"mary had a little lamb, little lamb, little lamb";
const SHORT: &'static [u8] = b"hello world";
#[test]
fn collect_to_vec() {
let buf: Vec<u8> = Cursor::new(SHORT).collect();
let buf: Vec<u8> = SHORT.collect();
assert_eq!(buf, SHORT);
let buf: Vec<u8> = Cursor::new(LONG).collect();
let buf: Vec<u8> = LONG.collect();
assert_eq!(buf, LONG);
}
#[test]
fn collect_to_bytes() {
let buf: Bytes = Cursor::new(SHORT).collect();
let buf: Bytes = SHORT.collect();
assert_eq!(buf, SHORT);
let buf: Bytes = Cursor::new(LONG).collect();
let buf: Bytes = LONG.collect();
assert_eq!(buf, LONG);
}
#[test]
fn collect_to_bytes_mut() {
let buf: BytesMut = Cursor::new(SHORT).collect();
let buf: BytesMut = SHORT.collect();
assert_eq!(buf, SHORT);
let buf: BytesMut = Cursor::new(LONG).collect();
let buf: BytesMut = LONG.collect();
assert_eq!(buf, LONG);
}