Struct ByteView
#[repr(C)]pub struct ByteView {
pub length: u32,
pub prefix: u32,
pub buffer_index: u32,
pub offset: u32,
}Expand description
Helper to access views of GenericByteViewArray (StringViewArray and
BinaryViewArray) where the length is greater than 12 bytes.
See Also:
GenericByteViewArrayfor more information on the layout of the views.- [
validate_binary_view] and [validate_string_view] to validate
§Example: Create a new u128 view
// Create a view for a string of length 20
// first four bytes are "Rust"
// stored in buffer 3
// at offset 42
let prefix = "Rust";
let view = ByteView::new(20, prefix.as_bytes())
.with_buffer_index(3)
.with_offset(42);
// create the final u128
let v = view.as_u128();
assert_eq!(v, 0x2a000000037473755200000014);§Example: decode a u128 into its constituent fields
// Convert a u128 to a ByteView
// See validate_{string,binary}_view functions to validate
let v = ByteView::from(0x2a000000037473755200000014);
assert_eq!(v.length, 20);
assert_eq!(v.prefix, 0x74737552);
assert_eq!(v.buffer_index, 3);
assert_eq!(v.offset, 42);Fields§
§length: u32The length of the string/bytes.
prefix: u32First 4 bytes of string/bytes data.
buffer_index: u32The buffer index.
offset: u32The offset into the buffer.
Implementations§
§impl ByteView
impl ByteView
pub fn new(length: u32, prefix: &[u8]) -> ByteView
pub fn new(length: u32, prefix: &[u8]) -> ByteView
Construct a ByteView for data length of bytes with the specified prefix.
See example on ByteView docs
Notes:
- the length should always be greater than [
MAX_INLINE_VIEW_LEN] (Data less than 12 bytes is stored as an inline view) - buffer and offset are set to
0
§Panics
If the prefix is not exactly 4 bytes
pub fn with_buffer_index(self, buffer_index: u32) -> ByteView
pub fn with_buffer_index(self, buffer_index: u32) -> ByteView
Set the Self::buffer_index field
pub fn with_offset(self, offset: u32) -> ByteView
pub fn with_offset(self, offset: u32) -> ByteView
Set the Self::offset field
Trait Implementations§
impl Copy for ByteView
Auto Trait Implementations§
impl Freeze for ByteView
impl RefUnwindSafe for ByteView
impl Send for ByteView
impl Sync for ByteView
impl Unpin for ByteView
impl UnwindSafe for ByteView
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more