From the std::iter::Iterator
documentation, I can see that only the next
method is required:
Required Methods
fn next(&mut self) -> Option<Self::Item>
But from the source code, after removing comments:
pub trait Iterator {
/// The type of the elements being iterated over.
#[stable(feature = "rust1", since = "1.0.0")]
type Item;
......
#[stable(feature = "rust1", since = "1.0.0")]
fn next(&mut self) -> Option<Self::Item>;
......
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
fn size_hint(&self) -> (usize, Option<usize>) { (0, None) }
......
}
I can see, except for the #[inline]
attribute, there is no difference between required and provided methods. How does Rust know which method is required or provided?