diff options
| author | Ulrik Sverdrup <bluss@users.noreply.github.com> | 2016-10-20 14:44:31 +0200 |
|---|---|---|
| committer | Ulrik Sverdrup <bluss@users.noreply.github.com> | 2016-10-20 14:44:31 +0200 |
| commit | a3cab90fda3b1ccfa4eb952dda49677c8d06c1ef (patch) | |
| tree | f7011f188ba1613fa7ded9c90145cfb6bc5c0774 /src/libcore | |
| parent | 69b9400b796f545226415feae36b9ea4f8cc70c0 (diff) | |
| download | rust-a3cab90fda3b1ccfa4eb952dda49677c8d06c1ef.tar.gz rust-a3cab90fda3b1ccfa4eb952dda49677c8d06c1ef.zip | |
Document TrustedLen’s contract
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/iter/traits.rs | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/libcore/iter/traits.rs b/src/libcore/iter/traits.rs index da150f1d57a..a56a864f618 100644 --- a/src/libcore/iter/traits.rs +++ b/src/libcore/iter/traits.rs @@ -666,7 +666,19 @@ pub trait FusedIterator: Iterator {} #[unstable(feature = "fused", issue = "35602")] impl<'a, I: FusedIterator + ?Sized> FusedIterator for &'a mut I {} -/// An iterator that has correct length +/// An iterator that reports an accurate length using size_hint. +/// +/// The iterator reports a size hint where it is either exact +/// (lower bound is equal to upper bound), or the upper bound is `None`. +/// The upper bound must only be `None` if the actual iterator length is +/// larger than `usize::MAX`. +/// +/// The iterator must produce exactly the number of elements it reported. +/// +/// # Safety +/// +/// This trait must only be implemented when the contract is upheld. +/// Consumers of this trait must inspect `.size_hint()`’s upper bound. #[unstable(feature = "trusted_len", issue = "0")] pub unsafe trait TrustedLen : Iterator {} |
