C# has two forms of this, but both of them throw for n>1
If the rust one doesn’t just panic, it feels like it’d need to be
enum IteratorSingleError<T> {
MoreThanOneItem(T),
EmptyIterator,
}
because the emptiness check will read the second item.
That said, I feel like if you’d do anything but .unwrap() such a thing, you’d be better off writing the code a different way, so I’m inclined to say that it would be best to just always panic for n>1, the same way that C# throws in those cases. (Notably, there’s no TrySingle in C#, their pattern for non-throwing equivalents.)
So I think I like the fn single(self) -> Option<Self::Item> version – the same signature as Iterator::last, which matches up with C#'s Enumerable.Last/Enumerable.LastOrDefault.