We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 2801f9a commit d8d2e82Copy full SHA for d8d2e82
library/core/src/iter/traits/collect.rs
@@ -152,6 +152,15 @@ pub trait FromIterator<A>: Sized {
152
fn from_iter<T: IntoIterator<Item = A>>(iter: T) -> Self;
153
}
154
155
+// implement `FromIterator` for type with Default and Extend
156
+impl<T, A: Default + Extend<T>> FromIterator<T> for A {
157
+ fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self {
158
+ let mut collection = A::default();
159
+ collection.extend(iter);
160
+ collection
161
+ }
162
+}
163
+
164
/// Conversion into an [`Iterator`].
165
///
166
/// By implementing `IntoIterator` for a type, you define how it will be
0 commit comments