imperative_rs

Trait InstructionSet

Source
pub trait InstructionSet: Sized {
    // Required methods
    fn decode(mem: &[u8]) -> Result<(usize, Self), DecodeError>;
    fn encode(&self, buf: &mut [u8]) -> Result<usize, EncodeError>;
}
Expand description

This trait defines an instruction set. It provides functionality to decode from or encode to opcodes. It can be autoderived for suitable enums by a procedual macro provided by this crate.

Required Methods§

Source

fn decode(mem: &[u8]) -> Result<(usize, Self), DecodeError>

Used to decode an instruction (i.e. Self) from a byte buffer. The buffer needs to be provided as a &[u8] and the function returns a result containing either a tuple containing the number of bytes written and the resulting instruction or an DecodeError.

Source

fn encode(&self, buf: &mut [u8]) -> Result<usize, EncodeError>

Used to encode instructions into a byte buffer. The buffer needs to be provided as a &mut [u8]. The function returns a result containing either the number of bytes read or an EncodeError

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.

Implementors§