I am creating a lot of structs using Option<Vec<T>>
instead of Vec<T>
to not allocate memory when not needed. And I looked up this answer about the sizes of both Vec
& Option<Vec>>
and both were same.
So my question is this. Should I use Vec<T>
and check its .len()
for the same effect or continue using Option
? Or are they equivalent?
Also originally I am a JavaScript Developer. And getting paranoid over to allocate or not to allocate.