Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

It doesn't make sense to convert a C array to a Vec, the Vec type is a growable array but the C array isn't growable. It makes sense to convert to Rust's array type, which has a fixed size, and we realise there's a problem at API boundaries because C's arrays decay to pointers, so the moment we touch an API boundary all safety is destroyed.


Depends on how the array is created. If it comes from "malloc" or C++ "new", it may need to be created as a "Vec".


Firstly, that's not an array. C has actual arrays, even though they decay to pointers at API edges and what you've made with malloc is not an array. I'll disregard C++ new and new[]

But also, it's definitely not a growable array. Box::new_uninit_slice makes the thing you've got here, a heap allocation of some specific size, which doesn't magically grow (or shrink) and isn't initialized yet.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: