mirror of
https://github.com/tokio-rs/bytes.git
synced 2026-08-22 00:00:15 +02:00
impl ExactSizeIterator for Iter<T: Buf> (#127)
This commit is contained in:
@@ -112,3 +112,5 @@ impl<T: Buf> Iterator for Iter<T> {
|
|||||||
(rem, Some(rem))
|
(rem, Some(rem))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<T: Buf> ExactSizeIterator for Iter<T> { }
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
extern crate bytes;
|
||||||
|
|
||||||
|
use bytes::{Buf, IntoBuf, Bytes};
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn iter_len() {
|
||||||
|
let buf = Bytes::from(&b"hello world"[..]).into_buf();
|
||||||
|
let iter = buf.iter();
|
||||||
|
|
||||||
|
assert_eq!(iter.size_hint(), (11, Some(11)));
|
||||||
|
assert_eq!(iter.len(), 11);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn empty_iter_len() {
|
||||||
|
let buf = Bytes::from(&b""[..]).into_buf();
|
||||||
|
let iter = buf.iter();
|
||||||
|
|
||||||
|
assert_eq!(iter.size_hint(), (0, Some(0)));
|
||||||
|
assert_eq!(iter.len(), 0);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user