That's true, but also note that calling from_iter
directly might be more concise and readable in the case where you need to specify the type and don't have a let
to hang it on, or want it to look like T::new()
and T::from()
for consistency. FromIterator
is even in the prelude since edition 2021, so it doesn't need to be imported to be used explicitly. So, Foo::from_iter([elem, elem, ...])
will work for every collection that you could also collect()
into.
5 Likes