Tracking issue for alloc_layout_extra (original) (raw)
Feature gate: #![feature(alloc_layout_extra)]
This issue tracks additional methods on Layout which allow layouts to be composed to build complex layouts.
Public API
pub const fn padding_needed_for(&self, align: usize) -> usize; pub const fn repeat(&self, n: usize) -> Result<(Layout, usize), LayoutErr>; pub const fn repeat_packed(&self, n: usize) -> Result<Layout, LayoutErr>; pub const fn extend_packed(&self, next: Layout) -> Result<Layout, LayoutErr>; pub const fn dangling(&self) -> NonNull;
The main use case is to construct complex allocation layouts for use with the stable global allocator API. For example:
- std::collections::HashMap
- hashbrown
- Not exactly an example of use, but it would be very useful in crossbeam-skiplist
Unresolved Questions
- One concern is that not many of these methods have been extensively used in practice. In the examples given above, only
extend,arrayandalign_toare used, and I expect that these will be the most used in practice.padding_needed_foris used in the implementation ofRc::from_rawandArc::from_raw, but in theory could be superseded by the offset returned byextend. - Related to the above,
repeat_packedandextend_packedhave no examples or doctests. - Should
repeatinclude trailing padding on the last element? - Should
padding_needed_fortake aTinstead of ausize?