Skip to content

Commit 2b0602e

Browse files
BrianWPcarllerche
authored andcommitted
impl ExactSizeIterator for Iter<T: Buf> (#127)
1 parent 3f5890b commit 2b0602e

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/buf/iter.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,5 @@ impl<T: Buf> Iterator for Iter<T> {
112112
(rem, Some(rem))
113113
}
114114
}
115+
116+
impl<T: Buf> ExactSizeIterator for Iter<T> { }

tests/test_iter.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
extern crate bytes;
2+
3+
use bytes::{Buf, IntoBuf, Bytes};
4+
5+
#[test]
6+
fn iter_len() {
7+
let buf = Bytes::from(&b"hello world"[..]).into_buf();
8+
let iter = buf.iter();
9+
10+
assert_eq!(iter.size_hint(), (11, Some(11)));
11+
assert_eq!(iter.len(), 11);
12+
}
13+
14+
15+
#[test]
16+
fn empty_iter_len() {
17+
let buf = Bytes::from(&b""[..]).into_buf();
18+
let iter = buf.iter();
19+
20+
assert_eq!(iter.size_hint(), (0, Some(0)));
21+
assert_eq!(iter.len(), 0);
22+
}

0 commit comments

Comments
 (0)