(layout: Layout)
| 12 | /// Same as `alloc::alloc::alloc`: layout must have non-zero size. |
| 13 | #[inline] |
| 14 | pub(crate) unsafe fn try_alloc(layout: Layout) -> Result<NonNull<u8>, OutOfMemory> { |
| 15 | // Safety: same as our safety conditions. |
| 16 | debug_assert!(layout.size() > 0); |
| 17 | let ptr = unsafe { std_alloc::alloc::alloc(layout) }; |
| 18 | |
| 19 | if let Some(ptr) = NonNull::new(ptr) { |
| 20 | Ok(ptr) |
| 21 | } else { |
| 22 | Err(OutOfMemory::new(layout.size())) |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | /// Create a `Box<T>`, or return an `OutOfMemory` error. |
| 27 | #[inline] |
no test coverage detected