-
Notifications
You must be signed in to change notification settings - Fork 13.9k
Open
Labels
A-allocatorsArea: Custom and system allocatorsArea: Custom and system allocatorsB-unstableBlocker: Implemented in the nightly compiler and unstable.Blocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCI-libs-api-nominatedNominated for discussion during a libs-api team meeting.Nominated for discussion during a libs-api team meeting.Libs-TrackedLibs issues that are tracked on the team's project board.Libs issues that are tracked on the team's project board.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.This issue / PR is in PFCP or FCP with a disposition to merge it.final-comment-periodIn the final comment period and will be merged soon unless new substantive objections are raised.In the final comment period and will be merged soon unless new substantive objections are raised.
Description
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<u8>;
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
,array
andalign_to
are used, and I expect that these will be the most used in practice.padding_needed_for
is used in the implementation ofRc::from_raw
andArc::from_raw
, but in theory could be superseded by the offset returned byextend
. - Related to the above,
repeat_packed
andextend_packed
have no examples or doctests. - Should
repeat
include trailing padding on the last element? - Should
padding_needed_for
take aT
instead of ausize
?
stepancheg, orzogc, MrCroxx, boozook and tuguzTsilverlyra, MrCroxx and honzaspstanislav-tkach, gxtaillon, joseluis and tuguzT
Metadata
Metadata
Assignees
Labels
A-allocatorsArea: Custom and system allocatorsArea: Custom and system allocatorsB-unstableBlocker: Implemented in the nightly compiler and unstable.Blocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCI-libs-api-nominatedNominated for discussion during a libs-api team meeting.Nominated for discussion during a libs-api team meeting.Libs-TrackedLibs issues that are tracked on the team's project board.Libs issues that are tracked on the team's project board.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.This issue / PR is in PFCP or FCP with a disposition to merge it.final-comment-periodIn the final comment period and will be merged soon unless new substantive objections are raised.In the final comment period and will be merged soon unless new substantive objections are raised.