[][src]Struct aoc19intcode::IntcodeVM

pub struct IntcodeVM { /* fields omitted */ }

A VM that runs Intcode programs.

Examples

use aoc19intcode::IntcodeVM;
assert_eq!(
    IntcodeVM::from_prog(&[2, 4, 4, 5, 99, 0])
        .run_prog()
        .expect("Tried to run a halted program.")[5],
    9801
);
use std::{thread, sync::mpsc};
use aoc19intcode::IntcodeVM;
let input = [2, 4, 4, 5, 99, 0];
let (mtx, prx) = mpsc::channel();
let (ptx, mrx) = mpsc::channel();
let (ftx, frx) = mpsc::channel();
mtx.send(2).expect("Failed to send an input to the VM.");
thread::spawn(move || {
    IntcodeVM::with_inp_flag(&input, Some(prx), Some(ptx), Some(ftx))
        .run_prog()
});
for _ in frx.recv() {
    println!("received {}", mrx.recv().expect("VM disconnected."));
}

Methods

impl IntcodeVM[src]

pub fn from_prog(prog: &[i128]) -> Self[src]

Returns a new VM with a program and no I/O controls.

pub fn with_io(
    prog: &[i128],
    input: Option<Receiver<i128>>,
    output: Option<Sender<i128>>
) -> Self
[src]

Returns a new VM with a program and I/O controls.

pub fn with_inp_flag(
    prog: &[i128],
    input: Option<Receiver<i128>>,
    output: Option<Sender<i128>>,
    inp_wait_flag: Option<Sender<()>>
) -> Self
[src]

Returns a new VM with a program and I/O controls, includes an input waiting flag sender that sends a unit (()) when the VM is expecting input.

pub fn run_prog(&mut self) -> Result<Vec<i128>, RanHaltedVMError>[src]

Runs the VM.

Trait Implementations

impl Debug for IntcodeVM[src]

impl Default for IntcodeVM[src]

impl Index<usize> for IntcodeVM[src]

type Output = i128

The returned type after indexing.

fn index(&self, ix: usize) -> &Self::Output[src]

To access any cell's value.

impl IndexMut<usize> for IntcodeVM[src]

fn index_mut(&mut self, ix: usize) -> &mut Self::Output[src]

To mutably access any cell's value.

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.