-
Notifications
You must be signed in to change notification settings - Fork 838
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve Buffer
documentation, deprecate Buffer::from_bytes
add From<Bytes>
and From<bytes::Bytes>
impls
#6939
Conversation
Buffer
documentation, add From<Bytes>
and From<bytes::Bytes>
impls
/// `Buffer`s can be sliced and cloned without copying the underlying data and can | ||
/// be created from memory allocated by non-Rust sources such as C/C++. | ||
/// | ||
/// # Example: Create a `Buffer` from a `Vec` (without copying) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rest of this PR is driven by the examples: converting to/from bytes::Bytes
and Vec
. I think it will be easier to do this operation now and not get hung up on Bytes
vs bytes::Bytes
They are basically an expansion of the nice example @kylebarron added in #6920
} | ||
|
||
/// Convert from [`bytes::Bytes`], not internal [`Bytes`] to `Buffer` | ||
impl From<bytes::Bytes> for Buffer { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is the From
impl proposed by @tustvold in #6930 (comment)
@@ -28,14 +28,18 @@ use crate::buffer::dangling_ptr; | |||
|
|||
/// A continuous, fixed-size, immutable memory region that knows how to de-allocate itself. | |||
/// | |||
/// This structs' API is inspired by the `bytes::Bytes`, but it is not limited to using rust's | |||
/// global allocator nor u8 alignment. | |||
/// Note that this structure is an internal implementation detail of the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hopefully this will reduce confusion about Bytes
(I have also been confused by the name before too, especially when not in an editor/IDE)
// Then we convert `arrow_buffer::Bytes` into `arrow_buffer:Buffer`, which is also zero copy | ||
let buf = arrow_buffer::Buffer::from_bytes(self.buf.clone().into()); | ||
// Zero copy convert `bytes::Bytes` into `arrow_buffer:Buffer` | ||
let buf = arrow_buffer::Buffer::from(self.buf.clone()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change to use the From impls
Buffer
documentation, add From<Bytes>
and From<bytes::Bytes>
implsBuffer
documentation, deprecate Buffer::from_bytes
add From<Bytes>
and From<bytes::Bytes>
impls
After thinking about this more I am also going to propose deprecating |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense to me; some minor comments on wording/formatting
} | ||
} | ||
|
||
/// Convert from [`bytes::Bytes`], not internal `Bytes` to `Buffer` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// Convert from [`bytes::Bytes`], not internal `Bytes` to `Buffer` | |
/// Convert from [`bytes::Bytes`] (not internal `Bytes`) to `Buffer` |
Co-authored-by: Jeffrey Vo <[email protected]>
Thank you for the review @Jefffrey -- I will leave this PR open for another day to allow time for additional comments |
Which issue does this PR close?
Buffer::from_bytes
takes unexportedBytes
#6754Buffer::from_bytes
#6920 from @kylebarronByteViewArrayDecoderPlain
#6930 from @XiangpengHaoRationale for this change
As described by @tv42 #6754 and @kylebarron in #6930 creating
Buffer
s in a zero copy way is confusing, I have also been personally confused byBytes
andbytes::Bytes
differenceAlso, the fact it is not clear how to make a
Buffer
in a zero copy manner lead to unintended copies as described by @XiangpengHao inByteViewArray
from parquet by removing an implicit copy #6031At least part of this confusion is that
Bytes
is an internal (non pub) struct that is named the same asbytes::Bytes
but appears in the public APII would like to make the whole situation less confusing
What changes are included in this PR?
Bytes
making it clear it is internal and how it is related tobytes::Bytes
Buffer
and add examples of how to constructBuffer
fromVec
andbytes::Bytes
From
impls to make it easier to createBuffer
in zero copy manner (used in examples)from_bytes
to close Public API using private types:Buffer::from_bytes
takes unexportedBytes
#6754Are there any user-facing changes?
From
impls forBuffer