In my macro I want to return struct that will return a $opcode_value
that I passed to macro, but I got an error:
error: variable 'opcode_value' is still repeating at this depth
--> src/main.rs:20:17
|
20 | $opcode_value
| ^^^^^^^^^^^^^
error: could not compile `playground` due to previous error
this is my code:
macro_rules! packet {
(
properties {
$(opcode $opcode_value:expr;)?
}
$(#[$outer:meta])*
$vis:vis struct $PacketStruct:ident {
$($field_name:ident: $field_type:ty),*$(,)?
}
) => {
$(#[$outer])*
#[derive(Clone)]
$vis struct $PacketStruct {
$($field_name: $field_type),*
}
impl $PacketStruct {
pub fn get_opcode() -> u32 {
$opcode_value
}
}
};
}
fn main() {
packet! {
properties {
opcode 10;
}
#[derive(Hash)]
pub struct Outcome {
name: String,
os: u8,
game_name: String,
}
}
}
Could somebody explain how to fix this issue ? And also, how to set return type of get_opcode
according to type of $opcode_value ?