added lifetime ... i guess

This commit is contained in:
2021-09-20 00:41:38 +02:00
parent adf039057d
commit 46b9cfbd8d

View File

@@ -18,23 +18,23 @@ pub struct Instruction {
pub argument: usize,
}
pub struct Machine {
pub struct Machine<'a> {
ip: usize,
mp: usize,
code: Vec<Instruction>,
memory: [u32; 50000],
input: &mut BufReader<Box<dyn Read>>,
output: &mut BufWriter<Box<dyn Write>>,
input: &'a mut BufReader<Box<dyn Read>>,
output: &'a mut BufWriter<Box<dyn Write>>,
buf: [u8; 1],
}
impl Machine {
pub fn new(code: Vec<Instruction>, input: &mut BufReader<Box<dyn Read>>, output: &mut BufWriter<Box<dyn Write>>) -> Self {
impl<'a> Machine<'a> {
pub fn new(code: Vec<Instruction>, input: &'a mut BufReader<Box<dyn Read>>, output: &'a mut BufWriter<Box<dyn Write>>) -> Self {
Machine {
ip: 0,
mp: 0,
code,
memory: [0, 50000],
memory: [0; 50000],
input,
output,
buf: [0;1],