@@ -84,9 +84,7 @@ impl<'a> From<&'a u128> for View<'a> {
84
84
}
85
85
}
86
86
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.
90
88
///
91
89
/// # Example
92
90
/// ```
@@ -198,7 +196,10 @@ impl From<u128> for OwnedView {
198
196
/// A view for data where the variable length data is less than or equal to 12.
199
197
/// See documentation on [`View`] for details.
200
198
///
199
+ /// # Notes
201
200
/// 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
202
203
#[ derive( Copy , Clone , PartialEq ) ]
203
204
pub struct InlineView < ' a > ( & ' a u128 ) ;
204
205
@@ -216,27 +217,33 @@ impl<'a> InlineView<'a> {
216
217
Self ( v)
217
218
}
218
219
219
- /// return a reference to the u128
220
+ /// Return a reference to the u128
220
221
pub fn as_u128 ( self ) -> & ' a u128 {
221
222
self . 0
222
223
}
223
224
224
- /// convert this inline view to a u128
225
+ /// Convert this inline view to a u128
225
226
pub fn into_u128 ( self ) -> u128 {
226
227
* self . 0
227
228
}
228
229
229
- /// The length of the data, in bytes
230
+ /// Return the length of the data, in bytes
230
231
#[ inline( always) ]
231
232
pub fn len ( & self ) -> usize {
232
233
// take first 4 bytes
233
234
let len = * self . 0 as u32 ;
234
235
len as usize
235
236
}
236
237
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
+
237
244
/// Access the value of the data, as bytes
238
245
///
239
- /// # Panic
246
+ /// # Panics
240
247
/// If the length is greater than 12 (aka if this view is invalid)
241
248
#[ inline( always) ]
242
249
pub fn as_bytes ( & self ) -> & [ u8 ] {
@@ -249,26 +256,20 @@ impl<'a> InlineView<'a> {
249
256
/// Undefined behavior if the length is greater than 12
250
257
#[ inline( always) ]
251
258
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 )
253
260
}
254
261
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
256
263
///
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`.
259
266
///
260
267
/// # Safety
261
268
/// Undefined behavior if the length is greater than 12
262
269
#[ inline( always) ]
263
270
pub unsafe fn get_bytes_unchecked < ' b > ( & self , v : & ' b u128 ) -> & ' b [ u8 ] {
264
271
v. to_byte_slice ( ) . get_unchecked ( 4 ..4 + self . len ( ) )
265
272
}
266
-
267
- /// Is the view zero bytes?
268
- #[ inline( always) ]
269
- pub fn is_empty ( & self ) -> bool {
270
- self . len ( ) == 0
271
- }
272
273
}
273
274
274
275
impl < ' a > From < & ' a u128 > for InlineView < ' a > {
@@ -302,7 +303,7 @@ impl<'a> From<InlineView<'a>> for u128 {
302
303
///
303
304
/// # See Also
304
305
/// * [`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`
306
307
#[ derive( Copy , Clone , PartialEq ) ]
307
308
pub struct OffsetView < ' a > ( & ' a u128 ) ;
308
309
0 commit comments