Why isn't there a blanket impl of FromIterator for Default + Extend?

⚓ Rust    📅 2026-04-05    👤 surdeus    👁️ 6      

surdeus

I had an idea that the following generic implementation could be useful:

impl<A, C: Default + Extend<A>> FromIterator<A> for C {
    fn from_iter<T: IntoIterator<Item = A>>(iter: T) -> Self {
        let mut c = C::default();
        c.extend(iter.into_iter());
        c
    }
}

In my code, this implementation would be quite convenient, but due to the orphan rules I cannot define it myself.

It also feels somewhat surprising that such an implementation is not part of the standard library.

Is there a specific reason why it has not been included?
And what would be the proper way to propose such an addition to the standard library?

2 posts - 2 participants

Read full topic

🏷️ Rust_feed