strum
strum copied to clipboard
Using `#[strum(to_string = "}")]` results in macro error
Hi!
I’m tinkering with writing a transpiler and am currently in the lexing stage. In my Token
enum I have the following variant: CurlyClose
. I’d like to implement the Display
trait for Token
using strum.
What I currently have:
#[derive(Debug, Clone, strum_macros::Display)]
pub enum Token {
// Other tokens …
/// An opening curly brace; `{`.
#[strum(to_string = "{")]
CurlyOpen,
/// A closing curly brace; `}`.
#[strum(to_string = "}")] // <—- “Bracket closed without previous opened bracket”
CurlyClose,
// Other tokens …
}
The #[strum(to_string = "}")]
macro is throwing a Bracket closed without previous opened bracket
compiler error. When I try to escape the closing curly brace the macro panics with proc-macro panicked: unexpected byte '}' after \ character in string literal
.
Am I doing something wrong? Other braces such as {
[
]
(
and )
work fine.