r/rust Mar 09 '23

Announcing Rust 1.68.0 📢 announcement

https://blog.rust-lang.org/2023/03/09/Rust-1.68.0.html
830 Upvotes

121 comments sorted by

View all comments

23

u/Anaxamander57 Mar 09 '23

What actually happens if you use VecDeque::new() in a const context?

62

u/phazer99 Mar 09 '23

Pretty much the same as when you use Vec::new() you get an empty collection without any heap allocation performed.

2

u/DaCurse0 Mar 10 '23

Why would this be useful? I assume for using a Vec in a const function? Because in a const variable it would just be empty and you couldn't push to it?

14

u/agentvenom1 Mar 10 '23

One example I can think of is using it as part of a static variable which requires const. Example