Lokathor / tinyvec

Just, really the littlest Vec you could need. So smol.
https://docs.rs/tinyvec
Apache License 2.0
648 stars 49 forks source link

`From<&'_ [T]>` implementation for ArrayVec. #133

Closed msmorgan closed 3 years ago

msmorgan commented 3 years ago

It would be useful to me to have such an implementation, or else a method that specifically writes a slice to a new ArrayVec.

Lokathor commented 3 years ago

i could probably accept a PR for this if it doesn't conflict with any of the other From impls (there's a few already).

In the meantime I think you can probably do this with slice.iter().collect()

msmorgan commented 3 years ago

Should it truncate the slice to its storage length, or would it be preferable to panic if the slice is too long?

Lokathor commented 3 years ago

i think the other impls overflow and panic, so the from impl should do the same.

paolobarbolini commented 3 years ago

Note: This trait must not fail. If the conversion can fail, use TryFrom.

Taken from the docs for From

This should probably be more like the implementation for slice into fixed size array (see here)

Lokathor commented 3 years ago

Ah, excellent. Yeah, then TryFrom should be used.