I have an enum where most values are just labels/constants, and one value wraps a string.
I want to compare two variables of this enum type, but ==
does not compile. What's the proper way here?
The structure of the enum type is roughly like this:
enum Token {
case plain(Substring)
case parenOpen
case parenClose
case curlyOpen
case curlyClose
case pipe
case colon
case eof
}
I want to iterate tokens until I hit a certain token, so I have a function that basically takes an endToken
parameter. The idea is if I see a parenOpen
token I want to process tokens until I see parenClose
, and if I see curlyOpen
I want to process tokens until I see curlyClose
, but this is a variable and depends on what I saw earlier, so I need to check against a variable.
How can I achieve this?
EDIT:
Someone suggested this is a duplicate of another question about matching the insides of the pattern. It is not the same. I want to ignore the inside of the value and just match against the value itself!