Tracking issue for try_reserve
: RFC 2116 fallible collection allocation · Issue #48043 · rust-lang/rust (original) (raw)
Navigation Menu
- Explore
- Pricing
Provide feedback
Saved searches
Use saved searches to filter your results more quickly
Appearance settings
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, VecDeque */ { 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 */ { 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 for TryReserveError { fn from(_: LayoutErr) -> Self { TryReserveError::CapacityOverflow } }