mirror of
https://github.com/tokio-rs/bytes.git
synced 2026-08-11 00:00:23 +02:00
Track Rust nightlies
This commit is contained in:
+6
-6
@@ -86,12 +86,12 @@ impl ToBytes for SeqByteStr {
|
||||
impl ops::Index<usize> for SeqByteStr {
|
||||
type Output = u8;
|
||||
|
||||
fn index(&self, index: &usize) -> &u8 {
|
||||
assert!(*index < self.len());
|
||||
fn index(&self, index: usize) -> &u8 {
|
||||
assert!(index < self.len());
|
||||
|
||||
unsafe {
|
||||
&*self.mem.ptr()
|
||||
.offset(*index as isize + self.pos as isize)
|
||||
.offset(index as isize + self.pos as isize)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -187,9 +187,9 @@ impl ToBytes for SmallByteStr {
|
||||
impl ops::Index<usize> for SmallByteStr {
|
||||
type Output = u8;
|
||||
|
||||
fn index(&self, index: &usize) -> &u8 {
|
||||
assert!(*index < self.len());
|
||||
&self.bytes[*index]
|
||||
fn index(&self, index: usize) -> &u8 {
|
||||
assert!(index < self.len());
|
||||
&self.bytes[index]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -163,7 +163,7 @@ impl ToBytes for Bytes {
|
||||
impl ops::Index<usize> for Bytes {
|
||||
type Output = u8;
|
||||
|
||||
fn index(&self, index: &usize) -> &u8 {
|
||||
fn index(&self, index: usize) -> &u8 {
|
||||
self.obj().index(index)
|
||||
}
|
||||
}
|
||||
@@ -212,7 +212,7 @@ trait ByteStrPriv {
|
||||
|
||||
fn get_type_id(&self) -> TypeId;
|
||||
|
||||
fn index(&self, index: &usize) -> &u8;
|
||||
fn index(&self, index: usize) -> &u8;
|
||||
|
||||
fn len(&self) -> usize;
|
||||
|
||||
@@ -245,7 +245,7 @@ impl<B: ByteStr + 'static> ByteStrPriv for B {
|
||||
Any::get_type_id(self)
|
||||
}
|
||||
|
||||
fn index(&self, index: &usize) -> &u8 {
|
||||
fn index(&self, index: usize) -> &u8 {
|
||||
ops::Index::index(self, index)
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -1,7 +1,7 @@
|
||||
#![crate_name = "bytes"]
|
||||
#![unstable]
|
||||
|
||||
#![feature(alloc, core, unsafe_no_drop_flag)]
|
||||
#![feature(alloc, convert, core, unsafe_no_drop_flag)]
|
||||
|
||||
pub use byte_buf::{ByteBuf, ROByteBuf, MutByteBuf};
|
||||
pub use byte_str::{SeqByteStr, SmallByteStr, SmallByteStrBuf};
|
||||
@@ -314,7 +314,7 @@ impl<'a> ToBytes for &'a [u8] {
|
||||
|
||||
impl<'a> ToBytes for &'a Vec<u8> {
|
||||
fn to_bytes(self) -> Bytes {
|
||||
self.as_slice().to_bytes()
|
||||
(&self[..]).to_bytes()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -407,7 +407,7 @@ impl<'a> Source for &'a Vec<u8> {
|
||||
type Error = BufError;
|
||||
|
||||
fn fill<B: MutBuf>(self, buf: &mut B) -> Result<usize, BufError> {
|
||||
Ok(buf.write_slice(self.as_slice()))
|
||||
Ok(buf.write_slice(self.as_ref()))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+5
-5
@@ -157,15 +157,15 @@ impl ToBytes for Rope {
|
||||
impl ops::Index<usize> for Rope {
|
||||
type Output = u8;
|
||||
|
||||
fn index(&self, index: &usize) -> &u8 {
|
||||
assert!(*index < self.len());
|
||||
fn index(&self, index: usize) -> &u8 {
|
||||
assert!(index < self.len());
|
||||
|
||||
let left_len = self.inner.left.len();
|
||||
|
||||
if *index < left_len {
|
||||
if index < left_len {
|
||||
self.inner.left.index(index)
|
||||
} else {
|
||||
self.inner.right.index(&(*index - left_len))
|
||||
self.inner.right.index(index - left_len)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -556,7 +556,7 @@ impl Balance {
|
||||
}
|
||||
|
||||
fn peek(&self) -> Option<&Bytes> {
|
||||
self.stack.as_slice().last()
|
||||
self.stack.last()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,26 +21,26 @@ pub fn test_initial_buf_empty() {
|
||||
pub fn test_byte_buf_read_write() {
|
||||
let mut buf = ByteBuf::mut_with_capacity(32);
|
||||
|
||||
buf.write(b"hello world".as_slice()).unwrap();
|
||||
buf.write(&b"hello world"[..]).unwrap();
|
||||
assert_eq!(21, buf.remaining());
|
||||
|
||||
buf.write(b" goodbye".as_slice()).unwrap();
|
||||
buf.write(&b" goodbye"[..]).unwrap();
|
||||
assert_eq!(13, buf.remaining());
|
||||
|
||||
let mut buf = buf.flip();
|
||||
let mut dst = [0; 5];
|
||||
|
||||
assert_eq!(5, buf.read(dst.as_mut_slice()).unwrap());
|
||||
assert_eq!(5, buf.read(&mut dst[..]).unwrap());
|
||||
assert_eq!(b"hello", &dst);
|
||||
|
||||
assert_eq!(5, buf.read(dst.as_mut_slice()).unwrap());
|
||||
assert_eq!(5, buf.read(&mut dst[..]).unwrap());
|
||||
assert_eq!(b" worl", &dst);
|
||||
|
||||
let mut dst = [0; 2];
|
||||
assert_eq!(2, buf.read(dst.as_mut_slice()).unwrap());
|
||||
assert_eq!(2, buf.read(&mut dst[..]).unwrap());
|
||||
assert_eq!(b"d ", &dst);
|
||||
|
||||
let mut dst = [0; 7];
|
||||
assert_eq!(7, buf.read(dst.as_mut_slice()).unwrap());
|
||||
assert_eq!(7, buf.read(&mut dst[..]).unwrap());
|
||||
assert_eq!(b"goodbye", &dst);
|
||||
}
|
||||
|
||||
+6
-6
@@ -5,7 +5,7 @@ pub fn test_debug_short_str_valid_ascii() {
|
||||
let b = Bytes::from_slice(b"abcdefghij234");
|
||||
let d = format!("{:?}", b);
|
||||
|
||||
assert_eq!(d.as_slice(), "Bytes[len=13; abcdefghij234]");
|
||||
assert_eq!(d, "Bytes[len=13; abcdefghij234]");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -25,10 +25,10 @@ pub fn test_debug_long_str_valid_ascii() {
|
||||
|
||||
let d = format!("{:?}", b);
|
||||
|
||||
assert_eq!(d.as_slice(), "Bytes[len=556; Lorem ipsum dolor sit amet, \
|
||||
consectetur adipiscing elit. Duis volutpat \
|
||||
eros in gravida malesuada. Phasellus \
|
||||
lobortis maximus cur ... ]");
|
||||
assert_eq!(d, "Bytes[len=556; Lorem ipsum dolor sit amet, \
|
||||
consectetur adipiscing elit. Duis volutpat \
|
||||
eros in gravida malesuada. Phasellus \
|
||||
lobortis maximus cur ... ]");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -38,5 +38,5 @@ pub fn test_short_string_invalid_ascii() {
|
||||
|
||||
println!("{:?}", b);
|
||||
|
||||
assert_eq!(d.as_slice(), "Bytes[len=11; foo\\x00bar\\xFFbaz]");
|
||||
assert_eq!(d, "Bytes[len=11; foo\\x00bar\\xFFbaz]");
|
||||
}
|
||||
|
||||
+6
-6
@@ -36,7 +36,7 @@ pub fn test_rope_round_trip() {
|
||||
let mut dst = vec![];
|
||||
rope.buf().read(&mut dst).unwrap();
|
||||
|
||||
assert_eq!(b"zomg", dst.as_slice());
|
||||
assert_eq!(b"zomg", dst);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -47,19 +47,19 @@ pub fn test_rope_slice() {
|
||||
assert_eq!(TEST_BYTES_1.len(), bytes.len());
|
||||
|
||||
bytes.buf().read(&mut dst).unwrap();
|
||||
assert_eq!(dst.as_slice(), TEST_BYTES_1);
|
||||
assert_eq!(dst, TEST_BYTES_1);
|
||||
|
||||
let left = bytes.slice_to(250);
|
||||
assert_eq!(250, left.len());
|
||||
|
||||
left.buf().read(&mut dst).unwrap();
|
||||
assert_eq!(dst.as_slice(), &TEST_BYTES_1[..250]);
|
||||
assert_eq!(dst, &TEST_BYTES_1[..250]);
|
||||
|
||||
let right = bytes.slice_from(250);
|
||||
assert_eq!(TEST_BYTES_1.len() - 250, right.len());
|
||||
|
||||
right.buf().read(&mut dst).unwrap();
|
||||
assert_eq!(dst.as_slice(), &TEST_BYTES_1[250..]);
|
||||
assert_eq!(dst, &TEST_BYTES_1[250..]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -74,7 +74,7 @@ pub fn test_rope_concat_two_byte_str() {
|
||||
assert_eq!(both.len(), TEST_BYTES_1.len() + TEST_BYTES_2.len());
|
||||
|
||||
both.buf().read(&mut dst).unwrap();
|
||||
assert_eq!(dst.as_slice(), TEST_BYTES_1.to_vec() + TEST_BYTES_2);
|
||||
assert_eq!(dst, TEST_BYTES_1.to_vec() + TEST_BYTES_2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -84,7 +84,7 @@ pub fn test_slice_parity() {
|
||||
let start = 512 * 1024 - 3333;
|
||||
let end = 512 * 1024 + 7777;
|
||||
|
||||
let _ = Rope::from_slice(bytes.as_slice()).slice(start, end);
|
||||
let _ = Rope::from_slice(&bytes).slice(start, end);
|
||||
|
||||
// stuff
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ pub fn test_slice_round_trip() {
|
||||
let mut dst = vec![];
|
||||
let src = gen_bytes(2000);
|
||||
|
||||
let s = SeqByteStr::from_slice(src.as_slice());
|
||||
let s = SeqByteStr::from_slice(&src);
|
||||
assert_eq!(2000, s.len());
|
||||
|
||||
s.buf().read(&mut dst).unwrap();
|
||||
@@ -18,7 +18,7 @@ pub fn test_slice_round_trip() {
|
||||
pub fn test_index() {
|
||||
let src = gen_bytes(2000);
|
||||
|
||||
let s = SeqByteStr::from_slice(src.as_slice());
|
||||
let s = SeqByteStr::from_slice(&src);
|
||||
|
||||
for i in 0..2000 {
|
||||
assert_eq!(src[i], s[i]);
|
||||
@@ -28,6 +28,6 @@ pub fn test_index() {
|
||||
#[test]
|
||||
#[should_panic]
|
||||
pub fn test_index_out_of_range() {
|
||||
let s = SeqByteStr::from_slice(gen_bytes(2000).as_slice());
|
||||
let s = SeqByteStr::from_slice(&gen_bytes(2000));
|
||||
let _ = s[2001];
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ pub fn test_slice_round_trip() {
|
||||
let mut dst = vec![];
|
||||
let src = gen_bytes(3);
|
||||
|
||||
let s = SmallByteStr::from_slice(src.as_slice()).unwrap();
|
||||
let s = SmallByteStr::from_slice(&src).unwrap();
|
||||
assert_eq!(3, s.len());
|
||||
|
||||
s.buf().read(&mut dst).unwrap();
|
||||
@@ -18,7 +18,7 @@ pub fn test_slice_round_trip() {
|
||||
pub fn test_index() {
|
||||
let src = gen_bytes(3);
|
||||
|
||||
let s = SmallByteStr::from_slice(src.as_slice()).unwrap();
|
||||
let s = SmallByteStr::from_slice(&src).unwrap();
|
||||
|
||||
for i in 0..3 {
|
||||
assert_eq!(src[i], s[i]);
|
||||
@@ -28,6 +28,6 @@ pub fn test_index() {
|
||||
#[test]
|
||||
#[should_panic]
|
||||
pub fn test_index_out_of_range() {
|
||||
let s = SmallByteStr::from_slice(gen_bytes(3).as_slice()).unwrap();
|
||||
let s = SmallByteStr::from_slice(&gen_bytes(3)).unwrap();
|
||||
let _ = s[2001];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user