tasm_lib::structure::tasm_object

Trait TasmObject

Source
pub trait TasmObject {
    const MAX_OFFSET: u32 = 268_435_456u32;

    // Required methods
    fn label_friendly_name() -> String;
    fn get_field(field_name: &str) -> Vec<LabelledInstruction>;
    fn get_field_with_size(field_name: &str) -> Vec<LabelledInstruction>;
    fn get_field_start_with_jump_distance(
        field_name: &str,
    ) -> Vec<LabelledInstruction>;
    fn compute_size_and_assert_valid_size_indicator(
        library: &mut Library,
    ) -> Vec<LabelledInstruction>;
    fn decode_iter<Itr: Iterator<Item = BFieldElement>>(
        iterator: &mut Itr,
    ) -> Result<Box<Self>, Box<dyn Error + Send + Sync>>;

    // Provided method
    fn decode_from_memory(
        memory: &HashMap<BFieldElement, BFieldElement>,
        address: BFieldElement,
    ) -> Result<Box<Self>, Box<dyn Error + Send + Sync>> { ... }
}
Expand description

This trait defines methods for dealing with custom-defined objects from within the VM, assuming those methods live in memory as they are encoded with BFieldCodec.

The arguments referring to fields are strings. For structs with unnamed fields, the nth field name is implicitly field_n.

Provided Associated Constants§

Source

const MAX_OFFSET: u32 = 268_435_456u32

Maximum jump distance for encoded size and length indicators. The field getters will compare any length or size indicator read from memory against this value and crash the VM if the indicator is larger or equal.

Required Methods§

Source

fn label_friendly_name() -> String

Source

fn get_field(field_name: &str) -> Vec<LabelledInstruction>

Returns tasm code that returns a pointer the field of the object, assuming:

  • that a pointer to the said object lives on top of the stack;
  • said object has a type that implements the TasmObject trait;
  • said object lives in memory encoded as BFieldCodec specifies.
BEFORE: _ *object
AFTER:  _ *field
Source

fn get_field_with_size(field_name: &str) -> Vec<LabelledInstruction>

Returns tasm code that returns a pointer the field of the object, along with the size of that field in number of BFieldElements, assuming:

  • that a pointer to the said object lives on top of the stack;
  • said object has a type that implements the TasmObject trait;
  • said object lives in memory encoded as BFieldCodec specifies.
BEFORE: _ *object
AFTER:  _ *field field_size

See also: get_field if you just want the field without the size.

Source

fn get_field_start_with_jump_distance( field_name: &str, ) -> Vec<LabelledInstruction>

Returns tasm code that returns a pointer to the start of the field of the object, along with the jump distance to the next field. Note that:

  • *field_start == *field if the size is statically known, but
  • *field_start == *field-1 if the size is not statically known.
BEFORE: _ *object
AFTER:  _ *field_start field_jump_distance

This function is used internally for the derive macro. You probably want to use get_field or get_field_with_size instead.

Source

fn compute_size_and_assert_valid_size_indicator( library: &mut Library, ) -> Vec<LabelledInstruction>

Return the size of a struct and crash if any contained size-indicator is not valid.

BEFORE: _ *object
AFTER:  _ calculated_size
Source

fn decode_iter<Itr: Iterator<Item = BFieldElement>>( iterator: &mut Itr, ) -> Result<Box<Self>, Box<dyn Error + Send + Sync>>

Decode as Self.

Provided Methods§

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl TasmObject for bool

Source§

impl TasmObject for u32

Source§

impl TasmObject for u64

Source§

impl TasmObject for u128

Source§

impl TasmObject for Claim

Source§

impl TasmObject for Proof

Source§

impl TasmObject for FriResponse

Source§

impl TasmObject for BFieldElement

Source§

impl TasmObject for Digest

Source§

impl TasmObject for Polynomial<'_, XFieldElement>

Source§

impl TasmObject for XFieldElement

Source§

impl TasmObject for MmrAccumulator

Source§

impl TasmObject for MmrMembershipProof

Source§

impl TasmObject for MmrSuccessorProof

Source§

impl<T> TasmObject for Option<T>

Source§

impl<T> TasmObject for Vec<T>

Source§

impl<T, S> TasmObject for (T, S)

Source§

impl<const N: usize, T> TasmObject for [T; N]

Implementors§