Vm

Struct Vm 

Source
pub struct Vm { /* private fields */ }
Expand description

A unique struct containing the processors and VM context.

Implementations§

Source§

impl Vm

Source

pub fn new() -> Self

Constructs a new Vm.

§Example
use vm::Vm;
let vm = Vm::new();
Source

pub fn load_instructions( &mut self, instructions: Vec<Box<dyn Execute>>, ) -> Result<(), Error>

Moves the given Instruction slice into VmCtx memory.

§Example
use vm::Vm;
let mut vm_inst = Vm::new();
let instructions = Vec::from([/* ... */]);
_ = vm_inst.load_instructions(instructions);
§Errors

When the VmCtx.instructions is poisoned, InstructionsPoisoned is returned.

Source

pub fn new_processor(&mut self) -> usize

Constructs a new processor and returns a unique handle to the processor.

The handle exists with the processor. Hence, it shares lifetimes with the Vm.

§Example
use vm::Vm;

let mut vm_inst = Vm::new();
let mut prod_idx = vm_inst.new_processor();
Source

pub fn destroy_processor(&mut self, index: usize)

Destroys the processor at the given index.

§Example
use vm::Vm;

let mut vm_inst = Vm::new();
let mut prod_idx = vm_inst.new_processor();

vm_inst.destroy_processor(prod_idx);
Source

pub fn processor(&self, index: usize) -> Result<&Processor, Error>

Returns a reference to the processor at the given index.

§Example
use vm::Vm;

let mut vm_inst = Vm::new();

let prod_idx = vm_inst.new_processor();
let processor = vm_inst.processor(prod_idx).unwrap();
Source

pub fn processor_mut(&mut self, index: usize) -> Result<&mut Processor, Error>

Returns a mutable reference to the processor at the given index.

§Example
use vm::Vm;

let mut vm_inst = Vm::new();

let prod_idx = vm_inst.new_processor();
let processor = vm_inst.processor_mut(prod_idx).unwrap();

Trait Implementations§

Source§

impl Debug for Vm

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Vm

Source§

fn default() -> Vm

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Vm

§

impl RefUnwindSafe for Vm

§

impl !Send for Vm

§

impl !Sync for Vm

§

impl Unpin for Vm

§

impl UnwindSafe for Vm

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.