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

when array to vec: use double array size as capacity #190

Closed kzhui125 closed 6 months ago

kzhui125 commented 7 months ago
let mut chars = tiny_vec!([char; 4]);
chars.extend(['1', '2', '3']);
dbg!(chars.capacity());

let mut chars = vec![' ', ' ', ' ', ' '];
chars.extend(['1', '2', '3']);
dbg!(chars.capacity());

maybe it's better to use double array size as capacity?

Lokathor commented 6 months ago

The expression tiny_vec!([char; 4]) has no way to extract the "4" and double it.

Also, An ArrayVec, which a TinyVec uses internally, has a fixed capacity set by the type. Even if it were possible to get the "4" and double it, the output value would be a different type than what the user asked for (every different array length is a different type), which would confuse a lot of people.

So, I don't think we can do this one.