instrs 0.1.0

A derive macro for (de)serializing enums into/from bytecode

What is this?

A derive macro for (de)serializing your own enums into bytecode, mainly for the purpose of building VMs


Converting enums with hundreds of variants into bytecode and back is not fun. This crate aims to automate this task with a fairly opinionated layout that makes it easy to focus on your VM's instructions rather than how it's laid out in memory.


// The instructions our VM can handle
pub enum Instruction {
// Unit variants

// Tuple variants

// Struct variants
Add {
a: usize,
b: usize,
store_in: usize,

//Supports most `std` types
Etc(u8, i16, f32, usize, Option<char>, bool),

// Variable-size items

// Arrays and tuples
Foo( ([u8; 3], [u32; 4]) ),

// Rust type system allows for powerful composition

Automatic resizing

By default, the enum variant is encoded as a u8. However, if your enum grows to >256 items the Serialize macro will instead use a u16. Be careful as this may invalidate any previously-compiled bytecode files!