diff --git a/arrow-data/src/byte_view.rs b/arrow-data/src/byte_view.rs index 7bb419503dc..ad634029fab 100644 --- a/arrow-data/src/byte_view.rs +++ b/arrow-data/src/byte_view.rs @@ -84,9 +84,7 @@ impl<'a> From<&'a u128> for View<'a> { } } -/// Owned variant of [`View`] -/// -/// This structure is used to construct a [`View`] from a string or byte slice. +/// Owned variant of [`View`] for constructing views from a string or byte slice. /// /// # Example /// ``` @@ -198,7 +196,10 @@ impl From for OwnedView { /// A view for data where the variable length data is less than or equal to 12. /// See documentation on [`View`] for details. /// +/// # Notes /// Note there is no validation done when converting to/from u128 +/// +/// Equality is based on the bitwise value of the view, not the data it logically points to #[derive(Copy, Clone, PartialEq)] pub struct InlineView<'a>(&'a u128); @@ -216,17 +217,17 @@ impl<'a> InlineView<'a> { Self(v) } - /// return a reference to the u128 + /// Return a reference to the u128 pub fn as_u128(self) -> &'a u128 { self.0 } - /// convert this inline view to a u128 + /// Convert this inline view to a u128 pub fn into_u128(self) -> u128 { *self.0 } - /// The length of the data, in bytes + /// Return the length of the data, in bytes #[inline(always)] pub fn len(&self) -> usize { // take first 4 bytes @@ -234,9 +235,15 @@ impl<'a> InlineView<'a> { len as usize } + /// Return true of the length of the data is zero + #[inline(always)] + pub fn is_empty(&self) -> bool { + self.len() == 0 + } + /// Access the value of the data, as bytes /// - /// # Panic + /// # Panics /// If the length is greater than 12 (aka if this view is invalid) #[inline(always)] pub fn as_bytes(&self) -> &[u8] { @@ -249,13 +256,13 @@ impl<'a> InlineView<'a> { /// Undefined behavior if the length is greater than 12 #[inline(always)] pub unsafe fn as_bytes_unchecked(&self) -> &[u8] { - self.0.to_byte_slice().get_unchecked(4..4 + self.len()) + self.get_bytes_unchecked(self.0) } - /// Access the value of the data, as bytes, unchecked described by this view + /// Access the value of `v`, as bytes, unchecked described by this view /// - /// This is used to retrieve the bytes described by this view directly from - /// a reference to the underlying `u128`. + /// This method can be used to access the inlined bytes described by this + /// view directly from a reference to the underlying `u128`. /// /// # Safety /// Undefined behavior if the length is greater than 12 @@ -263,12 +270,6 @@ impl<'a> InlineView<'a> { pub unsafe fn get_bytes_unchecked<'b>(&self, v: &'b u128) -> &'b [u8] { v.to_byte_slice().get_unchecked(4..4 + self.len()) } - - /// Is the view zero bytes? - #[inline(always)] - pub fn is_empty(&self) -> bool { - self.len() == 0 - } } impl<'a> From<&'a u128> for InlineView<'a> { @@ -302,7 +303,7 @@ impl<'a> From> for u128 { /// /// # See Also /// * [`View`] to determine the correct view type for a given `u128` -/// * [`OwnedViewBuilder`] for modifying the buffer index and offset of an `OffsetView` +/// * [`OffsetViewBuilder`] for modifying the buffer index and offset of an `OffsetView` #[derive(Copy, Clone, PartialEq)] pub struct OffsetView<'a>(&'a u128);