diff options
| author | Mara Bos <m-ou.se@m-ou.se> | 2021-06-17 23:40:58 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-06-17 23:40:58 +0200 |
| commit | b7dd942e150d1ac58ca03d316ce5b5f69d46988c (patch) | |
| tree | 2297a4e97f8d7beaca66b51ef7a228563dcbf0c5 /library/std/src/io/tests.rs | |
| parent | fcac47896696899badc9a436d798d48158895ea3 (diff) | |
| parent | 2cbd5d1df54400b8bd718b7e0dadc4c38c6f9932 (diff) | |
| download | rust-b7dd942e150d1ac58ca03d316ce5b5f69d46988c.tar.gz rust-b7dd942e150d1ac58ca03d316ce5b5f69d46988c.zip | |
Rollup merge of #86202 - a1phyr:spec_io_bytes_size_hint, r=m-ou-se
Specialize `io::Bytes::size_hint` for more types Improve the result of `<io::Bytes as Iterator>::size_hint` for some readers. I did not manage to specialize `SizeHint` for `io::Cursor` Side question: would it be interesting for `io::Read` to have an optional `size_hint` method ?
Diffstat (limited to 'library/std/src/io/tests.rs')
| -rw-r--r-- | library/std/src/io/tests.rs | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/library/std/src/io/tests.rs b/library/std/src/io/tests.rs index df0dc7e9d31..2ee30f5fb4f 100644 --- a/library/std/src/io/tests.rs +++ b/library/std/src/io/tests.rs @@ -225,6 +225,24 @@ fn empty_size_hint() { } #[test] +fn slice_size_hint() { + let size_hint = (&[1, 2, 3]).bytes().size_hint(); + assert_eq!(size_hint, (3, Some(3))); +} + +#[test] +fn take_size_hint() { + let size_hint = (&[1, 2, 3]).take(2).bytes().size_hint(); + assert_eq!(size_hint, (2, Some(2))); + + let size_hint = (&[1, 2, 3]).take(4).bytes().size_hint(); + assert_eq!(size_hint, (3, Some(3))); + + let size_hint = io::repeat(0).take(3).bytes().size_hint(); + assert_eq!(size_hint, (3, Some(3))); +} + +#[test] fn chain_empty_size_hint() { let chain = io::empty().chain(io::empty()); let size_hint = chain.bytes().size_hint(); @@ -242,7 +260,7 @@ fn chain_size_hint() { let chain = buf_reader_1.chain(buf_reader_2); let size_hint = chain.bytes().size_hint(); - assert_eq!(size_hint, (testdata.len(), None)); + assert_eq!(size_hint, (testdata.len(), Some(testdata.len()))); } #[test] |
