diff options
| author | Sebastian Dröge <sebastian@centricular.com> | 2021-01-31 18:53:11 +0200 |
|---|---|---|
| committer | Sebastian Dröge <sebastian@centricular.com> | 2021-02-01 09:47:23 +0200 |
| commit | 12b605af88e8935b7417234861ef8fa8e6131fd5 (patch) | |
| tree | 0634032589b00e177d0305e009dffb48cf6a070d | |
| parent | 99893346e85de78cb9cb021f831a2fe0b7dd1470 (diff) | |
| download | rust-12b605af88e8935b7417234861ef8fa8e6131fd5.tar.gz rust-12b605af88e8935b7417234861ef8fa8e6131fd5.zip | |
Implement `TrustedLen` for `iter::Fuse<I: TrustedLen>`
| -rw-r--r-- | library/core/src/iter/adapters/fuse.rs | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/library/core/src/iter/adapters/fuse.rs b/library/core/src/iter/adapters/fuse.rs index fc5fbd60b64..7a852c2cb9d 100644 --- a/library/core/src/iter/adapters/fuse.rs +++ b/library/core/src/iter/adapters/fuse.rs @@ -1,6 +1,8 @@ use crate::intrinsics; use crate::iter::adapters::{zip::try_get_unchecked, InPlaceIterable, SourceIter}; -use crate::iter::{DoubleEndedIterator, ExactSizeIterator, FusedIterator, TrustedRandomAccess}; +use crate::iter::{ + DoubleEndedIterator, ExactSizeIterator, FusedIterator, TrustedLen, TrustedRandomAccess, +}; use crate::ops::Try; /// An iterator that yields `None` forever after the underlying iterator @@ -182,6 +184,12 @@ where } } +#[unstable(feature = "trusted_len", issue = "37572")] +// SAFETY: `TrustedLen` requires that an accurate length is reported via `size_hint()`. As `Fuse` +// is just forwarding this to the wrapped iterator `I` this property is preserved and it is safe to +// implement `TrustedLen` here. +unsafe impl<I> TrustedLen for Fuse<I> where I: TrustedLen {} + #[doc(hidden)] #[unstable(feature = "trusted_random_access", issue = "none")] // SAFETY: `TrustedRandomAccess` requires that `size_hint()` must be exact and cheap to call, and |
