jhorstmann commented on code in PR #1866:
URL: https://github.com/apache/arrow-rs/pull/1866#discussion_r896126605
##########
arrow/src/buffer/immutable.rs:
##########
@@ -181,19 +181,14 @@ impl Buffer {
/// View buffer as typed slice.
///
- /// # Safety
+ /// # Panics
///
- /// `ArrowNativeType` is public so that it can be used as a trait bound
for other public
- /// components, such as the `ToByteSlice` trait. However, this means that
it can be
- /// implemented by user defined types, which it is not intended for.
- pub unsafe fn typed_data<T: ArrowNativeType + num::Num>(&self) -> &[T] {
- // JUSTIFICATION
- // Benefit
- // Many of the buffers represent specific types, and consumers of
`Buffer` often need to re-interpret them.
- // Soundness
- // * The pointer is non-null by construction
- // * alignment asserted below.
- let (prefix, offsets, suffix) = self.as_slice().align_to::<T>();
+ /// This function panics if the underlying buffer is not aligned
+ /// correctly for type `T`.
+ pub fn typed_data<T: ArrowNativeType>(&self) -> &[T] {
Review Comment:
My understanding is that it is safe because there are no actual undefined
bit patterns in any of the native types (as opposed to `bool` or `Option<...>`
for example). Certain bit patterns might get canonicalized when interpreted as
floating point values, but I don't think that would be considered undefined
behavior. There are more details about specific behavior in the docs for
[f64::from_bits](https://doc.rust-lang.org/std/primitive.f64.html#method.from_bits)
(which is considered safe).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]