rust-lang / nomicon

The Dark Arts of Advanced and Unsafe Rust Programming
https://doc.rust-lang.org/nomicon/
Apache License 2.0
1.85k stars 268 forks source link

Update vector code examples #251

Closed lukas9393 closed 3 years ago

lukas9393 commented 3 years ago

Hi, I tried to finish the chapter about Vec. Unfortunately this chapter contains old source code that is not buildable. I had difficulties to get the code to work. Finally I found the last chapter with the actual working code.

I took this and updated the code examples. With this code it should now be possible, step by step, to evolve to the final code.

Gankra commented 3 years ago

Can you provide some insight into why you're using the unstable Global type, and not the stable alloc functions?

Gankra commented 3 years ago

(this is hard to express properly because of the super overloaded terms -- these functions at the bottom: https://doc.rust-lang.org/alloc/alloc/index.html#functions)

lukas9393 commented 3 years ago

I have completely used the template from vec-final to update the tutorial. I have not decided why the unstable api was used. I think the reason why the vec-final example does not use the stable API is that the stable api will be deprecated in the future.

This function is expected to be deprecated in favor of the alloc method of the Global type when it and the AllocRef trait become stable.

-- Function alloc::alloc::alloc