Skip to content

Commit 12b605a

Browse files
committed
Implement TrustedLen for iter::Fuse<I: TrustedLen>
1 parent 9989334 commit 12b605a

File tree

1 file changed

+9
-1
lines changed
  • library/core/src/iter/adapters

1 file changed

+9
-1
lines changed

library/core/src/iter/adapters/fuse.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use crate::intrinsics;
22
use crate::iter::adapters::{zip::try_get_unchecked, InPlaceIterable, SourceIter};
3-
use crate::iter::{DoubleEndedIterator, ExactSizeIterator, FusedIterator, TrustedRandomAccess};
3+
use crate::iter::{
4+
DoubleEndedIterator, ExactSizeIterator, FusedIterator, TrustedLen, TrustedRandomAccess,
5+
};
46
use crate::ops::Try;
57

68
/// An iterator that yields `None` forever after the underlying iterator
@@ -182,6 +184,12 @@ where
182184
}
183185
}
184186

187+
#[unstable(feature = "trusted_len", issue = "37572")]
188+
// SAFETY: `TrustedLen` requires that an accurate length is reported via `size_hint()`. As `Fuse`
189+
// is just forwarding this to the wrapped iterator `I` this property is preserved and it is safe to
190+
// implement `TrustedLen` here.
191+
unsafe impl<I> TrustedLen for Fuse<I> where I: TrustedLen {}
192+
185193
#[doc(hidden)]
186194
#[unstable(feature = "trusted_random_access", issue = "none")]
187195
// SAFETY: `TrustedRandomAccess` requires that `size_hint()` must be exact and cheap to call, and

0 commit comments

Comments
 (0)