Tracking issue for try_reserve: RFC 2116 fallible collection allocation · Issue #48043 · rust-lang/rust (original) (raw)

Skip to content

Provide feedback

Saved searches

Use saved searches to filter your results more quickly

Sign up

Appearance settings

@aturon

Description

@aturon

This is a tracking issue for the try_reserve part of the RFC "fallible collection allocation" (rust-lang/rfcs#2116).

Steps:

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 } }