Open
Description
This is a tracking issue for the try_reserve
part of the RFC "fallible collection allocation" (rust-lang/rfcs#2116).
Steps:
- Implement the RFC Fallible allocation #48648
- Add
HashSet::try_reserve
: Replace HashMap implementation with SwissTable (as an external crate) #58623
- Add
- Finalize the error type
- Adjust documentation (see instructions on forge)
- Stabilization PR (see instructions on forge)
API:
impl /* each of String, Vec<T>, VecDeque<T> */ {
pub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError> {…}
pub fn try_reserve_exact(&mut self, additional: usize) -> Result<(), TryReserveError> {…}
}
impl /* each of HashMap<K, V> and HashSet<T> */ {
pub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError> {…}
}
/// The error type for `try_reserve` methods.
#[derive(Clone, PartialEq, Eq, Debug)]
pub enum TryReserveError { // in std::collections
/// Error due to the computed capacity exceeding the collection's maximum
/// (usually `isize::MAX` bytes).
CapacityOverflow,
/// The memory allocator returned an error
AllocError {
/// The layout of allocation request that failed
layout: Layout,
#[doc(hidden)]
#[unstable(feature = "container_error_extra", issue = "0", reason = "\
Enable exposing the allocator’s custom error value \
if an associated type is added in the future: \
https://github.com/rust-lang/wg-allocators/issues/23")]
non_exhaustive: (),
},
}
impl From<LayoutErr> for TryReserveError {
fn from(_: LayoutErr) -> Self {
TryReserveError::CapacityOverflow
}
}
Metadata
Metadata
Assignees
Labels
Area: Custom and system allocatorsArea: `std::collections`Blocker: Approved by a merged RFC and implemented but not stabilized.Blocker: Implemented in the nightly compiler and unstable.Category: An issue tracking the progress of sth. like the implementation of an RFCLibs issues that are tracked on the team's project board.Relevant to the library API team, which will review and decide on the PR/issue.