Why try_fold (and similar functions) requires Self: Sized?

Why Iterator:try_fold and Iterator:try_for_each functions that take mutable reference and that calls only Iterator:next requires Self: Sized? I understand why Iterator:fold has such requirement, since it is a function that accept value instead of reference, but I don't see any reason why try_fold and similar functions has such requirement and requires users to bypass it by passing &mut &mut Iterator, i.e.:

fn try_fold_wrapper(iterator: &mut dyn Iterator<Item=Result<(), ()>>) -> Result<(), ()> {
    (&mut &mut *iterator).try_fold((), |_, result| result)
}

It's necessary for dyn compatibility, as dispatchable functions can't have type parameters.

4 Likes

I see, thank you very much for answer and showing place in documentation that states it

2 Likes