(layout: Layout)
| 32 | /// Same as `alloc::alloc::alloc`: layout must have non-zero size. |
| 33 | #[inline] |
| 34 | unsafe fn try_alloc(layout: Layout) -> Result<NonNull<u8>, OutOfMemory> { |
| 35 | // Safety: same as our safety conditions. |
| 36 | debug_assert!(layout.size() > 0); |
| 37 | let ptr = unsafe { std_alloc::alloc::alloc(layout) }; |
| 38 | |
| 39 | if let Some(ptr) = NonNull::new(ptr) { |
| 40 | Ok(ptr) |
| 41 | } else { |
| 42 | Err(OutOfMemory::new(layout.size())) |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | /// Tries to reallocate a block of memory, returning `OutOfMemory` on failure. |
| 47 | /// |