What does the box keyword do?

前端 未结 3 1424
故里飘歌
故里飘歌 2021-02-01 12:27

In Rust, we can use the Box type to allocate things on the heap. This type is used to safely abstract pointers to heap memory. Box

3条回答
  •  萌比男神i
    2021-02-01 13:15

    Before box was marked as unstable, it was used as a shorthand for calling Box::new. However, it's always been intended to be able to allocate arbitrary types, such as Rc, or to use arbitrary allocators. Neither of these have been finalized, so it wasn't marked as stable for the 1.0 release. This is done to prevent supporting a bad decision for all of Rust 1.x.

    For further reference, you can read the RFC that changed the "placement new" syntax and also feature gated it.

提交回复
热议问题