Skip to main content

WriteRange

Struct WriteRange 

Source
pub struct WriteRange {
    pub account_index: u8,
    pub offset: u32,
    pub size: u32,
}
Expand description

One allowed write range on one instruction account.

account_index is the position in the instruction’s account list (the same index handed to Context::account). Offsets are absolute within the account data, including any layout header bytes, the same convention the segment access primitives use.

Fields§

§account_index: u8

Instruction account-list index this range applies to.

§offset: u32

Absolute byte offset of the allowed range.

§size: u32

Byte size of the allowed range. WriteRange::whole_account uses u32::MAX, which contains any request on the account (account data is capped far below 4 GiB).

Implementations§

Source§

impl WriteRange

Source

pub const fn new(account_index: u8, offset: u32, size: u32) -> Self

Allow writes to [offset, offset + size) on account_index.

Source

pub const fn whole_account(account_index: u8) -> Self

Allow whole-account writes on account_index (what a plain mut declaration grants).

Source

pub const fn tail_from(account_index: u8, offset: u32) -> Self

Allow writes to the open-ended tail [offset, +inf) on account_index, the grant a growable Seq<T> tail needs.

size is u32::MAX, so contains admits any sub-range starting at or after offset regardless of how large the account grows (the account data cap is far below 4 GiB, and contains widens to u64 so offset + u32::MAX cannot wrap).

Crucially this is not a whole-account grant when offset != 0: allows_whole_account_write requires a range containing [0, u32::MAX), and a tail range that starts past the fixed head fails that test. So the fixed head stays byte-protected and CPI writable-meta delegation stays refused, while the tail region past offset remains freely writable and growable.

Source

pub const fn contains(&self, offset: u32, size: u32) -> bool

Whether [offset, offset + size) is fully contained in this range. Widened to u64 so offset + size cannot wrap.

Trait Implementations§

Source§

impl Clone for WriteRange

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for WriteRange

Source§

impl Debug for WriteRange

Source§

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

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

impl Eq for WriteRange

Source§

impl PartialEq for WriteRange

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for WriteRange

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§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.