Skip to content

Commit a3cab90

Browse files
committed
Document TrustedLen’s contract
1 parent 69b9400 commit a3cab90

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/libcore/iter/traits.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,19 @@ pub trait FusedIterator: Iterator {}
666666
#[unstable(feature = "fused", issue = "35602")]
667667
impl<'a, I: FusedIterator + ?Sized> FusedIterator for &'a mut I {}
668668

669-
/// An iterator that has correct length
669+
/// An iterator that reports an accurate length using size_hint.
670+
///
671+
/// The iterator reports a size hint where it is either exact
672+
/// (lower bound is equal to upper bound), or the upper bound is `None`.
673+
/// The upper bound must only be `None` if the actual iterator length is
674+
/// larger than `usize::MAX`.
675+
///
676+
/// The iterator must produce exactly the number of elements it reported.
677+
///
678+
/// # Safety
679+
///
680+
/// This trait must only be implemented when the contract is upheld.
681+
/// Consumers of this trait must inspect `.size_hint()`’s upper bound.
670682
#[unstable(feature = "trusted_len", issue = "0")]
671683
pub unsafe trait TrustedLen : Iterator {}
672684

0 commit comments

Comments
 (0)