Expand description
Cross-program account lenses – read foreign fields by offset.
Hopper lenses read fields from foreign account data by byte offset and type without importing the foreign program’s Rust type. This reduces compile-time coupling when the caller already has a reviewed layout contract.
§Safety
Lenses bypass type-level layout guarantees. The caller must know the
correct offset and type for the target field. Incorrect offsets read
garbage data, never out-of-bounds memory: every accessor is
bounds-checked. Reference-returning lenses additionally hold a shared
data borrow (a crate::borrow::Ref guard) for their lifetime, so
they cannot coexist with an exclusive borrow of the same account’s
data; by-value lenses copy through raw pointers and take no borrow.
§Usage
ⓘ
use hopper_native::lens;
// Read a 32-byte address at offset 10 from a foreign program's account
// (skip 10-byte Hopper header: disc + version + layout_id).
let authority = lens::read_address(oracle_account, 10)?;
// Read a u64 price at offset 42.
let price = lens::read_le_u64(oracle_account, 42)?;
// Read a typed struct at an offset.
let data: &MyPodType = lens::read_field::<MyPodType>(account, 10)?;Functions§
- field_
eq - Compare a field in account data against an expected value without copying.
- read_
address - Read a 32-byte address from account data.
- read_
bool - Read a boolean from account data (0 = false, nonzero = true).
- read_
bytes - Read a byte slice from account data.
- read_
field - Read a
Projectablefield from account data at the given byte offset. - read_
field_ pod - Read a
Podfield from account data at the given byte offset. - read_
le_ u16 - Read a little-endian u16 from account data.
- read_
le_ u32 - Read a little-endian u32 from account data.
- read_
le_ u64 - Read a little-endian u64 from account data.
- read_u8
- Read a single byte from account data.