Skip to main content

FieldMut

Struct FieldMut 

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

Mutable typed view over a field’s bytes.

Implementations§

Source§

impl<'a> FieldMut<'a>

Source

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

Create a mutable field reference over the given byte slice.

Source

pub fn read_u8(&self) -> Result<u8, ProgramError>

Read a u8 from offset 0.

Source

pub fn read_u64(&self) -> Result<u64, ProgramError>

Read a little-endian u64 from offset 0.

Source

pub fn write_u8(&mut self, v: u8) -> Result<(), ProgramError>

Write a u8 at offset 0.

Source

pub fn write_u16(&mut self, v: u16) -> Result<(), ProgramError>

Write a little-endian u16 at offset 0.

Source

pub fn write_u32(&mut self, v: u32) -> Result<(), ProgramError>

Write a little-endian u32 at offset 0.

Source

pub fn write_u64(&mut self, v: u64) -> Result<(), ProgramError>

Write a little-endian u64 at offset 0.

Source

pub fn write_bool(&mut self, v: bool) -> Result<(), ProgramError>

Write a boolean (normalized to 0x00 or 0x01).

Source

pub fn write_address(&mut self, addr: &[u8; 32]) -> Result<(), ProgramError>

Write a 32-byte address.

Source

pub fn copy_from(&mut self, src: &[u8]) -> Result<(), ProgramError>

Copy raw bytes into this field.

Source

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

Borrow the underlying bytes immutably.

Source

pub fn as_bytes_mut(&mut self) -> &mut [u8]

Borrow the underlying bytes mutably.

Auto Trait Implementations§

§

impl<'a> Freeze for FieldMut<'a>

§

impl<'a> RefUnwindSafe for FieldMut<'a>

§

impl<'a> Send for FieldMut<'a>

§

impl<'a> Sync for FieldMut<'a>

§

impl<'a> Unpin for FieldMut<'a>

§

impl<'a> UnsafeUnpin for FieldMut<'a>

§

impl<'a> !UnwindSafe for FieldMut<'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.