(capacity: usize)
| 129 | /// then `isize::MAX`, then this function will panic. |
| 130 | #[inline] |
| 131 | pub fn with_capacity(capacity: usize) -> Self { |
| 132 | let capacity = bit_util::round_upto_multiple_of_64(capacity); |
| 133 | let layout = Layout::from_size_align(capacity, ALIGNMENT) |
| 134 | .expect("failed to create layout for MutableBuffer"); |
| 135 | let data = match layout.size() { |
| 136 | 0 => dangling_ptr(), |
| 137 | _ => { |
| 138 | // Safety: Verified size != 0 |
| 139 | let raw_ptr = unsafe { std::alloc::alloc(layout) }; |
| 140 | NonNull::new(raw_ptr).unwrap_or_else(|| handle_alloc_error(layout)) |
| 141 | } |
| 142 | }; |
| 143 | Self { |
| 144 | data, |
| 145 | len: 0, |
| 146 | layout, |
| 147 | #[cfg(feature = "pool")] |
| 148 | reservation: std::sync::Mutex::new(None), |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | /// Allocates a new [MutableBuffer] with `len` and capacity to be at least `len` where |
| 153 | /// all bytes are guaranteed to be `0u8`. |
nothing calls this directly
no test coverage detected