Trait stack_vm::FromByteCode [] [src]

pub trait FromByteCode {
    fn from_byte_code(_: &mut Read) -> Self;
}

Convert from byte code to a type.

This trait represents the ability to load your Operands from bytecode. stack-vm uses the rmp crate to load bytecode from a MsgPack encoded binary.

See the rmp docs to find out which functions you can use to write out your types.

Required Methods

Convert from MsgPack to your type.

This function takes a mutable reference of type Read and returns your operand type.

Example


#[derive(PartialEq, Debug)]
struct Operand(i64);

impl FromByteCode for Operand {
    fn from_byte_code(mut buf: &mut Read) -> Operand {
        let value = rmp::decode::read_int(&mut buf).unwrap();
        Operand(value)
    }
}
let bytecode = [0xd];
assert_eq!(Operand(13), Operand::from_byte_code(&mut &bytecode[..]));

Implementors