Skip to main content

FieldRef

Struct FieldRef 

Source
pub struct FieldRef<'a> { /* private fields */ }
Expand description

Immutable typed view over a field-sized byte slice.

Produced by split_fields (generated by zero_copy_layout!). Provides typed access without holding a reference to the whole struct.

Implementations§

Source§

impl<'a> FieldRef<'a>

Source

pub const fn new(data: &'a [u8]) -> Self

Create a field reference from a byte slice.

Source

pub const fn len(&self) -> usize

The byte length of this field.

Source

pub const fn is_empty(&self) -> bool

Whether the field is zero-length.

Source

pub const fn as_bytes(&self) -> &[u8]

Read the raw bytes.

Source

pub fn read_address(&self) -> Address

Read as an Address (32-byte public key).

Copies the bytes into an owned Address.

Source

pub fn as_address(&self) -> &Address

Borrow the field bytes as an &Address reference.

§Panics

Panics if the field is smaller than 32 bytes.

Source

pub fn read_u64(&self) -> u64

Read a u64 from the field (LE).

Source

pub fn read_u32(&self) -> u32

Read a u32 from the field (LE).

Source

pub fn read_u16(&self) -> u16

Read a u16 from the field (LE).

Source

pub fn read_u8(&self) -> u8

Read a u8 from the field.

Source

pub fn read_bool(&self) -> bool

Read a bool from the field.

Source

pub fn read_i64(&self) -> i64

Read an i64 from the field (LE).

Source

pub fn read_i32(&self) -> i32

Read an i32 from the field (LE).

Source

pub fn read_i16(&self) -> i16

Read an i16 from the field (LE).

Source

pub fn read_u128(&self) -> u128

Read a u128 from the field (LE).

Source

pub fn read_i128(&self) -> i128

Read an i128 from the field (LE).

Source

pub fn read_i8(&self) -> i8

Read an i8 from the field.

Auto Trait Implementations§

§

impl<'a> Freeze for FieldRef<'a>

§

impl<'a> RefUnwindSafe for FieldRef<'a>

§

impl<'a> Send for FieldRef<'a>

§

impl<'a> Sync for FieldRef<'a>

§

impl<'a> Unpin for FieldRef<'a>

§

impl<'a> UnsafeUnpin for FieldRef<'a>

§

impl<'a> UnwindSafe for FieldRef<'a>

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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>,

Source§

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.