bluss / maplit

Rust container / collection literal macros for HashMap, HashSet, BTreeMap, BTreeSet.
https://docs.rs/maplit/
Apache License 2.0
383 stars 21 forks source link

Macro for VecDeque #10

Open sunjay opened 7 years ago

sunjay commented 7 years ago

Would it be possible to add a macro similar to vec! but for VecDeque instead?

bluss commented 7 years ago

Yeah, why not.

VecDeque::from(vec![1, 2, 3]) is not actually cost free, the conversion needs to realloc it to a power of two (which the vec's capacity is not necessarily). So the goal of the macro must be to be better than that somehow.

sunjay commented 7 years ago

Could the macro expand to use with_capacity() and push()?

bluss commented 7 years ago

Yes I think so. I guess using vec![] is sometimes more ideal, but users can then use that.

sunjay commented 7 years ago

This is the source for vec!: https://github.com/rust-lang/rust/blob/master/src/libcollections/macros.rs

If I'm understanding it correctly, it seems to be using some unstable features.

bluss commented 7 years ago

right, it's using the placement box stuff. It is really ideal to do it like that for vec![] but for vecdeque it makes an allocation that is (possibly) too small. Maybe I should look at the table of allocation size buckets again and see how they are spread.

Nokel81 commented 5 years ago

I have an implementation based on with_capacity() and push_back(). Would a PR be welcome?

Boscop commented 4 years ago

@Nokel81 Yes, please :)

Nokel81 commented 4 years ago

31

justin13888 commented 9 months ago

I know this thread has been open for a few years but wondering if this functionality was ever merged or should this issue still be open?

gamedev-pnc commented 4 months ago

What's status for this feature request?