core::iter::from_fn and core::iter::successors documentation does not explain callback function signature (original) (raw)

Location

core::iter::from_fn
core::iter::successors

Summary

Both of these functions take callback methods that return an Option<T>. However, nowhere is actually described that this Option<T> is used to detect the end of the iterator (i.e. return Some while there are items, return None when at the end). I was able to deduce how things worked eventually by looking at the examples, but I was definitely a bit confused at first.

There should be a clear description on what the callback is expected to return, not just when the callback is called.