Stream: t-libs

Topic: Extend::extend

Lokathor (Jan 18 2020 at 20:16, on Zulip):

What should a collection do if someone tries to extend it beyond it's capacity and it cannot grow the capacity?

major options seem to be:

1) Panic
2) Drop the rest of the iterator items

This doesn't have to get added to the official docs, I'd just like to know general opinion at the moment.

Amanieu (Jan 18 2020 at 20:35, on Zulip):

ArrayVec simply drops the rest of the iterator.

Amanieu (Jan 18 2020 at 20:35, on Zulip):

I think this does need to go into the official docs for the Extend trait.

Lokathor (Jan 18 2020 at 21:41, on Zulip):

I had been leaning towards "panic" for my own ArrayVec type in the tinyvec crate. That is what it currently does.

It felt consistent to panic because all the other ways to add elements will cause a panic on overflow.

Steven Fackler (Jan 18 2020 at 23:17, on Zulip):

Panicking seems like a better option to me as well

simulacrum (Jan 19 2020 at 02:12, on Zulip):

Dropping the rest of the elements seems highly unexpected

gnzlbg (Jan 20 2020 at 12:38, on Zulip):

The program will silently continue until you get a logic error sometime later :/

gnzlbg (Jan 20 2020 at 12:40, on Zulip):

If someone needs this to be fallible, then we can always add a TryExtend API, similar to how try_push/try_reserve work

Simon Sapin (Jan 20 2020 at 18:29, on Zulip):

arrayvec has try_extend_from_slice. It could have a an iterator-based try_extend method even if there’s no TryExtend trait in the standard library.

Last update: Feb 25 2020 at 04:15UTC