Skip to main content

ScopedContext

Struct ScopedContext 

Source
pub struct ScopedContext<'ctx, 'a> { /* private fields */ }
Expand description

Borrow-scoped view of a Context.

Generated typed contexts expose this wrapper from their safe raw() method instead of returning &mut Context<'a> directly. That keeps account and remaining-account references tied to the borrow of the generated context, preventing backend account-view lifetimes from being widened through the raw escape hatch.

Implementations§

Source§

impl<'ctx, 'a> ScopedContext<'ctx, 'a>

Source

pub fn new(inner: &'ctx mut Context<'a>) -> Self

Create a borrow-scoped wrapper around a raw Hopper context.

Source

pub fn program_id(&self) -> &'ctx Address

Program ID, narrowed to the wrapper borrow lifetime.

Source

pub fn instruction_data(&self) -> &'ctx [u8]

Raw instruction data, narrowed to the wrapper borrow lifetime.

Source

pub fn account( &self, index: usize, ) -> Result<&'ctx AccountView<'a>, ProgramError>

Get an account by index, narrowed to the wrapper borrow lifetime.

Source

pub fn account_mut( &self, index: usize, ) -> Result<&'ctx AccountView<'a>, ProgramError>

Mutation-intent account access, narrowed to the wrapper borrow lifetime.

Source

pub fn num_accounts(&self) -> usize

Get the total number of accounts.

Source

pub fn accounts(&self) -> &'ctx [AccountView<'a>]

Get all accounts as a slice, narrowed to the wrapper borrow lifetime.

Source

pub fn segment_ref<'b, T: Pod>( &'b mut self, index: usize, abs_offset: u32, ) -> Result<SegRef<'b, T>, ProgramError>

Borrow one runtime-selected typed byte range for reading.

This is the safe bridge for generated typed contexts whose semantic column is known statically but whose cell offset is selected at runtime (for example, a slot in a column-oriented intent shard). The returned guard remains tied to this scoped context borrow and participates in the instruction segment-borrow ledger.

Source

pub fn segment_mut<'b, T: Pod>( &'b mut self, index: usize, abs_offset: u32, ) -> Result<SegRefMut<'b, T>, ProgramError>

Borrow one runtime-selected typed byte range for mutation.

The underlying Context::segment_mut performs the active strict_writes containment check before registering the exclusive segment lease, so exposing this method does not create a policy escape. It lets typed handlers keep their generated manifest/IDL metadata while selecting an exact cell inside a declared column at runtime.

Source

pub fn split_segments_mut<'b, T: Pod, const N: usize>( &'b mut self, index: usize, ranges: [(u32, u32); N], ) -> Result<SegmentsMut<'b, T, N>, ProgramError>

Borrow several disjoint runtime-selected typed ranges for mutation. Every range is checked against the active write policy before any lease is granted.

Source

pub fn borrows(&self) -> &SegmentBorrowRegistry

Access the instruction-scoped segment borrow registry.

Source

pub fn borrows_mut(&mut self) -> &mut SegmentBorrowRegistry

Mutably access the instruction-scoped segment borrow registry.

Source

pub fn audit_accounts(&self) -> AccountAudit<'ctx>

Inspect the currently reachable account slice for duplicate aliases.

Source

pub fn remaining_accounts(&self, from: usize) -> &'ctx [AccountView<'a>]

Get the remaining accounts starting at from, narrowed to the wrapper borrow lifetime.

Source

pub fn remaining_accounts_strict(&self, from: usize) -> RemainingAccounts<'ctx>

Get remaining accounts in strict duplicate-rejecting mode.

Source

pub fn remaining_accounts_passthrough( &self, from: usize, ) -> RemainingAccounts<'ctx>

Get remaining accounts in duplicate-preserving passthrough mode.

Source

pub fn remaining_accounts_typed(&self, from: usize) -> RemainingTyped<'ctx>

Get remaining accounts in strict mode and bind a sequential typed parser.

Source

pub fn remaining_accounts_lazy(&self, from: usize) -> RemainingLazy<'ctx>

Get remaining accounts in strict mode and bind a lazy indexed parser.

Source

pub fn require_accounts(&self, n: usize) -> ProgramResult

Require at least n accounts are present.

Source

pub fn require_unique_accounts(&self) -> ProgramResult

Require all account addresses to be unique.

Source

pub fn require_unique_writable_accounts(&self) -> ProgramResult

Require that no duplicated account is writable in this instruction.

Source

pub fn require_unique_signer_accounts(&self) -> ProgramResult

Require that no duplicated account is used as a signer role.

Source

pub fn require_data_len(&self, n: usize) -> ProgramResult

Require at least n bytes of instruction data.

Source

pub fn read_data<T: ValuePod>(&self, offset: usize) -> Result<T, ProgramError>

Read instruction data as a typed value.

Source

pub fn data_slice( &self, offset: usize, len: usize, ) -> Result<&'ctx [u8], ProgramError>

Get a byte slice from instruction data.

Auto Trait Implementations§

§

impl<'ctx, 'a> !Send for ScopedContext<'ctx, 'a>

§

impl<'ctx, 'a> !Sync for ScopedContext<'ctx, 'a>

§

impl<'ctx, 'a> !UnwindSafe for ScopedContext<'ctx, 'a>

§

impl<'ctx, 'a> Freeze for ScopedContext<'ctx, 'a>

§

impl<'ctx, 'a> RefUnwindSafe for ScopedContext<'ctx, 'a>

§

impl<'ctx, 'a> Unpin for ScopedContext<'ctx, 'a>

§

impl<'ctx, 'a> UnsafeUnpin for ScopedContext<'ctx, '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 = !

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.