Struct arrow_data::ByteView

source ·
#[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:

§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: u32

The length of the string/bytes.

§prefix: u32

First 4 bytes of string/bytes data.

§buffer_index: u32

The buffer index.

§offset: u32

The offset into the buffer.

Implementations§

source§

impl ByteView

source

pub fn new(length: u32, prefix: &[u8]) -> Self

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 12 (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

source

pub fn with_buffer_index(self, buffer_index: u32) -> Self

Set the Self::buffer_index field

source

pub fn with_offset(self, offset: u32) -> Self

Set the Self::offset field

source

pub fn as_u128(self) -> u128

Convert ByteView to u128 by concatenating the fields

Trait Implementations§

source§

impl Clone for ByteView

source§

fn clone(&self) -> ByteView

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for ByteView

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for ByteView

source§

fn default() -> ByteView

Returns the “default value” for a type. Read more
source§

impl From<ByteView> for u128

source§

fn from(value: ByteView) -> Self

Converts to this type from the input type.
source§

impl From<u128> for ByteView

source§

fn from(value: u128) -> Self

Converts to this type from the input type.
source§

impl Copy for ByteView

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> CloneToUninit for T
where T: Copy,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,