[−][src]Struct aoc19intcode::IntcodeVM
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]
prog: &[i128],
input: Option<Receiver<i128>>,
output: Option<Sender<i128>>
) -> Self
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]
prog: &[i128],
input: Option<Receiver<i128>>,
output: Option<Sender<i128>>,
inp_wait_flag: Option<Sender<()>>
) -> Self
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]
Auto Trait Implementations
impl !RefUnwindSafe for IntcodeVM
impl Send for IntcodeVM
impl !Sync for IntcodeVM
impl Unpin for IntcodeVM
impl !UnwindSafe for IntcodeVM
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,