error: expected one of `!`, `(`, `...`, `..=`, `..`, `::`, `=>`, `if`, `{`, or `|`, found `.`
--> src/main.rs:21:32
|
21 | Opcode::LOGIN_CHALLENGE.value => true,
| ^ expected one of 10 possible tokens
error: could not compile `playground` due to previous error
It's unclear to me what exactly you're trying to do with the match, but it is somewhat irrelevant: you can't create a const with a non-empty String because allocation is not a compile-time operation. That's what your latter error is getting at.
The reason this is an error is because the only values that you can use in a pattern (such as the left side of a match arm) to compare against are literals and const items. Option::LOGIN_CHALLENCE is the path (name) of a const item, but .value is not. You cannot use the dot operator in patterns in any way.
You could, however, declare a new const to extract the value:
let opcode: u32 = 100;
const LOGIN_CHALLENGE_VALUE: u32 = Opcode::LOGIN_CHALLENGE.value;
let result = match opcode {
LOGIN_CHALLENGE_VALUE => true,
_ => false,
};
Future versions of Rust may allow this to be written as an “inline const” so that you would be able to write