Skip to main content

ExternalZeroCopy

Trait ExternalZeroCopy 

Source
pub trait ExternalZeroCopy {
    type View<'a>;

    const OWNER: Option<Address> = None;
    const DISCRIMINATOR: Option<&'static [u8]> = None;
    const MIN_LEN: usize = 0;

    // Required method
    fn view<'a>(data: Ref<'a, [u8]>) -> Result<Self::View<'a>, ProgramError>;

    // Provided method
    fn validate(view: &AccountView<'_>) -> ProgramResult { ... }
}
Expand description

Validation contract for known non-Hopper account layouts.

Hopper-owned layouts use Hopper headers and Account. Known foreign accounts usually do not. Implement this trait on a marker or adapter type to validate owner, fixed byte prefix/discriminator, minimum length, version bytes, oracle freshness gates, or any other external invariant before binding an ExternalAccount.

Provided Associated Constants§

Source

const OWNER: Option<Address> = None

Single expected owner program, when the adapter has one.

Source

const DISCRIMINATOR: Option<&'static [u8]> = None

Optional byte prefix/discriminator at offset 0.

Source

const MIN_LEN: usize = 0

Minimum account data length accepted by this adapter.

Required Associated Types§

Source

type View<'a>

Guard-owned zero-copy view returned by this external adapter.

Implementations should store the supplied [Ref<'a, [u8]>] directly or project it into a narrower borrowed view. This keeps the account-data borrow alive for exactly as long as the external view exists.

Required Methods§

Source

fn view<'a>(data: Ref<'a, [u8]>) -> Result<Self::View<'a>, ProgramError>

Build the adapter’s typed zero-copy view from an active account-data borrow. The borrow guard is consumed so the returned view can carry it.

Provided Methods§

Source

fn validate(view: &AccountView<'_>) -> ProgramResult

Validate this external account. Override for multi-owner layouts, versioned dispatch, or custom invariants.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§