Skip to content

Commit

Permalink
limit freeze methods to only available for the default allocator
Browse files Browse the repository at this point in the history
Signed-off-by: Ruihang Xia <[email protected]>
  • Loading branch information
waynexia committed Sep 19, 2024
1 parent fa587a0 commit 6b28b10
Showing 1 changed file with 26 additions and 17 deletions.
43 changes: 26 additions & 17 deletions arrow-buffer/src/buffer/mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ pub struct MutableBuffer<A: Allocator = Global> {
allocator: A,
}

/// Constructors under default allocator
/// Constructors when using the default allocator [`Global`](std::alloc::Global)
impl MutableBuffer<Global> {
/// Allocate a new [MutableBuffer] with initial capacity to be at least `capacity`.
///
Expand Down Expand Up @@ -226,6 +226,31 @@ impl MutableBuffer<Global> {
buffer.truncate(bit_util::ceil(len, 8));
buffer
}

#[deprecated(
since = "2.0.0",
note = "This method is deprecated in favour of `into` from the trait `Into`."
)]
/// Freezes this buffer and return an immutable version of it.
///
/// This method is only available under the default [`Global`](std::alloc::Global)
/// for now. Support for custom allocators will be added in a future release.
/// Related ticket: https://github.com/apache/arrow-rs/issues/3960
pub fn freeze(self) -> Buffer {
self.into_buffer()
}

/// Freezes this buffer and return an immutable version of it.
///
/// This method is only available under the default [`Global`](std::alloc::Global)
/// for now. Support for custom allocators will be added in a future release.
/// Related ticket: https://github.com/apache/arrow-rs/issues/3960
#[inline]
pub(super) fn into_buffer(self) -> Buffer {
let bytes = unsafe { Bytes::new(self.data, self.len, Deallocation::Standard(self.layout)) };
std::mem::forget(self);
Buffer::from_bytes(bytes)
}
}

/// General methods
Expand Down Expand Up @@ -393,22 +418,6 @@ impl<A: Allocator> MutableBuffer<A> {
self.data.as_ptr()
}

#[deprecated(
since = "2.0.0",
note = "This method is deprecated in favour of `into` from the trait `Into`."
)]
/// Freezes this buffer and return an immutable version of it.
pub fn freeze(self) -> Buffer {
self.into_buffer()
}

#[inline]
pub(super) fn into_buffer(self) -> Buffer {
let bytes = unsafe { Bytes::new(self.data, self.len, Deallocation::Standard(self.layout)) };
std::mem::forget(self);
Buffer::from_bytes(bytes)
}

/// View this buffer as a mutable slice of a specific type.
///
/// # Panics
Expand Down

0 comments on commit 6b28b10

Please sign in to comment.