Allocates a new [MutableBuffer] from given `Bytes`.
(bytes: Bytes)
| 185 | |
| 186 | /// Allocates a new [MutableBuffer] from given `Bytes`. |
| 187 | pub(crate) fn from_bytes(bytes: Bytes) -> Result<Self, Bytes> { |
| 188 | let layout = match bytes.deallocation() { |
| 189 | Deallocation::Standard(layout) => *layout, |
| 190 | _ => return Err(bytes), |
| 191 | }; |
| 192 | |
| 193 | let len = bytes.len(); |
| 194 | let data = bytes.ptr(); |
| 195 | #[cfg(feature = "pool")] |
| 196 | let reservation = bytes.reservation.lock().unwrap().take(); |
| 197 | mem::forget(bytes); |
| 198 | |
| 199 | Ok(Self { |
| 200 | data, |
| 201 | len, |
| 202 | layout, |
| 203 | #[cfg(feature = "pool")] |
| 204 | reservation: Mutex::new(reservation), |
| 205 | }) |
| 206 | } |
| 207 | |
| 208 | /// creates a new [MutableBuffer] with capacity and length capable of holding `len` bits. |
| 209 | /// This is useful to create a buffer for packed bitmaps. |
nothing calls this directly
no test coverage detected