Skip to content

Commit 8656ea8

Browse files
committed
tweaks
1 parent 653065b commit 8656ea8

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

arrow-data/src/byte_view.rs

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,7 @@ impl<'a> From<&'a u128> for View<'a> {
8484
}
8585
}
8686

87-
/// Owned variant of [`View`]
88-
///
89-
/// This structure is used to construct a [`View`] from a string or byte slice.
87+
/// Owned variant of [`View`] for constructing views from a string or byte slice.
9088
///
9189
/// # Example
9290
/// ```
@@ -198,7 +196,10 @@ impl From<u128> for OwnedView {
198196
/// A view for data where the variable length data is less than or equal to 12.
199197
/// See documentation on [`View`] for details.
200198
///
199+
/// # Notes
201200
/// Note there is no validation done when converting to/from u128
201+
///
202+
/// Equality is based on the bitwise value of the view, not the data it logically points to
202203
#[derive(Copy, Clone, PartialEq)]
203204
pub struct InlineView<'a>(&'a u128);
204205

@@ -216,27 +217,33 @@ impl<'a> InlineView<'a> {
216217
Self(v)
217218
}
218219

219-
/// return a reference to the u128
220+
/// Return a reference to the u128
220221
pub fn as_u128(self) -> &'a u128 {
221222
self.0
222223
}
223224

224-
/// convert this inline view to a u128
225+
/// Convert this inline view to a u128
225226
pub fn into_u128(self) -> u128 {
226227
*self.0
227228
}
228229

229-
/// The length of the data, in bytes
230+
/// Return the length of the data, in bytes
230231
#[inline(always)]
231232
pub fn len(&self) -> usize {
232233
// take first 4 bytes
233234
let len = *self.0 as u32;
234235
len as usize
235236
}
236237

238+
/// Return true of the length of the data is zero
239+
#[inline(always)]
240+
pub fn is_empty(&self) -> bool {
241+
self.len() == 0
242+
}
243+
237244
/// Access the value of the data, as bytes
238245
///
239-
/// # Panic
246+
/// # Panics
240247
/// If the length is greater than 12 (aka if this view is invalid)
241248
#[inline(always)]
242249
pub fn as_bytes(&self) -> &[u8] {
@@ -249,26 +256,20 @@ impl<'a> InlineView<'a> {
249256
/// Undefined behavior if the length is greater than 12
250257
#[inline(always)]
251258
pub unsafe fn as_bytes_unchecked(&self) -> &[u8] {
252-
self.0.to_byte_slice().get_unchecked(4..4 + self.len())
259+
self.get_bytes_unchecked(self.0)
253260
}
254261

255-
/// Access the value of the data, as bytes, unchecked described by this view
262+
/// Access the value of `v`, as bytes, unchecked described by this view
256263
///
257-
/// This is used to retrieve the bytes described by this view directly from
258-
/// a reference to the underlying `u128`.
264+
/// This method can be used to access the inlined bytes described by this
265+
/// view directly from a reference to the underlying `u128`.
259266
///
260267
/// # Safety
261268
/// Undefined behavior if the length is greater than 12
262269
#[inline(always)]
263270
pub unsafe fn get_bytes_unchecked<'b>(&self, v: &'b u128) -> &'b [u8] {
264271
v.to_byte_slice().get_unchecked(4..4 + self.len())
265272
}
266-
267-
/// Is the view zero bytes?
268-
#[inline(always)]
269-
pub fn is_empty(&self) -> bool {
270-
self.len() == 0
271-
}
272273
}
273274

274275
impl<'a> From<&'a u128> for InlineView<'a> {
@@ -302,7 +303,7 @@ impl<'a> From<InlineView<'a>> for u128 {
302303
///
303304
/// # See Also
304305
/// * [`View`] to determine the correct view type for a given `u128`
305-
/// * [`OwnedViewBuilder`] for modifying the buffer index and offset of an `OffsetView`
306+
/// * [`OffsetViewBuilder`] for modifying the buffer index and offset of an `OffsetView`
306307
#[derive(Copy, Clone, PartialEq)]
307308
pub struct OffsetView<'a>(&'a u128);
308309

0 commit comments

Comments
 (0)