Returns `MutableBuffer` for mutating the buffer if this buffer is not shared. Returns `Err` if this is shared or its allocation is from an external source or it is not allocated with alignment [`ALIGNMENT`] # Example: Creating a [`MutableBuffer`] from a [`Buffer`] ``` # use arrow_buffer::buffer::{Buffer, MutableBuffer}; let buffer: Buffer = Buffer::from(&[1u8, 2, 3, 4][..]); // Only possible to c
(self)
| 381 | /// |
| 382 | /// [`ALIGNMENT`]: crate::alloc::ALIGNMENT |
| 383 | pub fn into_mutable(self) -> Result<MutableBuffer, Self> { |
| 384 | let ptr = self.ptr; |
| 385 | let length = self.length; |
| 386 | Arc::try_unwrap(self.data) |
| 387 | .and_then(|bytes| { |
| 388 | // The pointer of underlying buffer should not be offset. |
| 389 | assert_eq!(ptr, bytes.ptr().as_ptr()); |
| 390 | MutableBuffer::from_bytes(bytes).map_err(Arc::new) |
| 391 | }) |
| 392 | .map_err(|bytes| Buffer { |
| 393 | data: bytes, |
| 394 | ptr, |
| 395 | length, |
| 396 | }) |
| 397 | } |
| 398 | |
| 399 | /// Converts self into a `Vec`, if possible. |
| 400 | /// |