Representing enum variants with optional data in macro_rules
问题 I'm trying to create a macro to help with some boilerplate enum code that I've been repetitively writing. I managed to implement a simple enum (i.e. no arguments) relatively easily using a basic macro_rule . e.g. An excerpt: macro_rules! enum_helper { ($type:ident, { $( $name:ident ), * }) => { enum $type { $( $name, )+ } impl FromSql for $type { fn from_sql<R: Read>(_: &Type, raw: &mut R, _: &SessionInfo) -> Result<&type> { // ... the implementation } // ... plus some other internal traits