pub struct IntcodeVM { /* private fields */ }
Expand description
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."));
}
Implementations§
Source§impl IntcodeVM
impl IntcodeVM
Sourcepub fn with_io(
prog: &[i128],
input: Option<Receiver<i128>>,
output: Option<Sender<i128>>,
) -> Self
pub fn with_io( prog: &[i128], input: Option<Receiver<i128>>, output: Option<Sender<i128>>, ) -> Self
Returns a new VM with a program and I/O controls.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for IntcodeVM
impl RefUnwindSafe for IntcodeVM
impl Send for IntcodeVM
impl !Sync for IntcodeVM
impl Unpin for IntcodeVM
impl UnwindSafe for IntcodeVM
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more