What is the syntax for initialising a vec of enums within a struct?

Hello,

I have not found a helpful result on this the enum is not recognised in the CodeChunk implementation, it throws an error: can someone explain to me why this happens?
common::OpCode::OP_CONSTANT => println!("{} {} {}", offset, "OP**...**

| ^^^^^^ use of undeclared crate or module common



enum OpCode {
	OpConstant,
	OpReturn,
	Halt
}

pub struct CodeChunk {
	code:Vec<OpCode>,
	data:Vec<OpCode>,
	source_lines:Vec<i32>
}

impl CodeChunk {
	pub fn disassemble_instruction(chunk:&CodeChunk, offset:usize){
		let instruction = &chunk.code[offset];
		match instruction {
			common::OpCode::OpConstant => println!("{} {} {}", offset, "OP_CONSTANT", chunk.source_lines[offset])
		}
	}
}

If the snippet is representative of your actual code, drop the common:: prefix (and handle the other variants).

it works, thanks!

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.