diff options
| author | snf <snf@users.noreply.github.com> | 2018-03-08 14:36:43 +0000 |
|---|---|---|
| committer | snf <snf@users.noreply.github.com> | 2018-03-14 03:48:42 -0700 |
| commit | 92bfcd2b192e59d12d64acf6f46c1897a3273b3e (patch) | |
| tree | 001462078f9c699aa3cf33322be05cc6f7b9b3d5 /src/liballoc/allocator.rs | |
| parent | fab632f9759af4f3d96c6ec69e24e5428060dba4 (diff) | |
| download | rust-92bfcd2b192e59d12d64acf6f46c1897a3273b3e.tar.gz rust-92bfcd2b192e59d12d64acf6f46c1897a3273b3e.zip | |
implementing fallible allocation API (try_reserve) for Vec, String and HashMap
Diffstat (limited to 'src/liballoc/allocator.rs')
| -rw-r--r-- | src/liballoc/allocator.rs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/liballoc/allocator.rs b/src/liballoc/allocator.rs index 55e8c0b430f..fdc4efc66b9 100644 --- a/src/liballoc/allocator.rs +++ b/src/liballoc/allocator.rs @@ -373,6 +373,24 @@ impl fmt::Display for CannotReallocInPlace { } } +/// Augments `AllocErr` with a CapacityOverflow variant. +#[derive(Clone, PartialEq, Eq, Debug)] +#[unstable(feature = "try_reserve", reason = "new API", issue="48043")] +pub enum CollectionAllocErr { + /// Error due to the computed capacity exceeding the collection's maximum + /// (usually `isize::MAX` bytes). + CapacityOverflow, + /// Error due to the allocator (see the `AllocErr` type's docs). + AllocErr(AllocErr), +} + +#[unstable(feature = "try_reserve", reason = "new API", issue="48043")] +impl From<AllocErr> for CollectionAllocErr { + fn from(err: AllocErr) -> Self { + CollectionAllocErr::AllocErr(err) + } +} + /// An implementation of `Alloc` can allocate, reallocate, and /// deallocate arbitrary blocks of data described via `Layout`. /// |
