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§
Sourceconst MAX_OFFSET: u32 = 268_435_456u32
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§
fn label_friendly_name() -> String
Sourcefn get_field(field_name: &str) -> Vec<LabelledInstruction>
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
Sourcefn get_field_with_size(field_name: &str) -> Vec<LabelledInstruction>
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.
Sourcefn get_field_start_with_jump_distance(
field_name: &str,
) -> Vec<LabelledInstruction>
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.
Sourcefn compute_size_and_assert_valid_size_indicator(
library: &mut Library,
) -> Vec<LabelledInstruction>
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
Provided Methods§
fn decode_from_memory( memory: &HashMap<BFieldElement, BFieldElement>, address: BFieldElement, ) -> Result<Box<Self>, Box<dyn Error + Send + Sync>>
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.