Write docs and remove unecessary fns and types

This commit is contained in:
Carl Lerche
2017-02-16 10:26:48 -08:00
parent 53d1c788e0
commit 0e0066e8a0
8 changed files with 377 additions and 584 deletions
+37 -25
View File
@@ -17,7 +17,7 @@ fn test_bounds() {
#[test]
fn from_slice() {
let a = Bytes::from_slice(b"abcdefgh");
let a = Bytes::from(&b"abcdefgh"[..]);
assert_eq!(a, b"abcdefgh"[..]);
assert_eq!(a, &b"abcdefgh"[..]);
assert_eq!(a, Vec::from(&b"abcdefgh"[..]));
@@ -25,7 +25,7 @@ fn from_slice() {
assert_eq!(&b"abcdefgh"[..], a);
assert_eq!(Vec::from(&b"abcdefgh"[..]), a);
let a = BytesMut::from_slice(b"abcdefgh");
let a = BytesMut::from(&b"abcdefgh"[..]);
assert_eq!(a, b"abcdefgh"[..]);
assert_eq!(a, &b"abcdefgh"[..]);
assert_eq!(a, Vec::from(&b"abcdefgh"[..]));
@@ -36,39 +36,39 @@ fn from_slice() {
#[test]
fn fmt() {
let a = format!("{:?}", Bytes::from_slice(b"abcdefg"));
let a = format!("{:?}", Bytes::from(&b"abcdefg"[..]));
let b = format!("{:?}", b"abcdefg");
assert_eq!(a, b);
let a = format!("{:?}", BytesMut::from_slice(b"abcdefg"));
let a = format!("{:?}", BytesMut::from(&b"abcdefg"[..]));
assert_eq!(a, b);
}
#[test]
fn len() {
let a = Bytes::from_slice(b"abcdefg");
let a = Bytes::from(&b"abcdefg"[..]);
assert_eq!(a.len(), 7);
let a = BytesMut::from_slice(b"abcdefg");
let a = BytesMut::from(&b"abcdefg"[..]);
assert_eq!(a.len(), 7);
let a = Bytes::from_slice(b"");
let a = Bytes::from(&b""[..]);
assert!(a.is_empty());
let a = BytesMut::from_slice(b"");
let a = BytesMut::from(&b""[..]);
assert!(a.is_empty());
}
#[test]
fn index() {
let a = Bytes::from_slice(b"hello world");
let a = Bytes::from(&b"hello world"[..]);
assert_eq!(a[0..5], *b"hello");
}
#[test]
fn slice() {
let a = Bytes::from_slice(b"hello world");
let a = Bytes::from(&b"hello world"[..]);
let b = a.slice(3, 5);
assert_eq!(b, b"lo"[..]);
@@ -83,26 +83,26 @@ fn slice() {
#[test]
#[should_panic]
fn slice_oob_1() {
let a = Bytes::from_slice(b"hello world");
let a = Bytes::from(&b"hello world"[..]);
a.slice(5, 25);
}
#[test]
#[should_panic]
fn slice_oob_2() {
let a = Bytes::from_slice(b"hello world");
let a = Bytes::from(&b"hello world"[..]);
a.slice(25, 30);
}
#[test]
fn split_off() {
let hello = Bytes::from_slice(b"helloworld");
let hello = Bytes::from(&b"helloworld"[..]);
let world = hello.split_off(5);
assert_eq!(hello, &b"hello"[..]);
assert_eq!(world, &b"world"[..]);
let hello = BytesMut::from_slice(b"helloworld");
let hello = BytesMut::from(&b"helloworld"[..]);
let world = hello.split_off(5);
assert_eq!(hello, &b"hello"[..]);
@@ -112,21 +112,21 @@ fn split_off() {
#[test]
#[should_panic]
fn split_off_oob() {
let hello = Bytes::from_slice(b"helloworld");
let hello = Bytes::from(&b"helloworld"[..]);
hello.split_off(25);
}
#[test]
#[should_panic]
fn split_off_oob_mut() {
let hello = BytesMut::from_slice(b"helloworld");
let hello = BytesMut::from(&b"helloworld"[..]);
hello.split_off(25);
}
#[test]
fn split_off_uninitialized() {
let bytes = BytesMut::with_capacity(1024);
let other = bytes.split_off(128);
let mut bytes = BytesMut::with_capacity(1024);
let other = bytes.split_off_mut(128);
assert_eq!(bytes.len(), 0);
assert_eq!(bytes.capacity(), 128);
@@ -138,20 +138,20 @@ fn split_off_uninitialized() {
#[test]
fn drain_to_1() {
// Inline
let a = Bytes::from_slice(SHORT);
let a = Bytes::from(SHORT);
let b = a.drain_to(4);
assert_eq!(SHORT[4..], a);
assert_eq!(SHORT[..4], b);
// Allocated
let a = Bytes::from_slice(LONG);
let a = Bytes::from(LONG);
let b = a.drain_to(4);
assert_eq!(LONG[4..], a);
assert_eq!(LONG[..4], b);
let a = Bytes::from_slice(LONG);
let a = Bytes::from(LONG);
let b = a.drain_to(30);
assert_eq!(LONG[30..], a);
@@ -161,21 +161,21 @@ fn drain_to_1() {
#[test]
#[should_panic]
fn drain_to_oob() {
let hello = Bytes::from_slice(b"helloworld");
let hello = Bytes::from(&b"helloworld"[..]);
hello.drain_to(30);
}
#[test]
#[should_panic]
fn drain_to_oob_mut() {
let hello = BytesMut::from_slice(b"helloworld");
let hello = BytesMut::from(&b"helloworld"[..]);
hello.drain_to(30);
}
#[test]
fn drain_to_uninitialized() {
let bytes = BytesMut::with_capacity(1024);
let other = bytes.drain_to(128);
let mut bytes = BytesMut::with_capacity(1024);
let other = bytes.drain_to_mut(128);
assert_eq!(bytes.len(), 0);
assert_eq!(bytes.capacity(), 896);
@@ -183,3 +183,15 @@ fn drain_to_uninitialized() {
assert_eq!(other.len(), 0);
assert_eq!(other.capacity(), 128);
}
#[test]
fn fns_defined_for_bytes_mut() {
let mut bytes = BytesMut::from(&b"hello world"[..]);
bytes.as_ptr();
bytes.as_mut_ptr();
// Iterator
let v: Vec<u8> = bytes.iter().map(|b| *b).collect();
assert_eq!(&v[..], &bytes[..]);
}