]> git.lizzy.rs Git - rust.git/commit
Auto merge of #26955 - Gankro:raw-vec, r=bluss,alexcrichton
authorbors <bors@rust-lang.org>
Fri, 17 Jul 2015 23:58:52 +0000 (23:58 +0000)
committerbors <bors@rust-lang.org>
Fri, 17 Jul 2015 23:58:52 +0000 (23:58 +0000)
commite58601ab085591c71a27ae82137fc313222c2270
treee8a3f2b288b79255e7e16c6d4a9b3b027546f9f0
parent5df259b9da287043e8284eb53d61a17b89a89bee
parentb0ee1ebef4d2b2f0e396438a3db259c981dc2754
Auto merge of #26955 - Gankro:raw-vec, r=bluss,alexcrichton

Per the top level comment:

A low-level utility for more ergonomically allocating, reallocating, and deallocating a
a buffer of memory on the heap without having to worry about all the corner cases
involved. This type is excellent for building your own data structures like Vec and VecDeque.
In particular:

* Produces heap::EMPTY on zero-sized types
* Produces heap::EMPTY on zero-length allocations
* Catches all overflows in capacity computations (promotes them to "capacity overflow" panics)
* Guards against 32-bit systems allocating more than isize::MAX bytes
* Guards against overflowing your length
* Aborts on OOM
* Avoids freeing heap::EMPTY
* Contains a ptr::Unique and thus endows the user with all related benefits

This type does not in anyway inspect the memory that it manages. When dropped it *will*
free its memory, but it *won't* try to Drop its contents. It is up to the user of RawVec
to handle the actual things *stored* inside of a RawVec.

Note that a RawVec always forces its capacity to be usize::MAX for zero-sized types.
This enables you to use capacity growing logic catch the overflows in your length
that might occur with zero-sized types.

However this means that you need to be careful when roundtripping this type
with a `Box<[T]>`: `cap()` won't yield the len. However `with_capacity`,
`shrink_to_fit`, and `from_box` will actually set RawVec's private capacity
field. This allows zero-sized types to not be special-cased by consumers of
this type.

Edit:
fixes #18726 and fixes #23842
src/libcollections/vec.rs
src/libcollections/vec_deque.rs