File tree 1 file changed +23
-0
lines changed
1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -369,6 +369,25 @@ pub trait Iterator {
369
369
/// `None` here means that either there is no known upper bound, or the
370
370
/// upper bound is larger than `usize`.
371
371
///
372
+ /// # Implementation notes
373
+ ///
374
+ /// It is not enforced that an iterator implementation yields the
375
+ /// declared number of elements. A buggy iterator may yield less
376
+ /// than the lower bound or more than the upper bound of elements.
377
+ ///
378
+ /// `size_hint()` is primarily intended to be used for optimizations
379
+ /// such as reserving space for the elements of the iterator, but
380
+ /// must not be trusted to e.g. omit bounds checks in unsafe code.
381
+ /// An incorrect implementation of `size_hint()` should not lead to
382
+ /// memory safety violations.
383
+ ///
384
+ /// That said, the implementation should provide a correct
385
+ /// estimation, because otherwise it would be a violation of the
386
+ /// trait's protocol.
387
+ ///
388
+ /// The default implementation returns `(0, None)` which is correct
389
+ /// for any iterator.
390
+ ///
372
391
/// # Examples
373
392
///
374
393
/// Basic usage:
@@ -2731,7 +2750,11 @@ pub trait ExactSizeIterator: Iterator {
2731
2750
/// implementation, you can do so. See the [trait-level] docs for an
2732
2751
/// example.
2733
2752
///
2753
+ /// This function has the same safety guarantees as [`size_hint()`]
2754
+ /// function.
2755
+ ///
2734
2756
/// [trait-level]: trait.ExactSizeIterator.html
2757
+ /// [`size_hint()`]: trait.Iterator.html#method.size_hint
2735
2758
///
2736
2759
/// # Examples
2737
2760
///
You can’t perform that action at this time.
0 commit comments