Skip to main content

TypedSegment

Struct TypedSegment 

Source
pub struct TypedSegment<T: Pod, const OFFSET: u32> { /* private fields */ }
Expand description

Compile-time typed segment descriptor: T is the overlay type, OFFSET is the absolute byte offset from the start of account data. Zero-sized.

// Matches Vault.balance at body offset 0, past the 16-byte header:
const VAULT_BALANCE: TypedSegment<WireU64, { HopperHeader::SIZE as u32 }>
    = TypedSegment::new();

let bal = account.segment_ref_typed(&mut borrows, VAULT_BALANCE)?;

Implementations§

Source§

impl<T: Pod, const OFFSET: u32> TypedSegment<T, OFFSET>

Source

pub const fn new() -> Self

Construct the marker. Runs entirely at compile time.

Source

pub const fn offset() -> u32

The absolute byte offset of this segment (OFFSET const-generic).

Source

pub const fn size() -> u32

The byte size of this segment (size_of::<T>(), folded at compile time).

Source

pub const fn end() -> u32

One-past-the-end byte offset.

Source

pub const fn as_segment() -> Segment

Lower to a runtime Segment when a heterogeneous collection of segments is needed (e.g. a validation pass that iterates).

Trait Implementations§

Source§

impl<T: Clone + Pod, const OFFSET: u32> Clone for TypedSegment<T, OFFSET>

Source§

fn clone(&self) -> TypedSegment<T, OFFSET>

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<T: Debug + Pod, const OFFSET: u32> Debug for TypedSegment<T, OFFSET>

Source§

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

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

impl<T: Default + Pod, const OFFSET: u32> Default for TypedSegment<T, OFFSET>

Source§

fn default() -> TypedSegment<T, OFFSET>

Returns the “default value” for a type. Read more
Source§

impl<T: Copy + Pod, const OFFSET: u32> Copy for TypedSegment<T, OFFSET>

Auto Trait Implementations§

§

impl<T, const OFFSET: u32> Freeze for TypedSegment<T, OFFSET>

§

impl<T, const OFFSET: u32> RefUnwindSafe for TypedSegment<T, OFFSET>

§

impl<T, const OFFSET: u32> Send for TypedSegment<T, OFFSET>

§

impl<T, const OFFSET: u32> Sync for TypedSegment<T, OFFSET>

§

impl<T, const OFFSET: u32> Unpin for TypedSegment<T, OFFSET>

§

impl<T, const OFFSET: u32> UnsafeUnpin for TypedSegment<T, OFFSET>

§

impl<T, const OFFSET: u32> UnwindSafe for TypedSegment<T, OFFSET>

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 = 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.